X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=charset%2Fstk-charconv.h;h=3b47940f317d63ce7f99e943b3512835d26cccbd;hb=8c48090e240d68564c79eb29ac9004cc911bb5d0;hp=d63ba746efcd143527936e086545cb10ad79b57f;hpb=32ffcf1473c7bbba040a4f067e272fd9e5e85274;p=libucw.git diff --git a/charset/stk-charconv.h b/charset/stk-charconv.h index d63ba746..3b47940f 100644 --- a/charset/stk-charconv.h +++ b/charset/stk-charconv.h @@ -1,7 +1,10 @@ /* - * Sherlock Library -- Character Conversion with Allocation on the Stack + * 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 @@ -10,18 +13,18 @@ #include "charset/charconv.h" #include -/* The following macros convert strings between given charsets (CONV_CHARSET_x). - * The resulting string is allocated on the stack with the exception of cs_in == cs_out, - * when the pointer to the input string is returned. */ +/* The following macros convert strings between given charsets (CONV_CHARSET_x). */ + +#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_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) -#define stk_conv(s, cs_in, cs_out) \ - ({ struct conv_context _c; uns _l=stk_conv_internal(&_c, (s), (cs_in), (cs_out)); \ - if (_l) { _c.dest=_c.dest_start=alloca(_l); _c.dest_end=_c.dest+_l; conv_run(&_c); } \ - _c.dest_start; }) +/* Internals */ -#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) - -uns stk_conv_internal(struct conv_context *c, byte *s, uns cs_in, uns cs_out); +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