]> mj.ucw.cz Git - libucw.git/blob - charset/stk-charconv.c
Conversion between charsets with allocation on the stack
[libucw.git] / charset / stk-charconv.c
1 /*
2  *      Sherlock Library -- Character Conversion with Allocation on the Stack 
3  *
4  *      (c) 2006 Pavel Charvat <pchar@ucw.cz>
5  */
6
7 #include "lib/lib.h"
8 #include "charset/stk-charconv.h"
9 #include <string.h>
10
11 uns
12 stk_conv_internal(struct conv_context *c, byte *s, uns in_cs, uns out_cs)
13 {
14   /* We do not allocate anything for identical charsets. */
15   if (in_cs == out_cs)
16     {
17       c->dest_start = s;
18       return 0;
19     }  
20   
21   uns l = strlen(s);
22   
23   conv_init(c);
24   conv_set_charset(c, in_cs, out_cs);
25   c->source = s;
26   c->source_end = s + l + 1;
27
28   /* Resulting string can be longer after the conversion.
29    * The following constatnt must be at least 4 for conversion to UTF-8
30    * and at least the maximum length of the strings in string_table for other charsets. */
31   return 4 * l + 1;
32 }