2 * Sherlock Library -- Character Conversion with Allocation on the Stack
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
8 #include "charset/stk-charconv.h"
11 #define INITIAL_MIN_SIZE 16
12 #define INITIAL_SCALE 2
15 stk_conv_init(struct stk_conv_context *c, byte *s, uns in_cs, uns out_cs)
21 c->c.source_end = NULL;
26 conv_set_charset(&c->c, in_cs, out_cs);
28 c->c.source_end = s + l + 1;
29 if (l < (INITIAL_MIN_SIZE - 1) / INITIAL_SCALE)
30 c->len = INITIAL_MIN_SIZE;
32 c->len = l * INITIAL_SCALE + 1;
37 stk_conv_step(struct stk_conv_context *c, byte *buf)
41 memcpy(buf, c->c.source, c->len);
42 c->c.dest_start = buf;
47 uns l = c->c.dest_end - c->c.dest_start;
48 memcpy(buf, c->c.dest_start, l);
53 c->c.dest_start = buf;
54 c->c.dest_end = buf + c->len;
55 if ((conv_run(&c->c) & CONV_SOURCE_END))