extras/ignorecase.c
changeset 1556 1399fe45e5b9
parent 1544 7f6020ee746c
child 1631 1aec60db9326
child 1637 f83d05e87212
equal deleted inserted replaced
1555:5495a0e50b5e 1556:1399fe45e5b9
    25  *  Please see LICENSE.txt in the root of the source tree.
    25  *  Please see LICENSE.txt in the root of the source tree.
    26  *
    26  *
    27  *  \author Ryan C. Gordon.
    27  *  \author Ryan C. Gordon.
    28  */
    28  */
    29 
    29 
    30 /* I'm not screwing around with stricmp vs. strcasecmp... */
       
    31 /* !!! FIXME-3.0: this will NOT work with UTF-8 strings in physfs2.0 */
       
    32 static int caseInsensitiveStringCompare(const char *x, const char *y)
       
    33 {
       
    34     int ux, uy;
       
    35     do
       
    36     {
       
    37         ux = toupper((int) *x);
       
    38         uy = toupper((int) *y);
       
    39         if (ux != uy)
       
    40             return ((ux > uy) ? 1 : -1);
       
    41         x++;
       
    42         y++;
       
    43     } while ((ux) && (uy));
       
    44 
       
    45     return 0;
       
    46 } /* caseInsensitiveStringCompare */
       
    47 
       
    48 
       
    49 static int locateOneElement(char *buf)
    30 static int locateOneElement(char *buf)
    50 {
    31 {
    51     char *ptr;
    32     char *ptr;
    52     char **rc;
    33     char **rc;
    53     char **i;
    34     char **i;
    69         ptr++;  /* point past dirsep to entry itself. */
    50         ptr++;  /* point past dirsep to entry itself. */
    70     } /* else */
    51     } /* else */
    71 
    52 
    72     for (i = rc; *i != NULL; i++)
    53     for (i = rc; *i != NULL; i++)
    73     {
    54     {
    74         if (caseInsensitiveStringCompare(*i, ptr) == 0)
    55         if (PHYSFS_utf8stricmp(*i, ptr) == 0)
    75         {
    56         {
    76             strcpy(ptr, *i); /* found a match. Overwrite with this case. */
    57             strcpy(ptr, *i); /* found a match. Overwrite with this case. */
    77             PHYSFS_freeList(rc);
    58             PHYSFS_freeList(rc);
    78             return 1;
    59             return 1;
    79         } /* if */
    60         } /* if */