| 1410 | } |
| 1411 | |
| 1412 | String String::fromCharCode( int c ) |
| 1413 | { |
| 1414 | if (0<=c && c<=255) |
| 1415 | { |
| 1416 | return sConstStrings[c]; |
| 1417 | } |
| 1418 | else |
| 1419 | { |
| 1420 | #ifdef HX_SMART_STRINGS |
| 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")); |
| 1426 | #endif |
| 1427 | |
| 1428 | int group = c>>10; |
| 1429 | if (group>=1088) |
| 1430 | hx::Throw(HX_CSTRING("Invalid char code")); |
| 1431 | if (!sCharToString[group]) |
| 1432 | { |
| 1433 | String *ptr = (String *)malloc( sizeof(String)*1024 ); |
| 1434 | memset(ptr, 0, sizeof(String)*1024 ); |
| 1435 | sCharToString[group] = ptr; |
| 1436 | } |
| 1437 | String *ptr = sCharToString[group]; |
| 1438 | int cid = c & ((1<<10)-1); |
| 1439 | if (!ptr[cid].__s) |
| 1440 | { |
| 1441 | #ifdef HX_SMART_STRINGS |
| 1442 | int l = UTF16BytesCheck(c); |
| 1443 | char16_t *p = (char16_t *)InternalCreateConstBuffer(0,(l+1)*2,true); |
| 1444 | ((unsigned int *)p)[-1] |= HX_GC_STRING_CHAR16_T; |
| 1445 | if (c>=0x10000) |
| 1446 | { |
| 1447 | int over = (c-0x10000); |
| 1448 | p[0] = (over>>10) + 0xd800; |
| 1449 | p[1] = (over&0x3ff) + 0xdc00; |
| 1450 | } |
| 1451 | else |
| 1452 | p[0] = c; |
| 1453 | |
| 1454 | ptr[cid].length = l; |
| 1455 | ptr[cid].__w = p; |
| 1456 | fixHashPerm16(ptr[cid]); |
| 1457 | #else |
| 1458 | char buf[5]; |
| 1459 | int utf8Len = UTF8Bytes(c); |
| 1460 | char *p = buf; |
| 1461 | UTF8EncodeAdvance(p,c); |
| 1462 | buf[utf8Len] = '\0'; |
| 1463 | const char *s = (char *)InternalCreateConstBuffer(buf,utf8Len+1,true); |
| 1464 | ptr[cid].length = utf8Len; |
| 1465 | ptr[cid].__s = s; |
| 1466 | #endif |
| 1467 | } |
| 1468 | return ptr[cid]; |
| 1469 | } |
nothing calls this directly
no test coverage detected