/* Test al_ustr_find_set, al_ustr_find_set_cstr (invalid values). */ static void t34(void) { ALLEGRO_USTR *us = al_ustr_new("a\x80ábdðeéfghií"); /* Invalid byte sequence in search string. */ CHECK(al_ustr_find_set_cstr(us, 0, "gfe") == 8); /* Invalid byte sequence in accept set. */ CHECK(al_ustr_find_set_cstr(us, 0, "é\x80ðf") == 6); al_ustr_free(us); }
//return the new start int wz_find_eol(ALLEGRO_USTR* text, ALLEGRO_FONT* font, float max_width, int start, int* end) { int a, b; int first = 1; int last = 0; a = start; while(1) { ALLEGRO_USTR_INFO info; ALLEGRO_USTR* token; float len; /* Find the end of current token */ b = al_ustr_find_set_cstr(text, a, "\t\n "); if(b == -1) //found nothing { b = al_ustr_size(text); //this is the last whole word last = 1; } /* Check to see if the token fits */ token = al_ref_ustr(&info, text, start, b); len = al_get_ustr_width(font, token); if (len < max_width || first) { if(last) { *end = b + 1; return -1; } } else //we return the last num { *end = a - 1; return a; } /* Check what character we found */ { int character = al_ustr_get(text, b); if(character == '\n') { *end = b; return b + 1; } } a = b + 1; first = 0; } }
/* Test al_ustr_find_set, al_ustr_find_set_cstr. */ static void t33(void) { ALLEGRO_USTR *us = al_ustr_new("aábdðeéfghiíaábdðeéfghií"); /* al_ustr_find_set_cstr is s simple wrapper for al_ustr_find_set * so we test using that. */ /* Find ASCII. */ CHECK(al_ustr_find_set_cstr(us, 0, "gfe") == 7); CHECK(al_ustr_find_set_cstr(us, 7, "gfe") == 7); /* start_pos inclusive */ CHECK(al_ustr_find_set_cstr(us, 0, "") == -1); CHECK(al_ustr_find_set_cstr(us, 0, "xyz") == -1); /* Find non-ASCII. */ CHECK(al_ustr_find_set_cstr(us, 0, "éðf") == 5); CHECK(al_ustr_find_set_cstr(us, 5, "éðf") == 5); /* start_pos inclusive */ CHECK(al_ustr_find_set_cstr(us, 0, "ẋỹƶ") == -1); al_ustr_free(us); }
int _al_parse_key_binding(const char *s, unsigned int *modifiers) { ALLEGRO_USTR *us; unsigned start = 0; int keycode = 0; us = al_ustr_new(s); al_ustr_trim_ws(us); *modifiers = 0; while (start < al_ustr_size(us)) { /* XXX not all keys can be bound due to a conflict with the delimiter * characters */ int end = al_ustr_find_set_cstr(us, start, "+-"); unsigned int mod; /* Last component must be a key. */ if (end == -1) { keycode = match_key_name(al_cstr(us) + start); break; } /* Otherwise must be a modifier. */ al_ustr_set_chr(us, end, '\0'); mod = match_modifier(al_cstr(us) + start); if (!mod) { break; } (*modifiers) |= mod; start = end + 1; } al_ustr_free(us); return keycode; }