chiark / gitweb /
replace main utf-8 parser with table-driven one
[disorder] / lib / charset.h
CommitLineData
460b9539 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
13affe66
RK
23struct dynstr;
24
460b9539 25/* Character encoding conversion routines */
26
460b9539 27char *mb2utf8(const char *mb);
28char *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
33char *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
38char *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
44char *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
0e4472a0 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 */
460b9539 57static inline char *nullcheck(char *s) {
58 if(!s) exitfn(1); /* assume an error already reported */
59 return s;
60}
61
61507e3c
RK
62const char *truncate_for_display(const char *s, long max);
63
460b9539 64#endif /* CHARSET_H */
65
66/*
67Local Variables:
68c-basic-offset:2
69comment-column:40
70End:
71*/