|
Possible bug in allegro utf8 function |
archlinka
Member #17,215
December 2019
|
Hi, I was just looking to Allegro source code and foundsome strange situation. Or it's also possible that I just do not understand the code: 1/* Function: al_ustr_find_set
2 */
3int al_ustr_find_set(const ALLEGRO_USTR *us, int start_pos,
4 const ALLEGRO_USTR *accept)
5{
6 int rc;
7 int32_t c, d;
8 int pos;
9 int set_pos;
10
11 /* Fast path for ASCII characters. */
12 if (all_ascii(accept)) {
13 rc = _al_binchr(us, start_pos, accept);
14 return (rc == _AL_BSTR_ERR) ? -1 : rc;
15 }
16
17 /* Non-ASCII. */
18 pos = 0;
19 while ((c = al_ustr_get(us, pos)) != -1) {
20 if (c == -2) {
21 /* Invalid byte sequence. */
22 pos++;
23 continue;
24 }
25
26 set_pos = 0;
27 while ((d = al_ustr_get_next(accept, &set_pos)) != -1) {
28 if (c == d)
29 return pos;
30 }
31
32 pos += al_utf8_width(c);
33 }
34
35 return -1;
36}
It should find first occurrence of code point starting at pos start_pos. The thing I do not understand is that the argument start_pos is used only in one place in the function and that's the ASCII only branch. But not in the non ASCII. Is it bug or just there is something I do not see? |
amarillion
Member #940
January 2001
|
I think you're right, this looks like a bug. -- |
Peter Hull
Member #1,136
March 2001
|
I agree, if you've got time please could you create an issue on the github? Thanks.
|
|