]> mj.ucw.cz Git - libucw.git/blob - charset/charconv.h
UCW::CGI: Announce supported methods correctly
[libucw.git] / charset / charconv.h
1 /*
2  *      Character Set Conversion Library 1.2
3  *
4  *      (c) 1998--2005 Martin Mares <mj@ucw.cz>
5  *      (c) 2007 Pavel Charvat <pchar@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #ifndef _CHARSET_CHARCONV_H
12 #define _CHARSET_CHARCONV_H
13
14 struct conv_context {
15
16   /* Parameters supplied by the caller */
17
18   const unsigned char *source;          /* Current position in source buffer */
19   const unsigned char *source_end;      /* End of source buffer */
20   unsigned char *dest;                  /* Current position in destination buffer */
21   unsigned char *dest_start;            /* First byte of destination buffer */
22   unsigned char *dest_end;              /* End of destination buffer */
23
24   /* Internal variables */
25
26   int (*convert)(struct conv_context *);
27   int source_charset, dest_charset;
28   unsigned short int *in_to_x;
29   unsigned short int *x_to_out;
30   unsigned int state, code, remains;
31   unsigned char *string_at;
32 };
33
34 void conv_init(struct conv_context *);
35 void conv_set_charset(struct conv_context *, int, int);
36 #define conv_run(c) ((c)->convert(c))
37
38 #define CONV_SOURCE_END 1
39 #define CONV_DEST_END 2
40 #define CONV_SKIP 4
41
42 enum charset_id {
43         CONV_CHARSET_ASCII,
44         CONV_CHARSET_ISO_8859_1,
45         CONV_CHARSET_ISO_8859_2,
46         CONV_CHARSET_ISO_8859_3,
47         CONV_CHARSET_ISO_8859_4,
48         CONV_CHARSET_ISO_8859_5,
49         CONV_CHARSET_ISO_8859_6,
50         CONV_CHARSET_ISO_8859_7,
51         CONV_CHARSET_ISO_8859_8,
52         CONV_CHARSET_ISO_8859_9,
53         CONV_CHARSET_ISO_8859_10,
54         CONV_CHARSET_ISO_8859_11,
55         CONV_CHARSET_ISO_8859_13,
56         CONV_CHARSET_ISO_8859_14,
57         CONV_CHARSET_ISO_8859_15,
58         CONV_CHARSET_ISO_8859_16,
59         CONV_CHARSET_WIN1250,
60         CONV_CHARSET_WIN1251,
61         CONV_CHARSET_WIN1252,
62         CONV_CHARSET_KAMCS,
63         CONV_CHARSET_CSN369103,
64         CONV_CHARSET_CP852,
65         CONV_CHARSET_MACCE,
66         CONV_CHARSET_CORK,
67         CONV_CHARSET_UTF8,
68         CONV_CHARSET_UTF16_BE,
69         CONV_CHARSET_UTF16_LE,
70         CONV_NUM_CHARSETS
71 };
72
73 /* Conversion of a single character between current non-UTF8 charset and Unicode */
74 int conv_in_to_ucs(struct conv_context *c, unsigned int y);
75 int conv_ucs_to_out(struct conv_context *c, unsigned int ucs);
76
77 /* For those brave ones who want to mess with charconv internals */
78 unsigned int conv_x_to_ucs(unsigned int x);
79 unsigned int conv_ucs_to_x(unsigned int ucs);
80 unsigned int conv_x_count(void);
81
82 /* Charset names */
83
84 int find_charset_by_name(const char *);
85 char *charset_name(int);
86
87 #endif