2 * Sherlock Library -- Character Conversion with Allocation on the Stack
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
7 #ifndef _CHARSET_STK_CHARCONV_H
8 #define _CHARSET_STK_CHARCONV_H
10 #include "charset/charconv.h"
13 /* The following macros convert strings between given charsets (CONV_CHARSET_x).
14 * The resulting string is allocated on the stack with the exception of cs_in == cs_out,
15 * when the pointer to the input string is returned. */
17 #define stk_conv(s, cs_in, cs_out) \
18 ({ struct conv_context _c; uns _l=stk_conv_internal(&_c, (s), (cs_in), (cs_out)); \
19 if (_l) { _c.dest=_c.dest_start=alloca(_l); _c.dest_end=_c.dest+_l; conv_run(&_c); } \
22 #define stk_conv_to_utf8(s, cs_in) stk_conv(s, cs_in, CONV_CHARSET_UTF8)
23 #define stk_conv_from_utf8(s, cs_out) stk_conv(s, CONV_CHARSET_UTF8, cs_out)
25 uns stk_conv_internal(struct conv_context *c, byte *s, uns cs_in, uns cs_out);