chiark / gitweb /
even chattier logging
[disorder] / lib / charset.h
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004, 2005 Richard Kettlewell
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20 #ifndef CHARSET_H
21 #define CHARSET_H
22
23 struct dynstr;
24
25 /* Character encoding conversion routines */
26
27 int one_ucs42utf8(uint32_t c, struct dynstr *d);
28
29 uint32_t *utf82ucs4(const char *mb);
30 char *ucs42utf8(const uint32_t *u);
31 char *mb2utf8(const char *mb);
32 char *utf82mb(const char *utf8);
33 /* various conversions, between multibyte strings (mb) in
34  * whatever the current encoding is, and UTF-8 strings (utf8).  On
35  * error, a null pointer is returned and @errno@ set. */
36
37 char *any2utf8(const char *from/*encoding*/,
38                const char *any/*string*/);
39 /* arbitrary conversions from any null-free byte-based encoding that
40  * iconv knows about to UTF-8 */
41
42 char *any2mb(const char *from/*encoding or 0*/,
43              const char *any/*string*/);
44 /* Arbitrary conversions from any null-free byte-based encoding that
45  * iconv knows about to a multibyte string.  If FROM is 0 then ANY is
46  * returned unchanged. */
47
48 char *any2any(const char *from/*encoding or 0*/,
49               const char *to/*encoding to 0*/,
50               const char *any/*string*/);
51 /* Arbitrary conversions between any null-free byte-based encodings
52  * that iconv knows.  If FROM and TO are both 0 then ANY is returned
53  * unchanged. */
54
55 /** @brief Insist that @p s is not null
56  * @param s Pointer to check
57  * @return @p s
58  *
59  * Terminates the process if @p s is a null pointer.
60  */
61 static inline char *nullcheck(char *s) {
62   if(!s) exitfn(1);                     /* assume an error already reported */
63   return s;
64 }
65
66 int ucs4cmp(const uint32_t *a, const uint32_t *b);
67 /* like strcmp */
68
69 #endif /* CHARSET_H */
70
71 /*
72 Local Variables:
73 c-basic-offset:2
74 comment-column:40
75 End:
76 */