physfs_unicode.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 11 Mar 2007 08:56:23 +0000
changeset 804 45c29325e017
parent 787 81da113b878f
child 808 7656f86a9a2c
permissions -rw-r--r--
Added install targets for "make install"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
787
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
#if HAVE_CONFIG_H
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
#  include <config.h>
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
#endif
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
#include "physfs.h"
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
#define __PHYSICSFS_INTERNAL__
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
#include "physfs_internal.h"
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
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
/*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
 * From rfc3629, the UTF-8 spec:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
 *  http://www.ietf.org/rfc/rfc3629.txt
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 *
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
 *   Char. number range  |        UTF-8 octet sequence
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
 *      (hexadecimal)    |              (binary)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
 *   --------------------+---------------------------------------------
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
 *   0000 0000-0000 007F | 0xxxxxxx
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
 *   0000 0080-0000 07FF | 110xxxxx 10xxxxxx
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
 *   0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
 *   0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
/*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
 * 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
    27
 *  in Unicode (0x10FFFF is the largest codepoint value). We return this
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
 *  value from utf8codepoint() if there's bogus bits in the
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
 *  stream. utf8codepoint() will turn this value into something
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
 *  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
    31
 *  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
    32
 *  bits.
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
#define UNICODE_BOGUS_CHAR_VALUE 0xFFFFFFFF
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
/*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
 * 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
    38
 *  UTF-8 string. May not fly in Asian locales?
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
#define UNICODE_BOGUS_CHAR_CODEPOINT '?'
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
static PHYSFS_uint32 utf8codepoint(const char **_str)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    const char *str = *_str;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
    PHYSFS_uint32 retval = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    PHYSFS_uint32 octet = (PHYSFS_uint32) ((PHYSFS_uint8) *str);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    PHYSFS_uint32 octet2, octet3, octet4;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    if (octet == 0)  /* null terminator, end of string. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
        return 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
    else if (octet < 128)  /* one octet char: 0 to 127 */
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
        (*_str)++;  /* skip to next possible start of codepoint. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
        return(octet);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    else if ((octet > 127) && (octet < 192))  /* bad (starts with 10xxxxxx). */
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
        /*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
         * Apparently each of these is supposed to be flagged as a bogus
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
         *  char, instead of just resyncing to the next valid codepoint.
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
        (*_str)++;  /* skip to next possible start of codepoint. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    else if (octet < 224)  /* two octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
        octet -= (128+64);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
        octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
        if ((octet2 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
        *_str += 2;  /* skip to next possible start of codepoint. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
        retval = ((octet << 6) | (octet2 - 128));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
        if ((retval >= 0x80) && (retval <= 0x7FF))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
            return retval;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    else if (octet < 240)  /* three octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
        octet -= (128+64+32);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
        octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
        if ((octet2 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
        octet3 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
        if ((octet3 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
        *_str += 3;  /* skip to next possible start of codepoint. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
        retval = ( ((octet << 12)) | ((octet2-128) << 6) | ((octet3-128)) );
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
        /* There are seven "UTF-16 surrogates" that are illegal in UTF-8. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
        switch (retval)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
            case 0xD800:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
            case 0xDB7F:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
            case 0xDB80:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
            case 0xDBFF:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
            case 0xDC00:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
            case 0xDF80:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
            case 0xDFFF:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
                return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        } /* switch */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
        /* 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
   109
        if ((retval >= 0x800) && (retval <= 0xFFFD))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
            return retval;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
    else if (octet < 248)  /* four octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
        octet -= (128+64+32+16);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
        octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
        if ((octet2 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
        octet3 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
        if ((octet3 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
        octet4 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
        if ((octet4 & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
        *_str += 4;  /* skip to next possible start of codepoint. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
        retval = ( ((octet << 18)) | ((octet2 - 128) << 12) |
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
                   ((octet3 - 128) << 6) | ((octet4 - 128)) );
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
        if ((retval >= 0x10000) && (retval <= 0x10FFFF))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
            return retval;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    } /* else if */
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
    /*
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
     * Five and six octet sequences became illegal in rfc3629.
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
     *  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
   138
     *  ahead the right number of bytes and don't overflow the buffer.
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
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    else if (octet < 252)  /* five octets */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    {
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
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
        *_str += 5;  /* skip to next possible start of codepoint. */
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
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
        octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str));
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
        if ((octet & (128+64)) != 128)  /* Format isn't 10xxxxxx? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
            return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
        *_str += 6;  /* skip to next possible start of codepoint. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
        return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
    return UNICODE_BOGUS_CHAR_VALUE;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
} /* utf8codepoint */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
void PHYSFS_utf8toucs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
    len -= sizeof (PHYSFS_uint32);   /* save room for null char. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    while (len >= sizeof (PHYSFS_uint32))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
        PHYSFS_uint32 cp = utf8codepoint(&src);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
        if (cp == 0)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
            break;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
        else if (cp == UNICODE_BOGUS_CHAR_VALUE)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
        *(dst++) = cp;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
        len -= sizeof (PHYSFS_uint32);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    } /* while */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
    *dst = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
} /* PHYSFS_utf8toucs4 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
void PHYSFS_utf8toucs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    len -= sizeof (PHYSFS_uint16);   /* save room for null char. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
    while (len >= sizeof (PHYSFS_uint16))
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
        PHYSFS_uint32 cp = utf8codepoint(&src);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
        if (cp == 0)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
            break;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
        else if (cp == UNICODE_BOGUS_CHAR_VALUE)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
        /* !!! BLUESKY: UTF-16 surrogates? */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
        if (cp > 0xFFFF)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
            cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
        *(dst++) = cp;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
        len -= sizeof (PHYSFS_uint16);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
    } /* while */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    *dst = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
} /* PHYSFS_utf8toucs2 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
static void utf8fromcodepoint(PHYSFS_uint32 cp, char **_dst, PHYSFS_uint64 *_len)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    char *dst = *_dst;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
    PHYSFS_uint64 len = *_len;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    if (len == 0)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
        return;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    if (cp > 0x10FFFF)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
        cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    else if ((cp == 0xFFFE) || (cp == 0xFFFF))  /* illegal values. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
        cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
        /* There are seven "UTF-16 surrogates" that are illegal in UTF-8. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
        switch (cp)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
            case 0xD800:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
            case 0xDB7F:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
            case 0xDB80:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
            case 0xDBFF:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
            case 0xDC00:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
            case 0xDF80:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
            case 0xDFFF:
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
                cp = UNICODE_BOGUS_CHAR_CODEPOINT;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
        } /* switch */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
    } /* else */
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
    /* Do the encoding... */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
    if (cp < 0x80)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
        *(dst++) = (char) cp;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
        len--;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    } /* if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    else if (cp < 0x800)
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
        if (len < 2)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
            len = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
        else
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++) = (char) ((cp >> 6) | 128 | 64);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
            *(dst++) = (char) (cp & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
            len -= 2;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
        } /* else */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
    else if (cp < 0x10000)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
        if (len < 3)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
            len = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
        else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
            *(dst++) = (char) ((cp >> 12) | 128 | 64 | 32);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
            *(dst++) = (char) ((cp >> 6) & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
            *(dst++) = (char) (cp & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
            len -= 3;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
        } /* else */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
    } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
    else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
    {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
        if (len < 4)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
            len = 0;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
        else
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
        {
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
            *(dst++) = (char) ((cp >> 18) | 128 | 64 | 32 | 16);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
            *(dst++) = (char) ((cp >> 12) & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
            *(dst++) = (char) ((cp >> 6) & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
            *(dst++) = (char) (cp & 0x3F) | 128;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
            len -= 4;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
        } /* else if */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    } /* else */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    *_dst = dst;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    *_len = len;
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
} /* utf8fromcodepoint */
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
#define UTF8FROMTYPE(typ, src, dst, len) \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
    len--;  \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
    while (len) \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
    { \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
        const PHYSFS_uint32 cp = (PHYSFS_uint32) *(src++); \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
        if (cp == 0) break; \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
        utf8fromcodepoint(cp, &dst, &len); \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
    } \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
    *dst = '\0'; \
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
void PHYSFS_utf8fromucs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len)
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
    UTF8FROMTYPE(PHYSFS_uint32, src, dst, len);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
} /* PHYSFS_utf8fromucs4 */
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
void PHYSFS_utf8fromucs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
    UTF8FROMTYPE(PHYSFS_uint64, src, dst, len);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
} /* PHYSFS_utf8fromucs4 */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
/* latin1 maps to unicode codepoints directly, we just utf-8 encode it. */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
void PHYSFS_utf8fromlatin1(const char *src, char *dst, PHYSFS_uint64 len)
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
{
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
    UTF8FROMTYPE(PHYSFS_uint8, src, dst, len);
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
} /* PHYSFS_utf8fromlatin1 */
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
#undef UTF8FROMTYPE
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
/* end of physfs_unicode.c ... */
81da113b878f Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338