| 441 | |
| 442 | template<typename T> |
| 443 | inline String TCopyString(const T *inString,int inLength) |
| 444 | { |
| 445 | if (!inString) |
| 446 | return String(); |
| 447 | |
| 448 | #ifndef HX_SMART_STRINGS |
| 449 | if (sizeof(T)==1) |
| 450 | { |
| 451 | int len = 0; |
| 452 | const char *res = GCStringDup((const char *)inString,inLength,&len); |
| 453 | return String(res,len); |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | if (inLength == 0) { |
| 458 | return String::emptyString; |
| 459 | } |
| 460 | int length = inLength > 0 ? inLength : 0; |
| 461 | const char *ptr = TConvertToUTF8(inString, &length, 0, true ); |
| 462 | return String(ptr,length); |
| 463 | } |
| 464 | #else |
| 465 | int c16len=0; |
| 466 | bool hasWChar = false; |
| 467 | const T *end = inLength>=0 ? inString + inLength : 0; |
| 468 | if (end) |
| 469 | { |
| 470 | for(const T *s = inString; s<end; s++) |
| 471 | { |
| 472 | unsigned int c = *s; |
| 473 | if (c>127) |
| 474 | hasWChar = true; |
| 475 | c16len += UTF16BytesCheck(c); |
| 476 | } |
| 477 | } |
| 478 | else |
| 479 | for(const T *s = inString; *s; s++) |
| 480 | { |
| 481 | unsigned int c = *s; |
| 482 | if (c>127) |
| 483 | hasWChar = true; |
| 484 | c16len += UTF16BytesCheck(c); |
| 485 | } |
| 486 | |
| 487 | if (hasWChar) |
| 488 | { |
| 489 | char16_t *result = String::allocChar16Ptr(c16len); |
| 490 | c16len = 0; |
| 491 | for(const T *s = inString; ; s++) |
| 492 | { |
| 493 | if (end) |
| 494 | { |
| 495 | if (s>=end) break; |
| 496 | } |
| 497 | else |
| 498 | { |
| 499 | if (!*s) break; |
| 500 | } |
no test coverage detected