105#ifndef LLVM_SUPPORT_CONVERTUTF_H
106#define LLVM_SUPPORT_CONVERTUTF_H
112#include <system_error>
134#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
135#define UNI_MAX_BMP (UTF32)0x0000FFFF
136#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
137#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
138#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
140#define UNI_MAX_UTF8_BYTES_PER_CODE_POINT 4
142#define UNI_UTF16_BYTE_ORDER_MARK_NATIVE 0xFEFF
143#define UNI_UTF16_BYTE_ORDER_MARK_SWAPPED 0xFFFE
145#define UNI_UTF32_BYTE_ORDER_MARK_NATIVE 0x0000FEFF
146#define UNI_UTF32_BYTE_ORDER_MARK_SWAPPED 0xFFFE0000
161 const UTF8** sourceStart,
const UTF8* sourceEnd,
169 const UTF8** sourceStart,
const UTF8* sourceEnd,
177 const UTF8** sourceStart,
const UTF8* sourceEnd,
181 const UTF16** sourceStart,
const UTF16* sourceEnd,
185 const UTF32** sourceStart,
const UTF32* sourceEnd,
189 const UTF16** sourceStart,
const UTF16* sourceEnd,
193 const UTF32** sourceStart,
const UTF32* sourceEnd,
207template <
typename T>
class ArrayRef;
208template <
typename T>
class SmallVectorImpl;
221 char *&ResultPtr,
const UTF8 *&ErrorPtr);
270 const UTF8 *sourceEnd,
273 if (*source == sourceEnd)
329 SmallVectorImpl<UTF16> &DstUTF16);
334std::error_code UTF8ToUTF16(StringRef utf8, SmallVectorImpl<wchar_t> &utf16);
336std::error_code CurCPToUTF16(StringRef utf8, SmallVectorImpl<wchar_t> &utf16);
337std::error_code UTF16ToUTF8(
const wchar_t *utf16,
size_t utf16_len,
338 SmallVectorImpl<char> &utf8);
340std::error_code UTF16ToCurCP(
const wchar_t *utf16,
size_t utf16_len,
341 SmallVectorImpl<char> &utf8);
StringRef - Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
ConversionResult ConvertUTF8toUTF32(const UTF8 **sourceStart, const UTF8 *sourceEnd, UTF32 **targetStart, UTF32 *targetEnd, ConversionFlags flags)
Convert a partial UTF8 sequence to UTF32.
unsigned getNumBytesForUTF8(UTF8 firstByte)
bool hasUTF16ByteOrderMark(ArrayRef< char > SrcBytes)
Returns true if a blob of text starts with a UTF-16 big or little endian byte order mark.
ConversionResult ConvertUTF8toUTF32Partial(const UTF8 **sourceStart, const UTF8 *sourceEnd, UTF32 **targetStart, UTF32 *targetEnd, ConversionFlags flags)
Convert a partial UTF8 sequence to UTF32.
ConversionResult convertUTF8Sequence(const UTF8 **source, const UTF8 *sourceEnd, UTF32 *target, ConversionFlags flags)
Convert the first UTF8 sequence in the given source buffer to a UTF32 code point.
bool convertWideToUTF8(const std::wstring &Source, std::string &Result)
Converts a std::wstring to a UTF-8 encoded std::string.
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
ConversionResult ConvertUTF32toUTF16(const UTF32 **sourceStart, const UTF32 *sourceEnd, UTF16 **targetStart, UTF16 *targetEnd, ConversionFlags flags)
Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd)
ConversionResult ConvertUTF16toUTF8(const UTF16 **sourceStart, const UTF16 *sourceEnd, UTF8 **targetStart, UTF8 *targetEnd, ConversionFlags flags)
bool convertUTF32ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF32 into a UTF8 std::string.
bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source, char *&ResultPtr, const UTF8 *&ErrorPtr)
Convert an UTF8 StringRef to UTF8, UTF16, or UTF32 depending on WideCharWidth.
ConversionResult ConvertUTF32toUTF8(const UTF32 **sourceStart, const UTF32 *sourceEnd, UTF8 **targetStart, UTF8 *targetEnd, ConversionFlags flags)
Boolean isLegalUTF8String(const UTF8 **source, const UTF8 *sourceEnd)
unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd)
ConversionResult ConvertUTF16toUTF32(const UTF16 **sourceStart, const UTF16 *sourceEnd, UTF32 **targetStart, UTF32 *targetEnd, ConversionFlags flags)
bool convertUTF8ToUTF16String(StringRef SrcUTF8, SmallVectorImpl< UTF16 > &DstUTF16)
Converts a UTF-8 string into a UTF-16 string with native endianness.
bool ConvertCodePointToUTF8(unsigned Source, char *&ResultPtr)
Convert an Unicode code point to UTF8 sequence.
ConversionResult ConvertUTF8toUTF16(const UTF8 **sourceStart, const UTF8 *sourceEnd, UTF16 **targetStart, UTF16 *targetEnd, ConversionFlags flags)