language-extensions/R/common/src/Unicode.cpp
// -------------------------------------------------------------------------------------------------
// Name: GetChar32
//
// Description:
//  Converts a UTF16 character to UTF32 and return the number of char16s in len.
//
GetChar32
Description:
Converts a UTF16 character to UTF32 and return the number of char16s in len.
GetChar32 Description : Converts a UTF16 character to UTF32 and return the number of char16s in len .
static inline void
GetChar32(
	const char16_t   *char16,
	size_t           char16Len,
	char32_t         *char32,
	size_t           *len,
	bool             throwOnError = false)
{
	if (*char16 <= 0xd7ff || *char16 >= 0xe000)
	{
		*char32 = *char16;
		*len = OneChar16Len;
	}
	else if (*char16 <= 0xdbff && char16Len > 1 && char16[1] >= 0xdc00 && char16[1] <= 0xdfff)
	{
		*char32 =
			0x10000 +
			(((static_cast<char32_t>(char16[0]) - 0xd800) << 10) |
			(static_cast<char32_t>(char16[1]) - 0xdc00));
		*len = TwoChar16Len;
	}
	else if (throwOnError)
	{
		throw std::invalid_argument("There is a bad UTF-16 character");
	}
	else
	{
		*char32 = BadChar;
		*len = OneChar16Len;
	}
}
static inline void GetChar32 ( const char16_t * char16 , size_t char16Len , char32_t * char32 , size_t * len , bool throwOnError = false ) { if ( * char16 <= 0xd7ff || * char16 >= 0xe000 ) { * char32 = * char16 ; * len = OneChar16Len ; } else if ( * char16 <= 0xdbff && char16Len > 1 && char16 [ 1 ] >= 0xdc00 && char16 [ 1 ] <= 0xdfff ) { * char32 = 0x10000 + ( ( ( static_cast < char32_t > ( char16 [ 0 ] ) - 0xd800 ) << 10 ) | ( static_cast < char32_t > ( char16 [ 1 ] ) - 0xdc00 ) ) ; * len = TwoChar16Len ; } else if ( throwOnError ) { throw std :: invalid_argument ( " " ) ; } else { * char32 = BadChar ; * len = OneChar16Len ; } }
Name: GetChar32
Description:
Converts a UTF16 character to UTF32 and return the number of char16s in len.
Name : GetChar32 Description : Converts a UTF16 character to UTF32 and return the number of char16s in len .
// Not a valid UTF16 sequence. WideCharToMultiByte replaces invalid characters // with 0xfffd, unless the WC_ERR_INVALID_CHARS flag is used. In the name to // avoid errors, our implementation follows the same approach. //