Skip to content

Commit c8741e5

Browse files
committed
Allow String::fromCharCode to encode Utf16 surrogates unchanged. This allows a round-trip through charAt
1 parent b4e5ed0 commit c8741e5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/String.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,8 +1418,11 @@ String String::fromCharCode( int c )
14181418
else
14191419
{
14201420
#ifdef HX_SMART_STRINGS
1421-
if (IsUtf16Surrogate(c)||c>=0x110000)
1422-
c = 0xFFFD;
1421+
// Leave Utf16 surrogate handling up to the application - as far as hxcpp is concerned
1422+
// they are single characters. ie, mirror charAt.
1423+
// If the application does not group them as a pair, then it may not be possible to convert to utf8.
1424+
//if (IsUtf16Surrogate(c))
1425+
// hx::Throw(HX_CSTRING("Invalid unpaired surrogate code"));
14231426
#endif
14241427

14251428
int group = c>>10;

0 commit comments

Comments
 (0)