From 12304b3e4a94ac4e1d111c3d5e76963377c8585d Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 8 Jul 2015 16:19:16 +0200 Subject: [PATCH] Mempools: Added mp_append_utf8_32() --- ucw/mempool-str.c | 9 ++++++++- ucw/mempool.h | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ucw/mempool-str.c b/ucw/mempool-str.c index 1072e3da..0edfe264 100644 --- a/ucw/mempool-str.c +++ b/ucw/mempool-str.c @@ -1,7 +1,7 @@ /* * UCW Library -- Memory Pools (String Operations) * - * (c) 2004 Martin Mares + * (c) 2004--2015 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -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 diff --git a/ucw/mempool.h b/ucw/mempool.h index 44595ea7..c0147ad5 100644 --- a/ucw/mempool.h +++ b/ucw/mempool.h @@ -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)]`). -- 2.39.2