90 #ifndef LLVM_SUPPORT_CONVERTUTF_H
91 #define LLVM_SUPPORT_CONVERTUTF_H
93 #include "wpi/ArrayRef.h"
94 #include "wpi/StringRef.h"
112 typedef unsigned int UTF32;
113 typedef unsigned short UTF16;
114 typedef unsigned char UTF8;
115 typedef bool Boolean;
118 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
119 #define UNI_MAX_BMP (UTF32)0x0000FFFF
120 #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
121 #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
122 #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
124 #define UNI_MAX_UTF8_BYTES_PER_CODE_POINT 4
126 #define UNI_UTF16_BYTE_ORDER_MARK_NATIVE 0xFEFF
127 #define UNI_UTF16_BYTE_ORDER_MARK_SWAPPED 0xFFFE
137 strictConversion = 0,
141 ConversionResult ConvertUTF8toUTF16 (
142 const UTF8** sourceStart,
const UTF8* sourceEnd,
143 UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
150 const UTF8** sourceStart,
const UTF8* sourceEnd,
151 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
158 const UTF8** sourceStart,
const UTF8* sourceEnd,
159 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
161 ConversionResult ConvertUTF16toUTF8 (
162 const UTF16** sourceStart,
const UTF16* sourceEnd,
163 UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
165 ConversionResult ConvertUTF32toUTF8 (
166 const UTF32** sourceStart,
const UTF32* sourceEnd,
167 UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
169 ConversionResult ConvertUTF16toUTF32 (
170 const UTF16** sourceStart,
const UTF16* sourceEnd,
171 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
173 ConversionResult ConvertUTF32toUTF16 (
174 const UTF32** sourceStart,
const UTF32* sourceEnd,
175 UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
177 Boolean isLegalUTF8Sequence(
const UTF8 *source,
const UTF8 *sourceEnd);
179 Boolean isLegalUTF8String(
const UTF8 **source,
const UTF8 *sourceEnd);
181 unsigned getNumBytesForUTF8(UTF8 firstByte);
214 static inline ConversionResult convertUTF8Sequence(
const UTF8 **source,
215 const UTF8 *sourceEnd,
217 ConversionFlags flags) {
218 if (*source == sourceEnd)
219 return sourceExhausted;
220 unsigned size = getNumBytesForUTF8(**source);
221 if ((ptrdiff_t)size > sourceEnd - *source)
222 return sourceExhausted;
238 SmallVectorImpl<char> &DstUTF8);
246 SmallVectorImpl<UTF16> &DstUTF16);
ConversionResult ConvertUTF8toUTF32Partial(const UTF8 **sourceStart, const UTF8 *sourceEnd, UTF32 **targetStart, UTF32 *targetEnd, ConversionFlags flags)
Convert a partial UTF8 sequence to UTF32.
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
ConversionResult ConvertUTF8toUTF32(const UTF8 **sourceStart, const UTF8 *sourceEnd, UTF32 **targetStart, UTF32 *targetEnd, ConversionFlags flags)
Convert a partial UTF8 sequence to UTF32.
bool hasUTF16ByteOrderMark(ArrayRef< char > SrcBytes)
Returns true if a blob of text starts with a UTF-16 big or little endian byte order mark...
bool convertUTF8ToUTF16String(StringRef SrcUTF8, SmallVectorImpl< UTF16 > &DstUTF16)
Converts a UTF-8 string into a UTF-16 string with native endianness.
bool convertUTF16ToUTF8String(ArrayRef< UTF16 > SrcUTF16, SmallVectorImpl< char > &DstUTF8)
Converts a UTF-16 string into a UTF-8 string.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:999
bool ConvertCodePointToUTF8(unsigned Source, char *&ResultPtr)
Convert an Unicode code point to UTF8 sequence.