annotate src/Support/ConvertUTF.h @ 475:52f659be9008

New design params, including narrower AGC, Greenwood map for more channels, default 71, some renaming, open loop feature, ...
author dicklyon@google.com
date Thu, 22 Mar 2012 22:37:56 +0000
parents 582cbe817f2c
children
rev   line source
tomwalters@0 1 /*
tomwalters@0 2 * Copyright 2001-2004 Unicode, Inc.
tomwalters@0 3 *
tomwalters@0 4 * Disclaimer
tomwalters@0 5 *
tomwalters@0 6 * This source code is provided as is by Unicode, Inc. No claims are
tomwalters@0 7 * made as to fitness for any particular purpose. No warranties of any
tomwalters@0 8 * kind are expressed or implied. The recipient agrees to determine
tomwalters@0 9 * applicability of information provided. If this file has been
tomwalters@0 10 * purchased on magnetic or optical media from Unicode, Inc., the
tomwalters@0 11 * sole remedy for any claim will be exchange of defective media
tomwalters@0 12 * within 90 days of receipt.
tomwalters@0 13 *
tomwalters@0 14 * Limitations on Rights to Redistribute This Code
tomwalters@0 15 *
tomwalters@0 16 * Unicode, Inc. hereby grants the right to freely use the information
tomwalters@0 17 * supplied in this file in the creation of products supporting the
tomwalters@0 18 * Unicode Standard, and to make copies of this file in any form
tomwalters@0 19 * for internal or external distribution as long as this notice
tomwalters@0 20 * remains attached.
tomwalters@0 21 */
tomwalters@0 22
tomwalters@0 23 /* ---------------------------------------------------------------------
tomwalters@0 24
tomwalters@0 25 Conversions between UTF32, UTF-16, and UTF-8. Header file.
tomwalters@0 26
tomwalters@0 27 Several funtions are included here, forming a complete set of
tomwalters@0 28 conversions between the three formats. UTF-7 is not included
tomwalters@0 29 here, but is handled in a separate source file.
tomwalters@0 30
tomwalters@0 31 Each of these routines takes pointers to input buffers and output
tomwalters@0 32 buffers. The input buffers are const.
tomwalters@0 33
tomwalters@0 34 Each routine converts the text between *sourceStart and sourceEnd,
tomwalters@0 35 putting the result into the buffer between *targetStart and
tomwalters@0 36 targetEnd. Note: the end pointers are *after* the last item: e.g.
tomwalters@0 37 *(sourceEnd - 1) is the last item.
tomwalters@0 38
tomwalters@0 39 The return result indicates whether the conversion was successful,
tomwalters@0 40 and if not, whether the problem was in the source or target buffers.
tomwalters@0 41 (Only the first encountered problem is indicated.)
tomwalters@0 42
tomwalters@0 43 After the conversion, *sourceStart and *targetStart are both
tomwalters@0 44 updated to point to the end of last text successfully converted in
tomwalters@0 45 the respective buffers.
tomwalters@0 46
tomwalters@0 47 Input parameters:
tomwalters@0 48 sourceStart - pointer to a pointer to the source buffer.
tomwalters@0 49 The contents of this are modified on return so that
tomwalters@0 50 it points at the next thing to be converted.
tomwalters@0 51 targetStart - similarly, pointer to pointer to the target buffer.
tomwalters@0 52 sourceEnd, targetEnd - respectively pointers to the ends of the
tomwalters@0 53 two buffers, for overflow checking only.
tomwalters@0 54
tomwalters@0 55 These conversion functions take a ConversionFlags argument. When this
tomwalters@0 56 flag is set to strict, both irregular sequences and isolated surrogates
tomwalters@0 57 will cause an error. When the flag is set to lenient, both irregular
tomwalters@0 58 sequences and isolated surrogates are converted.
tomwalters@0 59
tomwalters@0 60 Whether the flag is strict or lenient, all illegal sequences will cause
tomwalters@0 61 an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,
tomwalters@0 62 or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
tomwalters@0 63 must check for illegal sequences.
tomwalters@0 64
tomwalters@0 65 When the flag is set to lenient, characters over 0x10FFFF are converted
tomwalters@0 66 to the replacement character; otherwise (when the flag is set to strict)
tomwalters@0 67 they constitute an error.
tomwalters@0 68
tomwalters@0 69 Output parameters:
tomwalters@0 70 The value "sourceIllegal" is returned from some routines if the input
tomwalters@0 71 sequence is malformed. When "sourceIllegal" is returned, the source
tomwalters@0 72 value will point to the illegal value that caused the problem. E.g.,
tomwalters@0 73 in UTF-8 when a sequence is malformed, it points to the start of the
tomwalters@0 74 malformed sequence.
tomwalters@0 75
tomwalters@0 76 Author: Mark E. Davis, 1994.
tomwalters@0 77 Rev History: Rick McGowan, fixes & updates May 2001.
tomwalters@0 78 Fixes & updates, Sept 2001.
tomwalters@0 79
tomwalters@0 80 ------------------------------------------------------------------------ */
tomwalters@0 81
tomwalters@0 82 /* ---------------------------------------------------------------------
tomwalters@0 83 The following 4 definitions are compiler-specific.
tomwalters@0 84 The C standard does not guarantee that wchar_t has at least
tomwalters@0 85 16 bits, so wchar_t is no less portable than unsigned short!
tomwalters@0 86 All should be unsigned values to avoid sign extension during
tomwalters@0 87 bit mask & shift operations.
tomwalters@0 88 ------------------------------------------------------------------------ */
tomwalters@0 89
tomwalters@0 90 typedef unsigned int UTF32; /* at least 32 bits */
tomwalters@0 91 typedef unsigned short UTF16; /* at least 16 bits */
tomwalters@0 92 typedef unsigned char UTF8; /* typically 8 bits */
tomwalters@0 93 typedef unsigned char Boolean; /* 0 or 1 */
tomwalters@0 94
tomwalters@0 95 /* Some fundamental constants */
tomwalters@0 96 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
tomwalters@0 97 #define UNI_MAX_BMP (UTF32)0x0000FFFF
tomwalters@0 98 #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
tomwalters@0 99 #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
tomwalters@0 100 #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
tomwalters@0 101
tomwalters@0 102 typedef enum {
tomwalters@0 103 conversionOK, /* conversion successful */
tomwalters@0 104 sourceExhausted, /* partial character in source, but hit end */
tomwalters@0 105 targetExhausted, /* insuff. room in target for conversion */
tomwalters@0 106 sourceIllegal /* source sequence is illegal/malformed */
tomwalters@0 107 } ConversionResult;
tomwalters@0 108
tomwalters@0 109 typedef enum {
tomwalters@0 110 strictConversion = 0,
tomwalters@0 111 lenientConversion
tomwalters@0 112 } ConversionFlags;
tomwalters@0 113
tomwalters@0 114 /* This is for C++ and does no harm in C */
tomwalters@0 115 #ifdef __cplusplus
tomwalters@0 116 extern "C" {
tomwalters@0 117 #endif
tomwalters@0 118
tomwalters@0 119 ConversionResult ConvertUTF8toUTF16 (
tomwalters@0 120 const UTF8** sourceStart, const UTF8* sourceEnd,
tomwalters@0 121 UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
tomwalters@0 122
tomwalters@0 123 ConversionResult ConvertUTF16toUTF8 (
tomwalters@0 124 const UTF16** sourceStart, const UTF16* sourceEnd,
tomwalters@0 125 UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
tomwalters@0 126
tomwalters@0 127 ConversionResult ConvertUTF8toUTF32 (
tomwalters@0 128 const UTF8** sourceStart, const UTF8* sourceEnd,
tomwalters@0 129 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
tomwalters@0 130
tomwalters@0 131 ConversionResult ConvertUTF32toUTF8 (
tomwalters@0 132 const UTF32** sourceStart, const UTF32* sourceEnd,
tomwalters@0 133 UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
tomwalters@0 134
tomwalters@0 135 ConversionResult ConvertUTF16toUTF32 (
tomwalters@0 136 const UTF16** sourceStart, const UTF16* sourceEnd,
tomwalters@0 137 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
tomwalters@0 138
tomwalters@0 139 ConversionResult ConvertUTF32toUTF16 (
tomwalters@0 140 const UTF32** sourceStart, const UTF32* sourceEnd,
tomwalters@0 141 UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
tomwalters@0 142
tomwalters@0 143 Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
tomwalters@0 144
tomwalters@0 145 #ifdef __cplusplus
tomwalters@0 146 }
tomwalters@0 147 #endif
tomwalters@0 148
tomwalters@0 149 /* --------------------------------------------------------------------- */