]> mj.ucw.cz Git - libucw.git/commitdiff
Mempools: Added mp_append_utf8_32()
authorMartin Mares <mj@ucw.cz>
Wed, 8 Jul 2015 14:19:16 +0000 (16:19 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 8 Jul 2015 14:19:16 +0000 (16:19 +0200)
ucw/mempool-str.c
ucw/mempool.h

index 1072e3dacb7fde29a0deceef692d77732478b6fa..0edfe26474ef4ba42e7a33d472ed4895e1a68d3e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     UCW Library -- Memory Pools (String Operations)
  *
- *     (c) 2004 Martin Mares <mj@ucw.cz>
+ *     (c) 2004--2015 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -9,6 +9,7 @@
 
 #include <ucw/lib.h>
 #include <ucw/mempool.h>
+#include <ucw/unicode.h>
 
 #include <alloca.h>
 #include <string.h>
@@ -94,6 +95,12 @@ mp_str_from_mem(struct mempool *a, const void *mem, size_t len)
   return str;
 }
 
+void *mp_append_utf8_32(struct mempool *pool, void *p, uint c)
+{
+  p = mp_spread(pool, p, utf8_space(c));
+  return utf8_32_put(p, c);
+}
+
 #ifdef TEST
 
 #include <stdio.h>
index 44595ea7faa8432421f02a103d952b271c80943c..c0147ad5fee3fc447e6c20efd2a141d83b417adb 100644 (file)
@@ -361,6 +361,13 @@ static inline void *mp_append_string(struct mempool *pool, void *p, const char *
   return mp_append_block(pool, p, str, strlen(str));
 }
 
+/**
+ * Append an UTF-8 character to the growing buffer. Called with @p pointing after
+ * the last byte in the buffer, returns a pointer after the last byte
+ * of the new (possibly reallocated) buffer.
+ **/
+void *mp_append_utf8_32(struct mempool *pool, void *p, uint c);
+
 /**
  * Close the growing buffer. The @end must point just behind the data, you want to keep
  * allocated (so it can be in the interval `[@mp_ptr(@pool), @mp_ptr(@pool) + @mp_avail(@pool)]`).