Ignore:
Timestamp:
Jan 10, 2009, 5:59:49 PM (13 years ago)
Author:
charles
Message:

(trunk libT) upgrade our copy of Unicode Inc's freeware ConvertUTF.[ch]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/ConvertUTF.h

    r7197 r7654  
    88/*
    99 * Copyright 2001-2004 Unicode, Inc.
    10  *
     10 * 
    1111 * Disclaimer
    12  *
     12 * 
    1313 * This source code is provided as is by Unicode, Inc. No claims are
    1414 * made as to fitness for any particular purpose. No warranties of any
     
    1818 * sole remedy for any claim will be exchange of defective media
    1919 * within 90 days of receipt.
    20  *
     20 * 
    2121 * Limitations on Rights to Redistribute This Code
    22  *
     22 * 
    2323 * Unicode, Inc. hereby grants the right to freely use the information
    2424 * supplied in this file in the creation of products supporting the
     
    4141    Each routine converts the text between *sourceStart and sourceEnd,
    4242    putting the result into the buffer between *targetStart and
    43     targetEnd. Note: the end pointers are *after* the last item: e.g.
    44  *(sourceEnd - 1) is the last item.
     43    targetEnd. Note: the end pointers are *after* the last item: e.g. 
     44    *(sourceEnd - 1) is the last item.
    4545
    4646    The return result indicates whether the conversion was successful,
     
    5353
    5454    Input parameters:
    55     sourceStart - pointer to a pointer to the source buffer.
    56         The contents of this are modified on return so that
    57         it points at the next thing to be converted.
    58     targetStart - similarly, pointer to pointer to the target buffer.
    59     sourceEnd, targetEnd - respectively pointers to the ends of the
    60         two buffers, for overflow checking only.
     55        sourceStart - pointer to a pointer to the source buffer.
     56                The contents of this are modified on return so that
     57                it points at the next thing to be converted.
     58        targetStart - similarly, pointer to pointer to the target buffer.
     59        sourceEnd, targetEnd - respectively pointers to the ends of the
     60                two buffers, for overflow checking only.
    6161
    6262    These conversion functions take a ConversionFlags argument. When this
     
    7575
    7676    Output parameters:
    77     The value "sourceIllegal" is returned from some routines if the input
    78     sequence is malformed.  When "sourceIllegal" is returned, the source
    79     value will point to the illegal value that caused the problem. E.g.,
    80     in UTF-8 when a sequence is malformed, it points to the start of the
    81     malformed sequence.
     77        The value "sourceIllegal" is returned from some routines if the input
     78        sequence is malformed.  When "sourceIllegal" is returned, the source
     79        value will point to the illegal value that caused the problem. E.g.,
     80        in UTF-8 when a sequence is malformed, it points to the start of the
     81        malformed sequence. 
    8282
    8383    Author: Mark E. Davis, 1994.
    8484    Rev History: Rick McGowan, fixes & updates May 2001.
    85         Fixes & updates, Sept 2001.
     85                Fixes & updates, Sept 2001.
    8686
    87    ------------------------------------------------------------------------ */
     87------------------------------------------------------------------------ */
    8888
    8989/* ---------------------------------------------------------------------
     
    9393    All should be unsigned values to avoid sign extension during
    9494    bit mask & shift operations.
    95    ------------------------------------------------------------------------ */
     95------------------------------------------------------------------------ */
    9696
    97 
    98 typedef unsigned int    UTF32;  /* at least 32 bits */
    99 typedef unsigned short  UTF16;  /* at least 16 bits */
    100 typedef unsigned char   UTF8;   /* typically 8 bits */
    101 typedef unsigned char   Boolean; /* 0 or 1 */
     97typedef unsigned long   UTF32;  /* at least 32 bits */
     98typedef unsigned short  UTF16;  /* at least 16 bits */
     99typedef unsigned char   UTF8;   /* typically 8 bits */
     100typedef unsigned char   Boolean; /* 0 or 1 */
    102101
    103102/* Some fundamental constants */
     
    108107#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
    109108
    110 typedef enum
    111 {
    112     conversionOK,       /* conversion successful */
    113     sourceExhausted,    /* partial character in source, but hit end */
    114     targetExhausted,    /* insuff. room in target for conversion */
    115     sourceIllegal       /* source sequence is illegal/malformed */
     109typedef enum {
     110        conversionOK,           /* conversion successful */
     111        sourceExhausted,        /* partial character in source, but hit end */
     112        targetExhausted,        /* insuff. room in target for conversion */
     113        sourceIllegal           /* source sequence is illegal/malformed */
    116114} ConversionResult;
    117115
    118 typedef enum
    119 {
    120     strictConversion = 0,
    121     lenientConversion
     116typedef enum {
     117        strictConversion = 0,
     118        lenientConversion
    122119} ConversionFlags;
    123120
     
    127124#endif
    128125
    129 ConversionResult ConvertUTF8toUTF16( const UTF8**    sourceStart,
    130                                      const UTF8*     sourceEnd,
    131                                      UTF16**         targetStart,
    132                                      UTF16*          targetEnd,
    133                                      ConversionFlags flags );
     126ConversionResult ConvertUTF8toUTF16 (
     127                const UTF8** sourceStart, const UTF8* sourceEnd,
     128                UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
    134129
    135 ConversionResult ConvertUTF16toUTF8( const UTF16**   sourceStart,
    136                                      const UTF16*    sourceEnd,
    137                                      UTF8**          targetStart,
    138                                      UTF8*           targetEnd,
    139                                      ConversionFlags flags );
     130ConversionResult ConvertUTF16toUTF8 (
     131                const UTF16** sourceStart, const UTF16* sourceEnd,
     132                UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
     133               
     134ConversionResult ConvertUTF8toUTF32 (
     135                const UTF8** sourceStart, const UTF8* sourceEnd,
     136                UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
    140137
    141 ConversionResult ConvertUTF8toUTF32( const UTF8**    sourceStart,
    142                                      const UTF8*     sourceEnd,
    143                                      UTF32**         targetStart,
    144                                      UTF32*          targetEnd,
    145                                      ConversionFlags flags );
     138ConversionResult ConvertUTF32toUTF8 (
     139                const UTF32** sourceStart, const UTF32* sourceEnd,
     140                UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
     141               
     142ConversionResult ConvertUTF16toUTF32 (
     143                const UTF16** sourceStart, const UTF16* sourceEnd,
     144                UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
    146145
    147 ConversionResult ConvertUTF32toUTF8( const UTF32**   sourceStart,
    148                                      const UTF32*    sourceEnd,
    149                                      UTF8**          targetStart,
    150                                      UTF8*           targetEnd,
    151                                      ConversionFlags flags );
     146ConversionResult ConvertUTF32toUTF16 (
     147                const UTF32** sourceStart, const UTF32* sourceEnd,
     148                UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
    152149
    153 ConversionResult ConvertUTF16toUTF32( const UTF16**   sourceStart,
    154                                       const UTF16*    sourceEnd,
    155                                       UTF32**         targetStart,
    156                                       UTF32*          targetEnd,
    157                                       ConversionFlags flags );
    158 
    159 ConversionResult ConvertUTF32toUTF16( const UTF32**   sourceStart,
    160                                       const UTF32*    sourceEnd,
    161                                       UTF16**         targetStart,
    162                                       UTF16*          targetEnd,
    163                                       ConversionFlags flags );
    164 
    165 Boolean          isLegalUTF8Sequence( const UTF8 *source,
    166                                       const UTF8 *sourceEnd );
     150Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
    167151
    168152#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.