]> mj.ucw.cz Git - libucw.git/blobdiff - charset/stk-charconv.h
log output: Fix of a bug introduced during cleanups
[libucw.git] / charset / stk-charconv.h
index c0d8568f0f43341192579e9b04294fb7ed05346a..1eb368d11cb5490aaeff8e3ff9fb90cf8f02589d 100644 (file)
@@ -1,23 +1,30 @@
 /*
- *     Sherlock Library -- Character Conversion with Allocation on the Stack 
+ *     Sherlock Library -- Character Conversion with Allocation on the Stack
  *
  *     (c) 2006 Pavel Charvat <pchar@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
-#ifndef _STK_CHARCONV_H
-#define _STK_CHARCONV_H
+#ifndef _CHARSET_STK_CHARCONV_H
+#define _CHARSET_STK_CHARCONV_H
 
 #include "charset/charconv.h"
 #include <alloca.h>
 
-#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; })
+/* 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)
+
+/* 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 *, byte *, uns, uns);
+uns stk_strconv_init(struct conv_context *c, const byte *s, uns cs_in, uns cs_out);
+uns stk_strconv_step(struct conv_context *c, byte *buf, uns len);
 
 #endif