wlt: fix shl_hook API changes
[platform/upstream/kmscon.git] / src / tsm_unicode.h
1 /*
2  * TSM - Unicode Handling
3  *
4  * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
5  * Copyright (c) 2011 University of Tuebingen
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files
9  * (the "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26
27 /*
28  * Unicode Helpers
29  * This file provides small helpers to make working with Unicode/UTF8/UCS4 input
30  * and output much easier.
31  */
32
33 #ifndef TSM_UNICODE_H
34 #define TSM_UNICODE_H
35
36 #include <inttypes.h>
37 #include <stdlib.h>
38
39 /* UCS4 helpers */
40
41 #define TSM_UCS4_MAX (0x7fffffffUL)
42 #define TSM_UCS4_INVALID (TSM_UCS4_MAX + 1)
43 #define TSM_UCS4_REPLACEMENT (0xfffdUL)
44 #define TSM_UCS4_MAXLEN 10
45
46 /* symbols */
47
48 struct tsm_symbol_table;
49 typedef uint32_t tsm_symbol_t;
50
51 extern const tsm_symbol_t tsm_symbol_default;
52
53 int tsm_symbol_table_new(struct tsm_symbol_table **out);
54 void tsm_symbol_table_ref(struct tsm_symbol_table *tbl);
55 void tsm_symbol_table_unref(struct tsm_symbol_table *tbl);
56
57 tsm_symbol_t tsm_symbol_make(uint32_t ucs4);
58 tsm_symbol_t tsm_symbol_append(struct tsm_symbol_table *tbl,
59                                tsm_symbol_t sym, uint32_t ucs4);
60 const uint32_t *tsm_symbol_get(struct tsm_symbol_table *tbl,
61                                tsm_symbol_t *sym, size_t *size);
62 unsigned int tsm_symbol_get_width(struct tsm_symbol_table *tbl,
63                                   tsm_symbol_t sym);
64
65 /* ucs4 to utf8 converter */
66
67 unsigned int tsm_ucs4_get_width(uint32_t ucs4);
68 size_t tsm_ucs4_to_utf8(uint32_t ucs4, char *out);
69 char *tsm_ucs4_to_utf8_alloc(const uint32_t *ucs4, size_t len, size_t *len_out);
70
71 /* utf8 state machine */
72
73 struct tsm_utf8_mach;
74
75 enum tsm_utf8_mach_state {
76         TSM_UTF8_START,
77         TSM_UTF8_ACCEPT,
78         TSM_UTF8_REJECT,
79         TSM_UTF8_EXPECT1,
80         TSM_UTF8_EXPECT2,
81         TSM_UTF8_EXPECT3,
82 };
83
84 int tsm_utf8_mach_new(struct tsm_utf8_mach **out);
85 void tsm_utf8_mach_free(struct tsm_utf8_mach *mach);
86
87 int tsm_utf8_mach_feed(struct tsm_utf8_mach *mach, char c);
88 uint32_t tsm_utf8_mach_get(struct tsm_utf8_mach *mach);
89 void tsm_utf8_mach_reset(struct tsm_utf8_mach *mach);
90
91 #endif /* TSM_UNICODE_H */