* Like utf8DecodeCheck, but for UTF-16. */
| 36 | * Like utf8DecodeCheck, but for UTF-16. |
| 37 | */ |
| 38 | static inline OffsetPt utf16DecodeCheck(const char16_t* str, std::u16string::size_type i) { |
| 39 | if (isHighSurrogate(str[i]) && isLowSurrogate(str[i + 1])) { |
| 40 | // High surrogate followed by low surrogate |
| 41 | char32_t pt = (((str[i] - 0xD800) << 10) | (str[i + 1] - 0xDC00)) + 0x10000; |
| 42 | return {2, pt}; |
| 43 | } else if (isHighSurrogate(str[i]) || isLowSurrogate(str[i])) { |
| 44 | // High surrogate *not* followed by low surrogate, or unpaired low surrogate |
| 45 | return kInvalidPt; |
| 46 | } else { |
| 47 | return {1, str[i]}; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | static inline char32_t utf16Decode(const char16_t* str, std::u16string::size_type& i) { |
| 52 | OffsetPt res = utf16DecodeCheck(str, i); |
no test coverage detected