Eina bin/(u)strbuf: Added eina_*buf_manage_new_length.
Same as eina_*buf_manage_new except for the length parameter. SVN revision: 66028
This commit is contained in:
parent
6bab74cfd7
commit
66b3c08aff
|
@ -159,3 +159,9 @@
|
||||||
2011-12-07 Mike Blumenkrantz (discomfitor/zmike)
|
2011-12-07 Mike Blumenkrantz (discomfitor/zmike)
|
||||||
|
|
||||||
* eina_log*level_check() functions now return the correct value
|
* eina_log*level_check() functions now return the correct value
|
||||||
|
|
||||||
|
2011-12-08 Tom Hacohen
|
||||||
|
|
||||||
|
* Binbuf + Strbuf + Ustrbuf: Added eina_*buf_manage_new_length.
|
||||||
|
Same as eina_(u)strbuf_manage_new except that it accepts a length
|
||||||
|
parameter.
|
||||||
|
|
|
@ -48,6 +48,24 @@ typedef struct _Eina_Strbuf Eina_Binbuf;
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Binbuf *eina_binbuf_new(void) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
EAPI Eina_Binbuf *eina_binbuf_new(void) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a new string buffer using the passed string. The passed
|
||||||
|
* string is used directly as the buffer, it's somehow the opposite function of
|
||||||
|
* @ref eina_binbuf_string_steal . The passed string must be malloced.
|
||||||
|
*
|
||||||
|
* @param str the string to manage
|
||||||
|
* @param length the length of the string.
|
||||||
|
* @return Newly allocated string buffer instance.
|
||||||
|
*
|
||||||
|
* This function creates a new string buffer. On error, @c NULL is
|
||||||
|
* returned and Eina error is set to #EINA_ERROR_OUT_OF_MEMORY. To
|
||||||
|
* free the resources, use eina_binbuf_free().
|
||||||
|
*
|
||||||
|
* @see eina_binbuf_manage_new()
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
EAPI Eina_Binbuf *eina_binbuf_manage_new_length(unsigned char *str, size_t length) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Free a string buffer.
|
* @brief Free a string buffer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -98,6 +98,24 @@ EAPI Eina_Strbuf *eina_strbuf_new(void) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Strbuf *eina_strbuf_manage_new(char *str) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
EAPI Eina_Strbuf *eina_strbuf_manage_new(char *str) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a new string buffer using the passed string. The passed
|
||||||
|
* string is used directly as the buffer, it's somehow the opposite function of
|
||||||
|
* @ref eina_strbuf_string_steal . The passed string must be malloced.
|
||||||
|
*
|
||||||
|
* @param str the string to manage
|
||||||
|
* @param length the length of the string.
|
||||||
|
* @return Newly allocated string buffer instance.
|
||||||
|
*
|
||||||
|
* This function creates a new string buffer. On error, @c NULL is
|
||||||
|
* returned and Eina error is set to #EINA_ERROR_OUT_OF_MEMORY. To
|
||||||
|
* free the resources, use eina_strbuf_free().
|
||||||
|
*
|
||||||
|
* @see eina_strbuf_manage_new()
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
EAPI Eina_Strbuf *eina_strbuf_manage_new_length(char *str, size_t length) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Free a string buffer.
|
* @brief Free a string buffer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -65,7 +65,25 @@ EAPI Eina_UStrbuf *eina_ustrbuf_new(void) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
* @see eina_ustrbuf_string_get()
|
* @see eina_ustrbuf_string_get()
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Strbuf *eina_ustrbuf_manage_new(Eina_Unicode *str) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
EAPI Eina_UStrbuf *eina_ustrbuf_manage_new(Eina_Unicode *str) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a new string buffer using the passed string. The passed
|
||||||
|
* string is used directly as the buffer, it's somehow the opposite function of
|
||||||
|
* @ref eina_ustrbuf_string_steal . The passed string must be malloced.
|
||||||
|
*
|
||||||
|
* @param str the string to manage
|
||||||
|
* @param length the length of the string.
|
||||||
|
* @return Newly allocated string buffer instance.
|
||||||
|
*
|
||||||
|
* This function creates a new string buffer. On error, @c NULL is
|
||||||
|
* returned and Eina error is set to #EINA_ERROR_OUT_OF_MEMORY. To
|
||||||
|
* free the resources, use eina_ustrbuf_free().
|
||||||
|
*
|
||||||
|
* @see eina_ustrbuf_manage_new()
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
EAPI Eina_UStrbuf *eina_ustrbuf_manage_new_length(Eina_Unicode *str, size_t length) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Free a string buffer.
|
* @brief Free a string buffer.
|
||||||
|
|
|
@ -65,6 +65,15 @@ _FUNC_EXPAND(new)(void)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EAPI _STRBUF_STRUCT_NAME *
|
||||||
|
_FUNC_EXPAND(manage_new_length)(_STRBUF_DATA_TYPE *str, size_t length)
|
||||||
|
{
|
||||||
|
_STRBUF_STRUCT_NAME *buf =
|
||||||
|
eina_strbuf_common_manage_new(_STRBUF_CSIZE, (void *) str, length);
|
||||||
|
EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
_FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf)
|
_FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf)
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,6 +98,30 @@ START_TEST(binbuf_remove)
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST(binbuf_manage_simple)
|
||||||
|
{
|
||||||
|
Eina_Binbuf *buf;
|
||||||
|
const unsigned char cbuf[] = "12\0 456 78\0 abcthis is some more random junk here!";
|
||||||
|
size_t size = sizeof(cbuf) - 1; /* We don't care about the real NULL */
|
||||||
|
|
||||||
|
eina_init();
|
||||||
|
|
||||||
|
buf = eina_binbuf_manage_new_length(cbuf, size);
|
||||||
|
fail_if(!buf);
|
||||||
|
|
||||||
|
fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
|
||||||
|
fail_if(size != eina_binbuf_length_get(buf));
|
||||||
|
eina_binbuf_append_length(buf, cbuf, size);
|
||||||
|
fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
|
||||||
|
fail_if(memcmp(eina_binbuf_string_get(buf) + size, cbuf, size));
|
||||||
|
fail_if(2 * size != eina_binbuf_length_get(buf));
|
||||||
|
|
||||||
|
eina_binbuf_free(buf);
|
||||||
|
|
||||||
|
eina_shutdown();
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
START_TEST(binbuf_insert)
|
START_TEST(binbuf_insert)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
|
Loading…
Reference in New Issue