1 module allegro5.utf8;
2 
3 import allegro5.internal.da5;
4 
5 import core.stdc.stdarg : va_list;
6 
7 nothrow @nogc extern (C)
8 {
9 	struct _al_tagbstring
10 	{
11 		int mlen;
12 		int slen;
13 		char* data;
14 	}
15 	
16 	alias _al_tagbstring ALLEGRO_USTR;
17 	alias _al_tagbstring ALLEGRO_USTR_INFO;
18 	
19 	ALLEGRO_USTR* al_ustr_new(in char* s);
20 	ALLEGRO_USTR* al_ustr_new_from_buffer(in char* s, size_t size);
21 	ALLEGRO_USTR* al_ustr_newf(in char* fmt, ...);
22 	void al_ustr_free(ALLEGRO_USTR* us);
23 	const(char)* al_cstr(in ALLEGRO_USTR* us);
24 	void al_ustr_to_buffer(in ALLEGRO_USTR* us, char* buffer, int size);
25 	char* al_cstr_dup(in ALLEGRO_USTR* us);
26 	ALLEGRO_USTR* al_ustr_dup(in ALLEGRO_USTR* us);
27 	ALLEGRO_USTR* al_ustr_dup_substr(in ALLEGRO_USTR* us, int start_pos, int end_pos);
28 	
29 	/* Predefined string */
30 	const(ALLEGRO_USTR)* al_ustr_empty_string();
31 
32 	/* Reference strings */
33 	const(ALLEGRO_USTR)* al_ref_cstr(ALLEGRO_USTR_INFO* info, in char* s);
34 	const(ALLEGRO_USTR)* al_ref_buffer(ALLEGRO_USTR_INFO* info, in char* s, size_t size);
35 	const(ALLEGRO_USTR)* al_ref_ustr(ALLEGRO_USTR_INFO* info, in ALLEGRO_USTR* us, int start_pos, int end_pos);
36 
37 	/* Sizes and offsets */
38 	size_t al_ustr_size(in ALLEGRO_USTR* us);
39 	size_t al_ustr_length(in ALLEGRO_USTR* us);
40 	int al_ustr_offset(in ALLEGRO_USTR* us, int index);
41 	bool al_ustr_next(in ALLEGRO_USTR* us, int* pos);
42 	bool al_ustr_prev(in ALLEGRO_USTR* us, int* pos);
43 
44 	/* Get codepoints */
45 	int al_ustr_get(in ALLEGRO_USTR* us, int pos);
46 	int al_ustr_get_next(in ALLEGRO_USTR* us, int* pos);
47 	int al_ustr_prev_get(in ALLEGRO_USTR* us, int* pos);
48 
49 	/* Insert */
50 	bool al_ustr_insert(ALLEGRO_USTR* us1, int pos, in ALLEGRO_USTR* us2);
51 	bool al_ustr_insert_cstr(ALLEGRO_USTR* us, int pos, in char* us2);
52 	size_t al_ustr_insert_chr(ALLEGRO_USTR* us, int pos, int c);
53 
54 	/* Append */
55 	bool al_ustr_append(ALLEGRO_USTR* us1, in ALLEGRO_USTR* us2);
56 	bool al_ustr_append_cstr(ALLEGRO_USTR* us, in char* s);
57 	size_t al_ustr_append_chr(ALLEGRO_USTR* us, int c);
58 	bool al_ustr_appendf(ALLEGRO_USTR* us, in char* fmt, ...);
59 	bool al_ustr_vappendf(ALLEGRO_USTR* us, in char* fmt, va_list ap);
60 
61 	/* Remove */
62 	bool al_ustr_remove_chr(ALLEGRO_USTR* us, int pos);
63 	bool al_ustr_remove_range(ALLEGRO_USTR* us, int start_pos, int end_pos);
64 	bool al_ustr_truncate(ALLEGRO_USTR* us, int start_pos);
65 	bool al_ustr_ltrim_ws(ALLEGRO_USTR* us);
66 	bool al_ustr_rtrim_ws(ALLEGRO_USTR* us);
67 	bool al_ustr_trim_ws(ALLEGRO_USTR* us);
68 
69 	/* Assign */
70 	bool al_ustr_assign(ALLEGRO_USTR* us1, in ALLEGRO_USTR* us2);
71 	bool al_ustr_assign_substr(ALLEGRO_USTR* us1, in ALLEGRO_USTR* us2, int start_pos, int end_pos);
72 	bool al_ustr_assign_cstr(ALLEGRO_USTR* us1, in char* s);
73 
74 	/* Replace */
75 	size_t al_ustr_set_chr(ALLEGRO_USTR* us, int pos, int c);
76 	bool al_ustr_replace_range(ALLEGRO_USTR* us1, int start_pos1, int end_pos1, in ALLEGRO_USTR* us2);
77 
78 	/* Searching */
79 	int al_ustr_find_chr(in ALLEGRO_USTR* us, int start_pos, int c);
80 	int al_ustr_rfind_chr(in ALLEGRO_USTR* us, int start_pos, int c);
81 	int al_ustr_find_set(in ALLEGRO_USTR* us, int start_pos, in ALLEGRO_USTR* accept);
82 	int al_ustr_find_set_cstr(in ALLEGRO_USTR* us, int start_pos, in char* accept);
83 	int al_ustr_find_cset(in ALLEGRO_USTR* us, int start_pos, in ALLEGRO_USTR* reject);
84 	int al_ustr_find_cset_cstr(in ALLEGRO_USTR* us, int start_pos, in char* reject);
85 	int al_ustr_find_str(in ALLEGRO_USTR* haystack, int start_pos, in ALLEGRO_USTR* needle);
86 	int al_ustr_find_cstr(in ALLEGRO_USTR* haystack, int start_pos, in char* needle);
87 	int al_ustr_rfind_str(in ALLEGRO_USTR* haystack, int start_pos, in ALLEGRO_USTR* needle);
88 	int al_ustr_rfind_cstr(in ALLEGRO_USTR* haystack, int start_pos, in char* needle);
89 	bool al_ustr_find_replace(ALLEGRO_USTR* us, int start_pos, in ALLEGRO_USTR* find, in ALLEGRO_USTR* replace);
90 	bool al_ustr_find_replace_cstr(ALLEGRO_USTR* us, int start_pos, in char* find, in char* replace);
91 
92 	/* Compare */
93 	bool al_ustr_equal(in ALLEGRO_USTR* us1, in ALLEGRO_USTR* us2);
94 	int al_ustr_compare(in ALLEGRO_USTR* u, in ALLEGRO_USTR* v);
95 	int al_ustr_ncompare(in ALLEGRO_USTR* us1, in ALLEGRO_USTR* us2, int n);
96 	bool al_ustr_has_prefix(in ALLEGRO_USTR* u, in ALLEGRO_USTR* v);
97 	bool al_ustr_has_prefix_cstr(in ALLEGRO_USTR* u, in char* s);
98 	bool al_ustr_has_suffix(in ALLEGRO_USTR* u, in ALLEGRO_USTR* v);
99 	bool al_ustr_has_suffix_cstr(in ALLEGRO_USTR* us1, in char* s);
100 
101 	/* Low level UTF-8 functions */
102 	size_t al_utf8_width(int c);
103 	size_t al_utf8_encode(char* s, int c);
104 
105 	/* UTF-16 */
106 	ALLEGRO_USTR* al_ustr_new_from_utf16(in ushort* s);
107 	size_t al_ustr_size_utf16(in ALLEGRO_USTR* us);
108 	size_t al_ustr_encode_utf16(in ALLEGRO_USTR* us, ushort* s, size_t n);
109 	size_t al_utf16_width(int c);
110 	size_t al_utf16_encode(ushort* s, int c);
111 }