vrshoot

view libs/assimp/ConvertUTF/ConvertUTF.h @ 0:b2f14e535253

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