src/physfs_unicode.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1597 54086208785f
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
#define __PHYSICSFS_INTERNAL__
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
#include "physfs_internal.h"
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
     4
#include "physfs_casefolding.h"
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
     5
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
/*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 * From rfc3629, the UTF-8 spec:
1373
527ef3c6a2d6 HTTPS all the things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1351
diff changeset
     9
 *  https://www.ietf.org/rfc/rfc3629.txt
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
 *
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
 *   Char. number range  |        UTF-8 octet sequence
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
 *      (hexadecimal)    |              (binary)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
 *   --------------------+---------------------------------------------
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 *   0000 0000-0000 007F | 0xxxxxxx
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
 *   0000 0080-0000 07FF | 110xxxxx 10xxxxxx
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
 *   0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
 *   0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
/*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
 * This may not be the best value, but it's one that isn't represented
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
 *  in Unicode (0x10FFFF is the largest codepoint value). We return this
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
 *  value from utf8codepoint() if there's bogus bits in the
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
 *  stream. utf8codepoint() will turn this value into something
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
 *  reasonable (like a question mark), for text that wants to try to recover,
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
 *  whereas utf8valid() will use the value to determine if a string has bad
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
 *  bits.
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#define UNICODE_BOGUS_CHAR_VALUE 0xFFFFFFFF
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
/*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
 * This is the codepoint we currently return when there was bogus bits in a
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
 *  UTF-8 string. May not fly in Asian locales?
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
#define UNICODE_BOGUS_CHAR_CODEPOINT '?'
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
static PHYSFS_uint32 utf8codepoint(const char **_str)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    const char *str = *_str;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    PHYSFS_uint32 retval = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    PHYSFS_uint32 octet = (PHYSFS_uint32) ((PHYSFS_uint8) *str);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    PHYSFS_uint32 octet2, octet3, octet4;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
    if (octet == 0)  /* null terminator, end of string. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        return 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    else if (octet < 128)  /* one octet char: 0 to 127 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
        (*_str)++;  /* skip to next possible start of codepoint. */
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 998
diff changeset
    51
        return octet;
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    else if ((octet > 127) && (octet < 192))  /* bad (starts with 10xxxxxx). */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
        /*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
         * Apparently each of these is supposed to be flagged as a bogus
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
         *  char, instead of just resyncing to the next valid codepoint.
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
         */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
        (*_str)++;  /* skip to next possible start of codepoint. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
        return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    else if (octet < 224)  /* two octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    {
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
    66
        (*_str)++;  /* advance at least one byte in case of an error */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        octet -= (128+64);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
        octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
        if ((octet2 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
    72
        *_str += 1;  /* skip to next possible start of codepoint. */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
        retval = ((octet << 6) | (octet2 - 128));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        if ((retval >= 0x80) && (retval <= 0x7FF))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            return retval;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    else if (octet < 240)  /* three octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    {
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
    80
        (*_str)++;  /* advance at least one byte in case of an error */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
        octet -= (128+64+32);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
        octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
        if ((octet2 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
        octet3 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
        if ((octet3 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
    90
        *_str += 2;  /* skip to next possible start of codepoint. */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
        retval = ( ((octet << 12)) | ((octet2-128) << 6) | ((octet3-128)) );
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
        /* There are seven "UTF-16 surrogates" that are illegal in UTF-8. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
        switch (retval)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
            case 0xD800:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
            case 0xDB7F:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
            case 0xDB80:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
            case 0xDBFF:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
            case 0xDC00:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
            case 0xDF80:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
            case 0xDFFF:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
                return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
        } /* switch */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        /* 0xFFFE and 0xFFFF are illegal, too, so we check them at the edge. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
        if ((retval >= 0x800) && (retval <= 0xFFFD))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
            return retval;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
    else if (octet < 248)  /* four octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
    {
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   113
        (*_str)++;  /* advance at least one byte in case of an error */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
        octet -= (128+64+32+16);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
        octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
        if ((octet2 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
        octet3 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
        if ((octet3 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
        octet4 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
        if ((octet4 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   127
        *_str += 3;  /* skip to next possible start of codepoint. */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
        retval = ( ((octet << 18)) | ((octet2 - 128) << 12) |
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
                   ((octet3 - 128) << 6) | ((octet4 - 128)) );
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
        if ((retval >= 0x10000) && (retval <= 0x10FFFF))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
            return retval;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    /*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
     * Five and six octet sequences became illegal in rfc3629.
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
     *  We throw the codepoint away, but parse them to make sure we move
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
     *  ahead the right number of bytes and don't overflow the buffer.
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
     */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    else if (octet < 252)  /* five octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    {
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   142
        (*_str)++;  /* advance at least one byte in case of an error */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   159
        *_str += 4;  /* skip to next possible start of codepoint. */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
        return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    else  /* six octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    {
1163
e46c11bb2780 Make sure utf8codepoint() advances the pointer even on bogus input.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   165
        (*_str)++;  /* advance at least one byte in case of an error */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
        *_str += 6;  /* skip to next possible start of codepoint. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
        return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
    return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
} /* utf8codepoint */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   193
static PHYSFS_uint32 utf16codepoint(const PHYSFS_uint16 **_str)
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   194
{
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   195
    const PHYSFS_uint16 *src = *_str;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   196
    PHYSFS_uint32 cp = (PHYSFS_uint32) *(src++);
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   197
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   198
    if (cp == 0)  /* null terminator, end of string. */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   199
        return 0;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   200
    /* Orphaned second half of surrogate pair? */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   201
    else if ((cp >= 0xDC00) && (cp <= 0xDFFF))
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   202
        cp = UNICODE_BOGUS_CHAR_CODEPOINT;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   203
    else if ((cp >= 0xD800) && (cp <= 0xDBFF))  /* start surrogate pair! */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   204
    {
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   205
        const PHYSFS_uint32 pair = (PHYSFS_uint32) *src;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   206
        if (pair == 0)
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   207
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   208
        else if ((pair < 0xDC00) || (pair > 0xDFFF))
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   209
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   210
        else
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   211
        {
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   212
            src++;  /* eat the other surrogate. */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   213
            cp = (((cp - 0xD800) << 10) | (pair - 0xDC00));
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   214
        } /* else */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   215
    } /* else if */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   216
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   217
    *_str = src;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   218
    return cp;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   219
} /* utf16codepoint */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   220
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   221
static PHYSFS_uint32 utf32codepoint(const PHYSFS_uint32 **_str)
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   222
{
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   223
    const PHYSFS_uint32 *src = *_str;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   224
    PHYSFS_uint32 cp = *(src++);
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   225
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   226
    if (cp == 0)  /* null terminator, end of string. */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   227
        return 0;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   228
    else if (cp > 0x10FFF)
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   229
        cp = UNICODE_BOGUS_CHAR_CODEPOINT;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   230
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   231
    *_str = src;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   232
    return cp;
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   233
} /* utf32codepoint */
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   234
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   235
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   236
void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
    len -= sizeof (PHYSFS_uint32);   /* save room for null char. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    while (len >= sizeof (PHYSFS_uint32))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
        PHYSFS_uint32 cp = utf8codepoint(&src);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
        if (cp == 0)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
            break;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
        else if (cp == UNICODE_BOGUS_CHAR_VALUE)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
        *(dst++) = cp;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
        len -= sizeof (PHYSFS_uint32);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
    } /* while */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
    *dst = 0;
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   251
} /* PHYSFS_utf8ToUcs4 */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   253
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   254
void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
    len -= sizeof (PHYSFS_uint16);   /* save room for null char. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
    while (len >= sizeof (PHYSFS_uint16))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
        PHYSFS_uint32 cp = utf8codepoint(&src);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
        if (cp == 0)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
            break;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
        else if (cp == UNICODE_BOGUS_CHAR_VALUE)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
1094
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   265
        if (cp > 0xFFFF)  /* UTF-16 surrogates (bogus chars in UCS-2) */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
        *(dst++) = cp;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
        len -= sizeof (PHYSFS_uint16);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
    } /* while */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    *dst = 0;
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   273
} /* PHYSFS_utf8ToUcs2 */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
1094
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   275
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   276
void PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   277
{
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   278
    len -= sizeof (PHYSFS_uint16);   /* save room for null char. */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   279
    while (len >= sizeof (PHYSFS_uint16))
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   280
    {
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   281
        PHYSFS_uint32 cp = utf8codepoint(&src);
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   282
        if (cp == 0)
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   283
            break;
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   284
        else if (cp == UNICODE_BOGUS_CHAR_VALUE)
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   285
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   286
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   287
        if (cp > 0xFFFF)  /* encode as surrogate pair */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   288
        {
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   289
            if (len < (sizeof (PHYSFS_uint16) * 2))
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   290
                break;  /* not enough room for the pair, stop now. */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   291
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   292
            cp -= 0x10000;  /* Make this a 20-bit value */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   293
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   294
            *(dst++) = 0xD800 + ((cp >> 10) & 0x3FF);
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   295
            len -= sizeof (PHYSFS_uint16);
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   296
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   297
            cp = 0xDC00 + (cp & 0x3FF);
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   298
        } /* if */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   299
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   300
        *(dst++) = cp;
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   301
        len -= sizeof (PHYSFS_uint16);
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   302
    } /* while */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   303
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   304
    *dst = 0;
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   305
} /* PHYSFS_utf8ToUtf16 */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   306
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
static void utf8fromcodepoint(PHYSFS_uint32 cp, char **_dst, PHYSFS_uint64 *_len)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
    char *dst = *_dst;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
    PHYSFS_uint64 len = *_len;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
    if (len == 0)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
        return;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
    if (cp > 0x10FFFF)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
        cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
    else if ((cp == 0xFFFE) || (cp == 0xFFFF))  /* illegal values. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
        cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
    else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
        /* There are seven "UTF-16 surrogates" that are illegal in UTF-8. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
        switch (cp)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
            case 0xD800:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
            case 0xDB7F:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
            case 0xDB80:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
            case 0xDBFF:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
            case 0xDC00:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
            case 0xDF80:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
            case 0xDFFF:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
                cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
        } /* switch */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
    } /* else */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
    /* Do the encoding... */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
    if (cp < 0x80)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
        *(dst++) = (char) cp;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
        len--;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
    } /* if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
    else if (cp < 0x800)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
        if (len < 2)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
            len = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
        else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
            *(dst++) = (char) ((cp >> 6) | 128 | 64);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
            *(dst++) = (char) (cp & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
            len -= 2;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
        } /* else */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
    else if (cp < 0x10000)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
        if (len < 3)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
            len = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
        else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
            *(dst++) = (char) ((cp >> 12) | 128 | 64 | 32);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
            *(dst++) = (char) ((cp >> 6) & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
            *(dst++) = (char) (cp & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
            len -= 3;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
        } /* else */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
    else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
        if (len < 4)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
            len = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
        else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
            *(dst++) = (char) ((cp >> 18) | 128 | 64 | 32 | 16);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
            *(dst++) = (char) ((cp >> 12) & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
            *(dst++) = (char) ((cp >> 6) & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
            *(dst++) = (char) (cp & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
            len -= 4;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
        } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
    } /* else */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
    *_dst = dst;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
    *_len = len;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
} /* utf8fromcodepoint */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
#define UTF8FROMTYPE(typ, src, dst, len) \
1092
12c87d886a75 Zero-sized destination buffers when converting to UTF-8 shouldn't overflow.
Ryan C. Gordon <icculus@icculus.org>
parents: 1016
diff changeset
   386
    if (len == 0) return; \
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
    len--;  \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
    while (len) \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
    { \
998
974b90b56c43 Fixed latin1 to UTF-8 conversion (sign conversion was broken).
Ryan C. Gordon <icculus@icculus.org>
parents: 986
diff changeset
   390
        const PHYSFS_uint32 cp = (PHYSFS_uint32) ((typ) (*(src++))); \
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
        if (cp == 0) break; \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
        utf8fromcodepoint(cp, &dst, &len); \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
    } \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
    *dst = '\0'; \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   396
void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len)
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
    UTF8FROMTYPE(PHYSFS_uint32, src, dst, len);
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   399
} /* PHYSFS_utf8FromUcs4 */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   401
void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    UTF8FROMTYPE(PHYSFS_uint64, src, dst, len);
1093
738b2ee912b9 Fixed incorrect comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1092
diff changeset
   404
} /* PHYSFS_utf8FromUcs2 */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
/* latin1 maps to unicode codepoints directly, we just utf-8 encode it. */
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   407
void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len)
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
    UTF8FROMTYPE(PHYSFS_uint8, src, dst, len);
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   410
} /* PHYSFS_utf8FromLatin1 */
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
#undef UTF8FROMTYPE
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   414
1094
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   415
void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   416
{
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   417
    if (len == 0)
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   418
        return;
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   419
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   420
    len--;
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   421
    while (len)
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   422
    {
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   423
        const PHYSFS_uint32 cp = utf16codepoint(&src);
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   424
        if (!cp)
1094
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   425
            break;
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   426
        utf8fromcodepoint(cp, &dst, &len);
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   427
    } /* while */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   428
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   429
    *dst = '\0';
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   430
} /* PHYSFS_utf8FromUtf16 */
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   431
aa12a958cc47 Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1093
diff changeset
   432
1597
54086208785f Made PHYSFS_caseFold() a public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1595
diff changeset
   433
int PHYSFS_caseFold(const PHYSFS_uint32 from, PHYSFS_uint32 *to)
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   434
{
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   435
    int i;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   436
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   437
    if (from < 128)  /* low-ASCII, easy! */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   438
    {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   439
        if ((from >= 'A') && (from <= 'Z'))
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   440
            *to = from - ('A' - 'a');
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   441
        else
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   442
            *to = from;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   443
        return 1;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   444
    } /* if */
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   445
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   446
    else if (from <= 0xFFFF)
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   447
    {
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   448
        const PHYSFS_uint8 hash = ((from ^ (from >> 8)) & 0xFF);
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   449
        const PHYSFS_uint16 from16 = (PHYSFS_uint16) from;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   450
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   451
        {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   452
            const CaseFoldHashBucket1_16 *bucket = &case_fold_hash1_16[hash];
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   453
            const int count = (int) bucket->count;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   454
            for (i = 0; i < count; i++)
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   455
            {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   456
                const CaseFoldMapping1_16 *mapping = &bucket->list[i];
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   457
                if (mapping->from == from16)
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   458
                {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   459
                    *to = mapping->to0;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   460
                    return 1;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   461
                } /* if */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   462
            } /* for */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   463
        }
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   464
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   465
        {
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   466
            const CaseFoldHashBucket2_16 *bucket = &case_fold_hash2_16[hash & 15];
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   467
            const int count = (int) bucket->count;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   468
            for (i = 0; i < count; i++)
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   469
            {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   470
                const CaseFoldMapping2_16 *mapping = &bucket->list[i];
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   471
                if (mapping->from == from16)
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   472
                {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   473
                    to[0] = mapping->to0;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   474
                    to[1] = mapping->to1;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   475
                    return 2;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   476
                } /* if */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   477
            } /* for */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   478
        }
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   479
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   480
        {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   481
            const CaseFoldHashBucket3_16 *bucket = &case_fold_hash3_16[hash & 3];
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   482
            const int count = (int) bucket->count;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   483
            for (i = 0; i < count; i++)
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   484
            {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   485
                const CaseFoldMapping3_16 *mapping = &bucket->list[i];
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   486
                if (mapping->from == from16)
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   487
                {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   488
                    to[0] = mapping->to0;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   489
                    to[1] = mapping->to1;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   490
                    to[2] = mapping->to2;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   491
                    return 3;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   492
                } /* if */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   493
            } /* for */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   494
        }
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   495
    } /* else if */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   496
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   497
    else  /* codepoint that doesn't fit in 16 bits. */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   498
    {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   499
        const PHYSFS_uint8 hash = ((from ^ (from >> 8)) & 0xFF);
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   500
        const CaseFoldHashBucket1_32 *bucket = &case_fold_hash1_32[hash & 15];
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   501
        const int count = (int) bucket->count;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   502
        for (i = 0; i < count; i++)
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   503
        {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   504
            const CaseFoldMapping1_32 *mapping = &bucket->list[i];
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   505
            if (mapping->from == from)
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   506
            {
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   507
                *to = mapping->to0;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   508
                return 1;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   509
            } /* if */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   510
        } /* for */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   511
    } /* else */
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   512
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   513
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   514
    /* Not found...there's no remapping for this codepoint. */
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   515
    *to = from;
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   516
    return 1;
1597
54086208785f Made PHYSFS_caseFold() a public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1595
diff changeset
   517
} /* PHYSFS_caseFold */
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   518
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   519
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   520
#define UTFSTRICMP(bits) \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   521
    PHYSFS_uint32 folded1[3], folded2[3]; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   522
    int head1 = 0, tail1 = 0, head2 = 0, tail2 = 0; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   523
    while (1) { \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   524
        PHYSFS_uint32 cp1, cp2; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   525
        if (head1 != tail1) { \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   526
            cp1 = folded1[tail1++]; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   527
        } else { \
1597
54086208785f Made PHYSFS_caseFold() a public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1595
diff changeset
   528
            head1 = PHYSFS_caseFold(utf##bits##codepoint(&str1), folded1); \
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   529
            cp1 = folded1[0]; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   530
            tail1 = 1; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   531
        } \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   532
        if (head2 != tail2) { \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   533
            cp2 = folded2[tail2++]; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   534
        } else { \
1597
54086208785f Made PHYSFS_caseFold() a public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1595
diff changeset
   535
            head2 = PHYSFS_caseFold(utf##bits##codepoint(&str2), folded2); \
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   536
            cp2 = folded2[0]; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   537
            tail2 = 1; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   538
        } \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   539
        if (cp1 < cp2) { \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   540
            return -1; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   541
        } else if (cp1 > cp2) { \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   542
            return 1; \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   543
        } else if (cp1 == 0) { \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   544
            break;  /* complete match. */ \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   545
        } \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   546
    } \
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   547
    return 0
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   548
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   549
int PHYSFS_utf8stricmp(const char *str1, const char *str2)
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   550
{
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   551
    UTFSTRICMP(8);
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   552
} /* PHYSFS_utf8stricmp */
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   553
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   554
int PHYSFS_utf16stricmp(const PHYSFS_uint16 *str1, const PHYSFS_uint16 *str2)
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   555
{
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   556
    UTFSTRICMP(16);
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   557
} /* PHYSFS_utf16stricmp */
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   558
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   559
int PHYSFS_ucs4stricmp(const PHYSFS_uint32 *str1, const PHYSFS_uint32 *str2)
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   560
{
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   561
    UTFSTRICMP(32);
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   562
} /* PHYSFS_ucs4stricmp */
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   563
1595
faabd13245ca unicode: Added UTF-16 and UCS-4 stricmp functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   564
#undef UTFSTRICMP
828
ee871d51510d Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   565
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
/* end of physfs_unicode.c ... */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567