]>
Dogcows Code - chaz/yoink/blob - src/Moof/ConvertUTF.h
6 * Copyright 2001-2004 Unicode, Inc.
10 * This source code is provided as is by Unicode, Inc. No claims are
11 * made as to fitness for any particular purpose. No warranties of any
12 * kind are expressed or implied. The recipient agrees to determine
13 * applicability of information provided. If this file has been
14 * purchased on magnetic or optical media from Unicode, Inc., the
15 * sole remedy for any claim will be exchange of defective media
16 * within 90 days of receipt.
18 * Limitations on Rights to Redistribute This Code
20 * Unicode, Inc. hereby grants the right to freely use the information
21 * supplied in this file in the creation of products supporting the
22 * Unicode Standard, and to make copies of this file in any form
23 * for internal or external distribution as long as this notice
27 /* ---------------------------------------------------------------------
29 Conversions between UTF32, UTF-16, and UTF-8. Header file.
31 Several funtions are included here, forming a complete set of
32 conversions between the three formats. UTF-7 is not included
33 here, but is handled in a separate source file.
35 Each of these routines takes pointers to input buffers and output
36 buffers. The input buffers are const.
38 Each routine converts the text between *sourceStart and sourceEnd,
39 putting the result into the buffer between *targetStart and
40 targetEnd. Note: the end pointers are *after* the last item: e.g.
41 *(sourceEnd - 1) is the last item.
43 The return result indicates whether the conversion was successful,
44 and if not, whether the problem was in the source or target buffers.
45 (Only the first encountered problem is indicated.)
47 After the conversion, *sourceStart and *targetStart are both
48 updated to point to the end of last text successfully converted in
49 the respective buffers.
52 sourceStart - pointer to a pointer to the source buffer.
53 The contents of this are modified on return so that
54 it points at the next thing to be converted.
55 targetStart - similarly, pointer to pointer to the target buffer.
56 sourceEnd, targetEnd - respectively pointers to the ends of the
57 two buffers, for overflow checking only.
59 These conversion functions take a ConversionFlags argument. When this
60 flag is set to strict, both irregular sequences and isolated surrogates
61 will cause an error. When the flag is set to lenient, both irregular
62 sequences and isolated surrogates are converted.
64 Whether the flag is strict or lenient, all illegal sequences will cause
65 an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,
66 or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
67 must check for illegal sequences.
69 When the flag is set to lenient, characters over 0x10FFFF are converted
70 to the replacement character; otherwise (when the flag is set to strict)
71 they constitute an error.
74 The value "sourceIllegal" is returned from some routines if the input
75 sequence is malformed. When "sourceIllegal" is returned, the source
76 value will point to the illegal value that caused the problem. E.g.,
77 in UTF-8 when a sequence is malformed, it points to the start of the
80 Author: Mark E. Davis, 1994.
81 Rev History: Rick McGowan, fixes & updates May 2001.
82 Fixes & updates, Sept 2001.
84 ------------------------------------------------------------------------ */
86 /* ---------------------------------------------------------------------
87 The following 4 definitions are compiler-specific.
88 The C standard does not guarantee that wchar_t has at least
89 16 bits, so wchar_t is no less portable than unsigned short!
90 All should be unsigned values to avoid sign extension during
91 bit mask & shift operations.
92 ------------------------------------------------------------------------ */
97 typedef uint32_t UTF32
; /* exactly 32 bits */
98 typedef uint16_t UTF16
; /* exactly 16 bits */
99 typedef uint8_t UTF8
; /* exactly 8 bits */
101 /* Some fundamental constants */
102 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
103 #define UNI_MAX_BMP (UTF32)0x0000FFFF
104 #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
105 #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
106 #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
109 conversionOK
, /* conversion successful */
110 sourceExhausted
, /* partial character in source, but hit end */
111 targetExhausted
, /* insuff. room in target for conversion */
112 sourceIllegal
/* source sequence is illegal/malformed */
116 strictConversion
= 0,
120 /* This is for C++ and does no harm in C */
125 ConversionResult
ConvertUTF8toUTF16 (
126 const UTF8
** sourceStart
, const UTF8
* sourceEnd
,
127 UTF16
** targetStart
, UTF16
* targetEnd
, ConversionFlags flags
);
129 ConversionResult
ConvertUTF16toUTF8 (
130 const UTF16
** sourceStart
, const UTF16
* sourceEnd
,
131 UTF8
** targetStart
, UTF8
* targetEnd
, ConversionFlags flags
);
133 ConversionResult
ConvertUTF8toUTF32 (
134 const UTF8
** sourceStart
, const UTF8
* sourceEnd
,
135 UTF32
** targetStart
, UTF32
* targetEnd
, ConversionFlags flags
);
137 ConversionResult
ConvertUTF32toUTF8 (
138 const UTF32
** sourceStart
, const UTF32
* sourceEnd
,
139 UTF8
** targetStart
, UTF8
* targetEnd
, ConversionFlags flags
);
141 ConversionResult
ConvertUTF16toUTF32 (
142 const UTF16
** sourceStart
, const UTF16
* sourceEnd
,
143 UTF32
** targetStart
, UTF32
* targetEnd
, ConversionFlags flags
);
145 ConversionResult
ConvertUTF32toUTF16 (
146 const UTF32
** sourceStart
, const UTF32
* sourceEnd
,
147 UTF16
** targetStart
, UTF16
* targetEnd
, ConversionFlags flags
);
149 bool isLegalUTF8Sequence(const UTF8
*source
, const UTF8
*sourceEnd
);
155 /* --------------------------------------------------------------------- */
157 #endif // _CONVERTUTF_H_
This page took 0.044572 seconds and 4 git commands to generate.