]> mj.ucw.cz Git - libucw.git/blob - charset/stk-charconv.h
c0d8568f0f43341192579e9b04294fb7ed05346a
[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
7 #ifndef _STK_CHARCONV_H
8 #define _STK_CHARCONV_H
9
10 #include "charset/charconv.h"
11 #include <alloca.h>
12
13 #define stk_conv(s, cs_in, cs_out) \
14     ({ struct conv_context _c; uns _l=stk_conv_internal(&_c, (s), (cs_in), (cs_out)); \
15     if (_l) { _c.dest=_c.dest_start=alloca(_l); _c.dest_end=_c.dest+_l; conv_run(&_c); } \
16     _c.dest_start; })
17
18 #define stk_conv_to_utf8(s, cs_in) stk_conv(s, cs_in, CONV_CHARSET_UTF8)
19 #define stk_conv_from_utf8(s, cs_out) stk_conv(s, CONV_CHARSET_UTF8, cs_out)
20     
21 uns stk_conv_internal(struct conv_context *, byte *, uns, uns);
22
23 #endif