language-extensions/R/common/src/Unicode.cpp
// -------------------------------------------------------------------------------------------------
// Name: GetChar32
//
// Description:
//  Converts a UTF8 character to UTF32
//
GetChar32
Description:
Converts a UTF8 character to UTF32
GetChar32 Description : Converts a UTF8 character to UTF32
static inline void
GetChar32(const char *char8, size_t char8Len, char32_t *char32, size_t *len, bool *ill)
{
	*ill = false;
	const uint8_t* p = reinterpret_cast<const uint8_t*>(char8);
	if (*p <= 0x7f)
	{
		*char32 = static_cast<unsigned char>(*p);
		*len = OneChar8Len;
	}
	else
	{
		CharClass charClass = GetCharClass(*p);
		switch (charClass)
		{
		case CharClass::L2A:
			Handle2ByteUtf8(p, char8Len, char32, len, ill);
			break;
		case CharClass::L3A:
		case CharClass::L3B:
		case CharClass::L3C:
			HandleUtf8<3>(p, char8Len, char32, len, ill);
			break;
		case CharClass::L4A:
		case CharClass::L4B:
		case CharClass::L4C:
			HandleUtf8<4>(p, char8Len, char32, len, ill);
			break;
		default:
			 Invalid character
			*ill = true;
			*char32 = BadChar;
			*len = OneChar8Len;
		}
	}
}
static inline void GetChar32 ( const char * char8 , size_t char8Len , char32_t * char32 , size_t * len , bool * ill ) { * ill = false ; const uint8_t * p = reinterpret_cast < const uint8_t * > ( char8 ) ; if ( * p <= 0x7f ) { * char32 = static_cast < unsigned char > ( * p ) ; * len = OneChar8Len ; } else { CharClass charClass = GetCharClass ( * p ) ; switch ( charClass ) { case CharClass :: L2A : Handle2ByteUtf8 ( p , char8Len , char32 , len , ill ) ; break ; case CharClass :: L3A : case CharClass :: L3B : case CharClass :: L3C : HandleUtf8 < 3 > ( p , char8Len , char32 , len , ill ) ; break ; case CharClass :: L4A : case CharClass :: L4B : case CharClass :: L4C : HandleUtf8 < 4 > ( p , char8Len , char32 , len , ill ) ; break ; default : * ill = true ; * char32 = BadChar ; * len = OneChar8Len ; } } }
Name: GetChar32
Description:
Converts a UTF8 character to UTF32
Name : GetChar32 Description : Converts a UTF8 character to UTF32
// Handle ASCII separately // // Invalid character