X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=charset%2Fstk-charconv.h;h=01a242cdc9887d5510ee47e2f34c15e9660938ef;hb=8ab69f51fccccbcae521bd7f7e3ae27146fd1217;hp=d8ae585c4fefa91d9e570ed77090bad63f002792;hpb=47fec72b685482a58561be68759e9a8f9059e6b5;p=libucw.git diff --git a/charset/stk-charconv.h b/charset/stk-charconv.h index d8ae585c..01a242cd 100644 --- a/charset/stk-charconv.h +++ b/charset/stk-charconv.h @@ -2,6 +2,9 @@ * Sherlock Library -- Character Conversion with Allocation on the Stack * * (c) 2006 Pavel Charvat + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ #ifndef _CHARSET_STK_CHARCONV_H @@ -12,25 +15,16 @@ /* The following macros convert strings between given charsets (CONV_CHARSET_x). */ -#define stk_conv(s, cs_in, cs_out) \ - ({ struct stk_conv_context _c; stk_conv_init(&_c, (s), (cs_in), (cs_out)); \ - while (stk_conv_step(&_c, alloca(_c.request))); _c.c.dest_start; }) +#define stk_strconv(s, cs_in, cs_out) \ + ({ struct conv_context _c; uns _l=stk_strconv_init(&_c, (s), (cs_in), (cs_out)); \ + while (_l) _l=stk_strconv_step(&_c, alloca(_l), _l); _c.dest_start; }) -#define stk_conv_to_utf8(s, cs_in) stk_conv(s, cs_in, CONV_CHARSET_UTF8) -#define stk_conv_from_utf8(s, cs_out) stk_conv(s, CONV_CHARSET_UTF8, cs_out) +#define stk_strconv_to_utf8(s, cs_in) stk_strconv(s, cs_in, CONV_CHARSET_UTF8) +#define stk_strconv_from_utf8(s, cs_out) stk_strconv(s, CONV_CHARSET_UTF8, cs_out) -/* Internal structure and routines. */ - -struct stk_conv_context { - struct conv_context c; - uns count; - uns sum; - uns request; - byte *buf[16]; - uns size[16]; -}; +/* Internals */ -void stk_conv_init(struct stk_conv_context *c, byte *s, uns cs_in, uns cs_out); -int stk_conv_step(struct stk_conv_context *c, byte *buf); +uns stk_strconv_init(struct conv_context *c, byte *s, uns cs_in, uns cs_out); +uns stk_strconv_step(struct conv_context *c, byte *buf, uns len); #endif