2 * Sherlock Library -- Character Conversion with Allocation on the Stack
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <charset/stk-charconv.h>
14 #define INITIAL_MIN_SIZE 16
15 #define INITIAL_SCALE 2
18 stk_strconv_init(struct conv_context *c, const byte *s, uint in_cs, uint out_cs)
28 conv_set_charset(c, in_cs, out_cs);
30 c->source_end = s + l + 1;
31 if (l < (INITIAL_MIN_SIZE - 1) / INITIAL_SCALE)
32 return INITIAL_MIN_SIZE;
34 return l * INITIAL_SCALE + 1;
38 stk_strconv_step(struct conv_context *c, byte *buf, uint len)
42 memcpy(buf, c->source, len);
48 uint l = c->dest_end - c->dest_start;
49 memcpy(buf, c->dest_start, l);
55 c->dest_end = buf + len;
56 if (conv_run(c) & CONV_SOURCE_END)