1 #ifndef __al_included_allegro5_utf8_h
2 #define __al_included_allegro5_utf8_h
3 
4 #include "allegro5/base.h"
5 
6 #ifdef __cplusplus
7    extern "C" {
8 #endif
9 
10 /* Type: ALLEGRO_USTR
11  */
12 typedef struct _al_tagbstring ALLEGRO_USTR;
13 
14 /* Type: ALLEGRO_USTR_INFO
15  */
16 typedef struct _al_tagbstring ALLEGRO_USTR_INFO;
17 
18 #ifndef __al_tagbstring_defined
19 #define __al_tagbstring_defined
20 struct _al_tagbstring {
21 	int mlen;
22 	int slen;
23 	unsigned char * data;
24 };
25 #endif
26 
27 /* Creating strings */
28 AL_FUNC(ALLEGRO_USTR *, al_ustr_new, (const char *s));
29 AL_FUNC(ALLEGRO_USTR *, al_ustr_new_from_buffer, (const char *s, size_t size));
30 AL_PRINTFUNC(ALLEGRO_USTR *, al_ustr_newf, (const char *fmt, ...), 1, 2);
31 AL_FUNC(void, al_ustr_free, (ALLEGRO_USTR *us));
32 AL_FUNC(const char *, al_cstr, (const ALLEGRO_USTR *us));
33 AL_FUNC(void, al_ustr_to_buffer, (const ALLEGRO_USTR *us, char *buffer, int size));
34 AL_FUNC(char *, al_cstr_dup, (const ALLEGRO_USTR *us));
35 AL_FUNC(ALLEGRO_USTR *, al_ustr_dup, (const ALLEGRO_USTR *us));
36 AL_FUNC(ALLEGRO_USTR *, al_ustr_dup_substr, (const ALLEGRO_USTR *us,
37       int start_pos, int end_pos));
38 
39 /* Predefined string */
40 AL_FUNC(const ALLEGRO_USTR *, al_ustr_empty_string, (void));
41 
42 /* Reference strings */
43 AL_FUNC(const ALLEGRO_USTR *, al_ref_cstr, (ALLEGRO_USTR_INFO *info, const char *s));
44 AL_FUNC(const ALLEGRO_USTR *, al_ref_buffer, (ALLEGRO_USTR_INFO *info, const char *s,
45       size_t size));
46 AL_FUNC(const ALLEGRO_USTR *, al_ref_ustr, (ALLEGRO_USTR_INFO *info,
47       const ALLEGRO_USTR *us, int start_pos, int end_pos));
48 
49 /* Sizes and offsets */
50 AL_FUNC(size_t, al_ustr_size, (const ALLEGRO_USTR *us));
51 AL_FUNC(size_t, al_ustr_length, (const ALLEGRO_USTR *us));
52 AL_FUNC(int, al_ustr_offset, (const ALLEGRO_USTR *us, int index));
53 AL_FUNC(bool, al_ustr_next, (const ALLEGRO_USTR *us, int *pos));
54 AL_FUNC(bool, al_ustr_prev, (const ALLEGRO_USTR *us, int *pos));
55 
56 /* Get codepoints */
57 AL_FUNC(int32_t, al_ustr_get, (const ALLEGRO_USTR *us, int pos));
58 AL_FUNC(int32_t, al_ustr_get_next, (const ALLEGRO_USTR *us, int *pos));
59 AL_FUNC(int32_t, al_ustr_prev_get, (const ALLEGRO_USTR *us, int *pos));
60 
61 /* Insert */
62 AL_FUNC(bool, al_ustr_insert, (ALLEGRO_USTR *us1, int pos,
63       const ALLEGRO_USTR *us2));
64 AL_FUNC(bool, al_ustr_insert_cstr, (ALLEGRO_USTR *us, int pos,
65       const char *us2));
66 AL_FUNC(size_t, al_ustr_insert_chr, (ALLEGRO_USTR *us, int pos, int32_t c));
67 
68 /* Append */
69 AL_FUNC(bool, al_ustr_append, (ALLEGRO_USTR *us1, const ALLEGRO_USTR *us2));
70 AL_FUNC(bool, al_ustr_append_cstr, (ALLEGRO_USTR *us, const char *s));
71 AL_FUNC(size_t, al_ustr_append_chr, (ALLEGRO_USTR *us, int32_t c));
72 AL_PRINTFUNC(bool, al_ustr_appendf, (ALLEGRO_USTR *us, const char *fmt, ...),
73       2, 3);
74 AL_FUNC(bool, al_ustr_vappendf, (ALLEGRO_USTR *us, const char *fmt,
75       va_list ap));
76 
77 /* Remove */
78 AL_FUNC(bool, al_ustr_remove_chr, (ALLEGRO_USTR *us, int pos));
79 AL_FUNC(bool, al_ustr_remove_range, (ALLEGRO_USTR *us, int start_pos,
80       int end_pos));
81 AL_FUNC(bool, al_ustr_truncate, (ALLEGRO_USTR *us, int start_pos));
82 AL_FUNC(bool, al_ustr_ltrim_ws, (ALLEGRO_USTR *us));
83 AL_FUNC(bool, al_ustr_rtrim_ws, (ALLEGRO_USTR *us));
84 AL_FUNC(bool, al_ustr_trim_ws, (ALLEGRO_USTR *us));
85 
86 /* Assign */
87 AL_FUNC(bool, al_ustr_assign, (ALLEGRO_USTR *us1, const ALLEGRO_USTR *us2));
88 AL_FUNC(bool, al_ustr_assign_substr, (ALLEGRO_USTR *us1, const ALLEGRO_USTR *us2,
89       int start_pos, int end_pos));
90 AL_FUNC(bool, al_ustr_assign_cstr, (ALLEGRO_USTR *us1, const char *s));
91 
92 /* Replace */
93 AL_FUNC(size_t, al_ustr_set_chr, (ALLEGRO_USTR *us, int pos, int32_t c));
94 AL_FUNC(bool, al_ustr_replace_range, (ALLEGRO_USTR *us1, int start_pos1,
95       int end_pos1, const ALLEGRO_USTR *us2));
96 
97 /* Searching */
98 AL_FUNC(int, al_ustr_find_chr, (const ALLEGRO_USTR *us, int start_pos,
99       int32_t c));
100 AL_FUNC(int, al_ustr_rfind_chr, (const ALLEGRO_USTR *us, int start_pos,
101       int32_t c));
102 AL_FUNC(int, al_ustr_find_set, (const ALLEGRO_USTR *us, int start_pos,
103       const ALLEGRO_USTR *accept));
104 AL_FUNC(int, al_ustr_find_set_cstr, (const ALLEGRO_USTR *us, int start_pos,
105       const char *accept));
106 AL_FUNC(int, al_ustr_find_cset, (const ALLEGRO_USTR *us, int start_pos,
107       const ALLEGRO_USTR *reject));
108 AL_FUNC(int, al_ustr_find_cset_cstr, (const ALLEGRO_USTR *us, int start_pos,
109       const char *reject));
110 AL_FUNC(int, al_ustr_find_str, (const ALLEGRO_USTR *haystack, int start_pos,
111       const ALLEGRO_USTR *needle));
112 AL_FUNC(int, al_ustr_find_cstr, (const ALLEGRO_USTR *haystack, int start_pos,
113       const char *needle));
114 AL_FUNC(int, al_ustr_rfind_str, (const ALLEGRO_USTR *haystack, int start_pos,
115       const ALLEGRO_USTR *needle));
116 AL_FUNC(int, al_ustr_rfind_cstr, (const ALLEGRO_USTR *haystack, int start_pos,
117       const char *needle));
118 AL_FUNC(bool, al_ustr_find_replace, (ALLEGRO_USTR *us, int start_pos,
119       const ALLEGRO_USTR *find, const ALLEGRO_USTR *replace));
120 AL_FUNC(bool, al_ustr_find_replace_cstr, (ALLEGRO_USTR *us, int start_pos,
121       const char *find, const char *replace));
122 
123 /* Compare */
124 AL_FUNC(bool, al_ustr_equal, (const ALLEGRO_USTR *us1, const ALLEGRO_USTR *us2));
125 AL_FUNC(int, al_ustr_compare, (const ALLEGRO_USTR *u, const ALLEGRO_USTR *v));
126 AL_FUNC(int, al_ustr_ncompare, (const ALLEGRO_USTR *us1, const ALLEGRO_USTR *us2,
127       int n));
128 AL_FUNC(bool, al_ustr_has_prefix,(const ALLEGRO_USTR *u, const ALLEGRO_USTR *v));
129 AL_FUNC(bool, al_ustr_has_prefix_cstr, (const ALLEGRO_USTR *u, const char *s));
130 AL_FUNC(bool, al_ustr_has_suffix,(const ALLEGRO_USTR *u, const ALLEGRO_USTR *v));
131 AL_FUNC(bool, al_ustr_has_suffix_cstr,(const ALLEGRO_USTR *us1, const char *s));
132 
133 /* Low level UTF-8 functions */
134 AL_FUNC(size_t, al_utf8_width, (int32_t c));
135 AL_FUNC(size_t, al_utf8_encode, (char s[], int32_t c));
136 
137 /* UTF-16 */
138 AL_FUNC(ALLEGRO_USTR *, al_ustr_new_from_utf16, (uint16_t const *s));
139 AL_FUNC(size_t, al_ustr_size_utf16, (const ALLEGRO_USTR *us));
140 AL_FUNC(size_t, al_ustr_encode_utf16, (const ALLEGRO_USTR *us, uint16_t *s, size_t n));
141 AL_FUNC(size_t, al_utf16_width, (int c));
142 AL_FUNC(size_t, al_utf16_encode, (uint16_t s[], int32_t c));
143 
144 #ifdef __cplusplus
145    }
146 #endif
147 
148 #endif
149 
150 /* vim: set sts=3 sw=3 et: */
151