chiark / gitweb /
Some minor debianization fixes
[disorder] / lib / unicode.h
CommitLineData
e5a5a138
RK
1/*
2 * This file is part of DisOrde
3 * Copyright (C) 2007 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/** @file lib/unicode.h
21 * @brief Unicode support functions
22 */
23
24#ifndef UNICODE_H
25#define UNICODE_H
26
092f426f
RK
27/** @brief Smart pointer into a string
28 *
29 * Iterators can be efficiently moved either forwards or back to the start of
30 * the string. They cannot (currently) efficiently be moved backwards. Their
31 * advantage is that they remember internal state to speed up boundary
32 * detection.
33 *
34 * Iterators can point to any code point of the string, or to a hypothetical
35 * post-final code point of value 0, but not outside the string.
36 */
37typedef struct utf32_iterator_data *utf32_iterator;
38
c85b7022
RK
39/** @brief Property tailor function
40 * @param c Code point
41 * @return Tailored property or -1 to use standard value
42 *
43 * See also utf32_iterator_tailor_word_break().
44 */
45typedef int unicode_property_tailor(uint32_t c);
46
e5a5a138
RK
47char *utf32_to_utf8(const uint32_t *s, size_t ns, size_t *nd);
48uint32_t *utf8_to_utf32(const char *s, size_t ns, size_t *nd);
18cda350 49int utf8_valid(const char *s, size_t ns);
e5a5a138 50
3c82b504
RK
51int utf32_combining_class(uint32_t c);
52
e5a5a138
RK
53size_t utf32_len(const uint32_t *s);
54int utf32_cmp(const uint32_t *a, const uint32_t *b);
55
56uint32_t *utf32_decompose_canon(const uint32_t *s, size_t ns, size_t *ndp);
57char *utf8_decompose_canon(const char *s, size_t ns, size_t *ndp);
58
59uint32_t *utf32_decompose_compat(const uint32_t *s, size_t ns, size_t *ndp);
60char *utf8_decompose_compat(const char *s, size_t ns, size_t *ndp);
61
16506c9d
RK
62uint32_t *utf32_compose_canon(const uint32_t *s, size_t ns, size_t *ndp);
63char *utf8_compose_canon(const char *s, size_t ns, size_t *ndp);
64
65uint32_t *utf32_compose_compat(const uint32_t *s, size_t ns, size_t *ndp);
66char *utf8_compose_compat(const char *s, size_t ns, size_t *ndp);
67
e5a5a138
RK
68uint32_t *utf32_casefold_canon(const uint32_t *s, size_t ns, size_t *ndp);
69char *utf8_casefold_canon(const char *s, size_t ns, size_t *ndp);
70
71uint32_t *utf32_casefold_compat(const uint32_t *s, size_t ns, size_t *ndp);
72char *utf8_casefold_compat(const char *s, size_t ns, size_t *ndp);
73
1625e11a 74int utf32_is_grapheme_boundary(const uint32_t *s, size_t ns, size_t n);
0b7052da 75int utf32_is_word_boundary(const uint32_t *s, size_t ns, size_t n);
e5a5a138 76
092f426f
RK
77utf32_iterator utf32_iterator_new(const uint32_t *s, size_t ns);
78void utf32_iterator_destroy(utf32_iterator it);
79
80size_t utf32_iterator_where(utf32_iterator it);
81int utf32_iterator_set(utf32_iterator it, size_t n);
82int utf32_iterator_advance(utf32_iterator it, size_t n);
83uint32_t utf32_iterator_code(utf32_iterator it);
84int utf32_iterator_grapheme_boundary(utf32_iterator it);
85int utf32_iterator_word_boundary(utf32_iterator it);
c85b7022
RK
86void utf32_iterator_tailor_word_break(utf32_iterator it,
87 unicode_property_tailor *pt);
092f426f 88
c85b7022
RK
89uint32_t **utf32_word_split(const uint32_t *s, size_t ns, size_t *nwp,
90 unicode_property_tailor *wbreak);
91char **utf8_word_split(const char *s, size_t ns, size_t *nwp,
92 unicode_property_tailor *wbreak);
8818b7fc 93
caecd4f4
RK
94/** @brief Convert 0-terminated UTF-32 to UTF-8
95 * @param s 0-terminated UTF-32 string
96 * @return 0-terminated UTF-8 string or 0 on error
97 *
98 * See utf32_to_utf8() for possible causes of errors.
99 */
100static inline char *utf32nt_to_utf8(const uint32_t *s) {
101 return utf32_to_utf8(s, utf32_len(s), 0);
102}
103
104/** @brief Convert 0-terminated UTF-8 to UTF-32
105 * @param s 0-terminated UTF-8 string
106 * @return 0-terminated UTF-32 string or 0 on error
107 *
108 * See utf8_to_utf32() for possible causes of errors.
109 */
110static inline uint32_t *utf8nt_to_utf32(const char *s) {
111 return utf8_to_utf32(s, strlen(s), 0);
112}
113
e5a5a138
RK
114#endif /* UNICODE_H */
115
116/*
117Local Variables:
118c-basic-offset:2
119comment-column:40
120fill-column:79
121indent-tabs-mode:nil
122End:
123*/