]> mj.ucw.cz Git - libucw.git/blob - charset/stk-charconv.h
Mempool: Do not count the struct mempool to its stats.used_size.
[libucw.git] / charset / stk-charconv.h
1 /*
2  *      Sherlock Library -- Character Conversion with Allocation on the Stack
3  *
4  *      (c) 2006 Pavel Charvat <pchar@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _CHARSET_STK_CHARCONV_H
11 #define _CHARSET_STK_CHARCONV_H
12
13 #include <charset/charconv.h>
14 #include <alloca.h>
15
16 #ifdef CONFIG_UCW_CLEAN_ABI
17 #define stk_strconv_init ucw_stk_strconv_init
18 #define stk_strconv_step ucw_stk_strconv_step
19 #endif
20
21 /* The following macros convert strings between given charsets (CONV_CHARSET_x). */
22
23 #define stk_strconv(s, cs_in, cs_out) \
24     ({ struct conv_context _c; uns _l=stk_strconv_init(&_c, (s), (cs_in), (cs_out)); \
25        while (_l) _l=stk_strconv_step(&_c, alloca(_l), _l); _c.dest_start; })
26
27 #define stk_strconv_to_utf8(s, cs_in) stk_strconv(s, cs_in, CONV_CHARSET_UTF8)
28 #define stk_strconv_from_utf8(s, cs_out) stk_strconv(s, CONV_CHARSET_UTF8, cs_out)
29
30 /* Internals */
31
32 uns stk_strconv_init(struct conv_context *c, const byte *s, uns cs_in, uns cs_out);
33 uns stk_strconv_step(struct conv_context *c, byte *buf, uns len);
34
35 #endif