language-extensions/R/common/src/Unicode.cpp
// -------------------------------------------------------------------------------------------------
// Name: GetChar8
//
// Description:
//  Converts UTF32 to UTF8 and return the number of char8s in charLen.
//
GetChar8
Description:
Converts UTF32 to UTF8 and return the number of char8s in charLen.
GetChar8 Description : Converts UTF32 to UTF8 and return the number of char8s in charLen .
static inline void
GetChar8(char32_t char32, char *char8, size_t *charLen) noexcept
{
	if (char32 < 0x80)
	{
		*char8 = static_cast<char>(char32);
		*charLen = OneChar8Len;
	}
	else if (char32 < 0x800)
	{
		char8[1] = 0x80 | (char32 & 0x3f);
		char32 >>= 6;
		char8[0] = static_cast<char>(0xc0 | char32);
		*charLen = TwoChar8Len;
	}
	else if (char32 < 0x10000)
	{
		char8[2] = 0x80 | (char32 & 0x3f);
		char32 >>= 6;
		char8[1] = 0x80 | (char32 & 0x3f);
		char32 >>= 6;
		char8[0] = static_cast<char>(0xe0 | char32);
		*charLen = ThreeChar8Len;
	}
	else
	{
		char8[3] = 0x80 | (char32 & 0x3f);
		char32 >>= 6;
		char8[2] = 0x80 | (char32 & 0x3f);
		char32 >>= 6;
		char8[1] = 0x80 | (char32 & 0x3f);
		char32 >>= 6;
		char8[0] = static_cast<char>(0xf0 | char32);
		*charLen = FourChar8Len;
	}
}
static inline void GetChar8 ( char32_t char32 , char * char8 , size_t * charLen ) noexcept { if ( char32 < 0x80 ) { * char8 = static_cast < char > ( char32 ) ; * charLen = OneChar8Len ; } else if ( char32 < 0x800 ) { char8 [ 1 ] = 0x80 | ( char32 & 0x3f ) ; char32 >>= 6 ; char8 [ 0 ] = static_cast < char > ( 0xc0 | char32 ) ; * charLen = TwoChar8Len ; } else if ( char32 < 0x10000 ) { char8 [ 2 ] = 0x80 | ( char32 & 0x3f ) ; char32 >>= 6 ; char8 [ 1 ] = 0x80 | ( char32 & 0x3f ) ; char32 >>= 6 ; char8 [ 0 ] = static_cast < char > ( 0xe0 | char32 ) ; * charLen = ThreeChar8Len ; } else { char8 [ 3 ] = 0x80 | ( char32 & 0x3f ) ; char32 >>= 6 ; char8 [ 2 ] = 0x80 | ( char32 & 0x3f ) ; char32 >>= 6 ; char8 [ 1 ] = 0x80 | ( char32 & 0x3f ) ; char32 >>= 6 ; char8 [ 0 ] = static_cast < char > ( 0xf0 | char32 ) ; * charLen = FourChar8Len ; } }
Name: GetChar8
Description:
Converts UTF32 to UTF8 and return the number of char8s in charLen.
Name : GetChar8 Description : Converts UTF32 to UTF8 and return the number of char8s in charLen .