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). */
15 #define stk_conv(s, cs_in, cs_out) \
16 ({ struct stk_conv_context _c; stk_conv_init(&_c, (s), (cs_in), (cs_out)); \
17 while (stk_conv_step(&_c, alloca(_c.len))); _c.c.dest_start; })
19 #define stk_conv_to_utf8(s, cs_in) stk_conv(s, cs_in, CONV_CHARSET_UTF8)
20 #define stk_conv_from_utf8(s, cs_out) stk_conv(s, CONV_CHARSET_UTF8, cs_out)
22 /* Internal structure and routines. */
24 struct stk_conv_context {
25 struct conv_context c;
29 void stk_conv_init(struct stk_conv_context *c, byte *s, uns cs_in, uns cs_out);
30 int stk_conv_step(struct stk_conv_context *c, byte *buf);