DisOrder 3.0
[disorder] / lib / charset.h
1 /*
2 * This file is part of DisOrder.
3 * Copyright (C) 2004, 2005, 2007, 2008 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 char *mb2utf8(const char *mb);
28 char *utf82mb(const char *utf8);
29 /* various conversions, between multibyte strings (mb) in
30 * whatever the current encoding is, and UTF-8 strings (utf8). On
31 * error, a null pointer is returned and @errno@ set. */
32
33 char *any2utf8(const char *from/*encoding*/,
34 const char *any/*string*/);
35 /* arbitrary conversions from any null-free byte-based encoding that
36 * iconv knows about to UTF-8 */
37
38 char *any2mb(const char *from/*encoding or 0*/,
39 const char *any/*string*/);
40 /* Arbitrary conversions from any null-free byte-based encoding that
41 * iconv knows about to a multibyte string. If FROM is 0 then ANY is
42 * returned unchanged. */
43
44 char *any2any(const char *from/*encoding or 0*/,
45 const char *to/*encoding to 0*/,
46 const char *any/*string*/);
47 /* Arbitrary conversions between any null-free byte-based encodings
48 * that iconv knows. If FROM and TO are both 0 then ANY is returned
49 * unchanged. */
50
51 /** @brief Insist that @p s is not null
52 * @param s Pointer to check
53 * @return @p s
54 *
55 * Terminates the process if @p s is a null pointer.
56 */
57 static inline char *nullcheck(char *s) {
58 if(!s) exitfn(1); /* assume an error already reported */
59 return s;
60 }
61
62 const char *truncate_for_display(const char *s, long max);
63
64 #endif /* CHARSET_H */
65
66 /*
67 Local Variables:
68 c-basic-offset:2
69 comment-column:40
70 End:
71 */