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