Imported Upstream version 0.63.0
[hcoop/debian/courier-authlib.git] / unicode / unicode2.c
1 /*
2 ** Copyright 2000-2003 Double Precision, Inc.
3 ** See COPYING for distribution information.
4 **
5 ** $Id: unicode2.c,v 1.3 2003/03/07 00:47:31 mrsam Exp $
6 */
7
8 #include "unicode_config.h"
9 #include "unicode.h"
10 #include <string.h>
11 #include <ctype.h>
12 #include <stdlib.h>
13
14 char *unicode_toutf8(const unicode_char *u)
15 {
16 return (unicode_utf8_fromu(u, 0));
17 }
18
19 unicode_char *unicode_fromutf8(const char *c)
20 {
21 return (unicode_utf8_tou(c, 0));
22 }
23
24 char *unicode_ctoutf8(const struct unicode_info *ui, const char *c,
25 int *err)
26 {
27 unicode_char *uc= (*ui->c2u)(ui, c, err);
28 char *p;
29
30 if (!uc) return (0);
31
32 p=unicode_utf8_fromu(uc, err);
33 if (err && *err > 0)
34 *err=0;
35
36 free(uc);
37 return (p);
38 }
39
40 char *unicode_cfromutf8(const struct unicode_info *ui, const char *c,
41 int *err)
42 {
43 unicode_char *uc;
44 char *p;
45
46 uc=unicode_utf8_tou(c, err);
47 if (!uc) return (0);
48
49 p=(*ui->u2c)(ui, uc, err);
50 free(uc);
51 if (err && *err > 0)
52 *err=0;
53 return (p);
54 }