Commit | Line | Data |
---|---|---|
460b9539 | 1 | /* |
2 | * This file is part of DisOrder. | |
f74f4f32 | 3 | * Copyright (C) 2004, 2005, 2007-2009 Richard Kettlewell |
460b9539 | 4 | * |
e7eb3a27 | 5 | * This program is free software: you can redistribute it and/or modify |
460b9539 | 6 | * it under the terms of the GNU General Public License as published by |
e7eb3a27 | 7 | * the Free Software Foundation, either version 3 of the License, or |
460b9539 | 8 | * (at your option) any later version. |
e7eb3a27 RK |
9 | * |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
460b9539 | 15 | * You should have received a copy of the GNU General Public License |
e7eb3a27 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
460b9539 | 17 | */ |
132a5a4a | 18 | /** @file lib/charset.h @brief Character set conversion */ |
460b9539 | 19 | #ifndef CHARSET_H |
20 | #define CHARSET_H | |
21 | ||
05b75f8d RK |
22 | #include "log.h" |
23 | ||
13affe66 RK |
24 | struct dynstr; |
25 | ||
460b9539 | 26 | /* Character encoding conversion routines */ |
27 | ||
460b9539 | 28 | char *mb2utf8(const char *mb); |
29 | char *utf82mb(const char *utf8); | |
30 | /* various conversions, between multibyte strings (mb) in | |
31 | * whatever the current encoding is, and UTF-8 strings (utf8). On | |
32 | * error, a null pointer is returned and @errno@ set. */ | |
33 | ||
34 | char *any2utf8(const char *from/*encoding*/, | |
35 | const char *any/*string*/); | |
36 | /* arbitrary conversions from any null-free byte-based encoding that | |
37 | * iconv knows about to UTF-8 */ | |
38 | ||
39 | char *any2mb(const char *from/*encoding or 0*/, | |
40 | const char *any/*string*/); | |
41 | /* Arbitrary conversions from any null-free byte-based encoding that | |
42 | * iconv knows about to a multibyte string. If FROM is 0 then ANY is | |
43 | * returned unchanged. */ | |
44 | ||
45 | char *any2any(const char *from/*encoding or 0*/, | |
46 | const char *to/*encoding to 0*/, | |
47 | const char *any/*string*/); | |
48 | /* Arbitrary conversions between any null-free byte-based encodings | |
49 | * that iconv knows. If FROM and TO are both 0 then ANY is returned | |
50 | * unchanged. */ | |
51 | ||
f74f4f32 RK |
52 | char *mb2utf8_f(char *mb); |
53 | char *utf82mb_f(char *utf8); | |
54 | char *any2utf8_f(const char *from/*encoding*/, | |
55 | char *any/*string*/); | |
56 | char *any2mb_f(const char *from/*encoding or 0*/, | |
57 | char *any/*string*/); | |
58 | char *any2any_f(const char *from/*encoding or 0*/, | |
59 | const char *to/*encoding to 0*/, | |
60 | char *any/*string*/); | |
61 | ||
0e4472a0 | 62 | /** @brief Insist that @p s is not null |
63 | * @param s Pointer to check | |
64 | * @return @p s | |
65 | * | |
66 | * Terminates the process if @p s is a null pointer. | |
67 | */ | |
460b9539 | 68 | static inline char *nullcheck(char *s) { |
69 | if(!s) exitfn(1); /* assume an error already reported */ | |
70 | return s; | |
71 | } | |
72 | ||
61507e3c RK |
73 | const char *truncate_for_display(const char *s, long max); |
74 | ||
460b9539 | 75 | #endif /* CHARSET_H */ |
76 | ||
77 | /* | |
78 | Local Variables: | |
79 | c-basic-offset:2 | |
80 | comment-column:40 | |
81 | End: | |
82 | */ |