Eina bin/(u)strbuf: Added eina_*buf_manage_new_length.
authortasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 8 Dec 2011 13:10:57 +0000 (13:10 +0000)
committertasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 8 Dec 2011 13:10:57 +0000 (13:10 +0000)
Same as eina_*buf_manage_new except for the length parameter.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@66028 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
src/include/eina_binbuf.h
src/include/eina_strbuf.h
src/include/eina_ustrbuf.h
src/lib/eina_binbuf_template_c.x
src/tests/eina_test_binbuf.c

index 7d261b3..6b5d7d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 2011-12-07  Mike Blumenkrantz (discomfitor/zmike)
 
         * 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.
index 92f788e..7c3524b 100644 (file)
@@ -49,6 +49,24 @@ typedef struct _Eina_Strbuf Eina_Binbuf;
 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.
  *
  * @param buf The string buffer to free.
index 7043575..34c200f 100644 (file)
@@ -99,6 +99,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;
 
 /**
+ * @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.
  *
  * @param buf The string buffer to free.
index f68cb7b..9710c42 100644 (file)
@@ -65,7 +65,25 @@ EAPI Eina_UStrbuf *eina_ustrbuf_new(void) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
  * @see eina_ustrbuf_string_get()
  * @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.
index 613a715..7e0c539 100644 (file)
@@ -65,6 +65,15 @@ _FUNC_EXPAND(new)(void)
    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
 _FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf)
 {
index 713e078..90332c1 100644 (file)
@@ -98,6 +98,30 @@ START_TEST(binbuf_remove)
 }
 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)
 {
 #if 0