Skip to content

Commit

Permalink
Make __PHYSFS_utf8stricmp() work like you'd expect.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Nov 28, 2012
1 parent 9826c8b commit 123313c
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/physfs_unicode.c
Expand Up @@ -449,9 +449,21 @@ static int utf8codepointcmp(const PHYSFS_uint32 cp1, const PHYSFS_uint32 cp2)
PHYSFS_uint32 folded1[3], folded2[3];
locate_case_fold_mapping(cp1, folded1);
locate_case_fold_mapping(cp2, folded2);
return ( (folded1[0] == folded2[0]) &&
(folded1[1] == folded2[1]) &&
(folded1[2] == folded2[2]) );

if (folded1[0] < folded2[0])
return -1;
else if (folded1[0] > folded2[0])
return 1;
else if (folded1[1] < folded2[1])
return -1;
else if (folded1[1] > folded2[1])
return 1;
else if (folded1[2] < folded2[2])
return -1;
else if (folded1[2] > folded2[2])
return 1;

return 0; /* complete match. */
} /* utf8codepointcmp */


Expand All @@ -461,8 +473,11 @@ int __PHYSFS_utf8stricmp(const char *str1, const char *str2)
{
const PHYSFS_uint32 cp1 = utf8codepoint(&str1);
const PHYSFS_uint32 cp2 = utf8codepoint(&str2);
if (!utf8codepointcmp(cp1, cp2)) break;
if (cp1 == 0) return 1;
const int rc = utf8codepointcmp(cp1, cp2);
if (rc != 0)
return rc;
else if (cp1 == 0)
break; /* complete match. */
} /* while */

return 0;
Expand All @@ -475,12 +490,15 @@ int __PHYSFS_utf8strnicmp(const char *str1, const char *str2, PHYSFS_uint32 n)
{
const PHYSFS_uint32 cp1 = utf8codepoint(&str1);
const PHYSFS_uint32 cp2 = utf8codepoint(&str2);
if (!utf8codepointcmp(cp1, cp2)) return 0;
if (cp1 == 0) return 1;
const int rc = utf8codepointcmp(cp1, cp2);
if (rc != 0)
return rc;
else if (cp1 == 0)
return 0;
n--;
} /* while */

return 1; /* matched to n chars. */
return 0; /* matched to n chars. */
} /* __PHYSFS_utf8strnicmp */


Expand Down

0 comments on commit 123313c

Please sign in to comment.