language-extensions/R/common/src/Unicode.cpp
// -------------------------------------------------------------------------------------------------
// Name: ToUtf16
//
// Description:
//  Converts the given char string with the given length to an utf-16 encoded u16string
//
ToUtf16
Description:
Converts the given char string with the given length to an utf-16 encoded u16string
ToUtf16 Description : Converts the given char string with the given length to an utf - 16 encoded u16string
void ToUtf16(const char *s, size_t l, std::u16string &ans)
{
	ans.resize(0);
	size_t i = 0;
	size_t j = 0;
	char32_t char32 = 0;
	size_t char8Len;
	char16_t char16s[2];
	size_t char16Len = 0;
	bool isIll;
	while (i < l)
	{
		GetChar32(s+i, l-i, &char32, &char8Len, &isIll);
		if (!isIll)
		{
			GetChar16(char32, char16s, &char16Len);
			j += char16Len;
		}
		else
		{
			size_t char16Len;
			GetChar16(char32, char16s, &char16Len);
			j += char16Len;
		}
		switch(char16Len)
		{
		case 1:
			ans.push_back(char16s[0]);
			break;
		case 2:
			ans.push_back(char16s[0]);
			ans.push_back(char16s[1]);
			break;
		}
		i += char8Len;
	}
}
void ToUtf16 ( const char * s , size_t l , std :: u16string & ans ) { ans . resize ( 0 ) ; size_t i = 0 ; size_t j = 0 ; char32_t char32 = 0 ; size_t char8Len ; char16_t char16s [ 2 ] ; size_t char16Len = 0 ; bool isIll ; while ( i < l ) { GetChar32 ( s + i , l - i , & char32 , & char8Len , & isIll ) ; if ( ! isIll ) { GetChar16 ( char32 , char16s , & char16Len ) ; j += char16Len ; } else { size_t char16Len ; GetChar16 ( char32 , char16s , & char16Len ) ; j += char16Len ; } switch ( char16Len ) { case 1 : ans . push_back ( char16s [ 0 ] ) ; break ; case 2 : ans . push_back ( char16s [ 0 ] ) ; ans . push_back ( char16s [ 1 ] ) ; break ; } i += char8Len ; } }
Name: ToUtf16
Description:
Converts the given char string with the given length to an utf-16 encoded u16string
Name : ToUtf16 Description : Converts the given char string with the given length to an utf - 16 encoded u16string