Helper function to convert Char-16 index to byte index
| 505 | |
| 506 | // Helper function to convert Char-16 index to byte index |
| 507 | FOLLY_ALWAYS_INLINE static int64_t |
| 508 | char16IndexToByteIndex(const char16_t* src, size_t strSize, size_t charSize) { |
| 509 | int64_t byteIndex = 0; |
| 510 | const char16_t* srcLimit = src != nullptr ? src + charSize : nullptr; |
| 511 | uint32_t ch = 0, ch2 = 0; |
| 512 | while (byteIndex < strSize && src < srcLimit) { |
| 513 | // Increment currentCharIndex for each starting byte of UTF-8 character |
| 514 | uint32_t ch = *src++; |
| 515 | if (ch <= 0x7f) { |
| 516 | byteIndex++; |
| 517 | } else if (ch <= 0x7ff) { |
| 518 | byteIndex += 2; |
| 519 | } else if (ch <= 0xd7ff || ch >= 0xe000) { |
| 520 | byteIndex += 3; |
| 521 | } else if ( |
| 522 | ((ch & 0x400) == 0) && src < srcLimit && |
| 523 | (((ch2 = *src) & 0xfffffc00) == 0xdc00)) { |
| 524 | ++src; |
| 525 | byteIndex += 4; |
| 526 | } else { |
| 527 | byteIndex += 3; |
| 528 | } |
| 529 | } |
| 530 | return byteIndex; |
| 531 | } |
| 532 | |
| 533 | /// Returns the start char index of the Nth instance of subString in |
| 534 | /// string. Search starts from startPosition. Positions start with 0. If not |
no outgoing calls
no test coverage detected