| 17 | #endif |
| 18 | |
| 19 | void char2Byte(const char* strBegin, const char* strEnd, vector<uint32_t>& startPos, vector<uint16_t>& length) |
| 20 | { |
| 21 | if (strBegin == strEnd) return; |
| 22 | vector<size_t> charPos; |
| 23 | auto it = strBegin; |
| 24 | for (; it != strEnd; ) |
| 25 | { |
| 26 | charPos.emplace_back(it - strBegin); |
| 27 | uint8_t c = *it; |
| 28 | if ((c & 0xF8) == 0xF0) |
| 29 | { |
| 30 | it += 4; |
| 31 | } |
| 32 | else if ((c & 0xF0) == 0xE0) |
| 33 | { |
| 34 | it += 3; |
| 35 | } |
| 36 | else if ((c & 0xE0) == 0xC0) |
| 37 | { |
| 38 | it += 2; |
| 39 | } |
| 40 | else if ((c & 0x80)) |
| 41 | { |
| 42 | throw std::runtime_error{ "utf-8 decoding error" }; |
| 43 | } |
| 44 | else it += 1; |
| 45 | } |
| 46 | charPos.emplace_back(strEnd - strBegin); |
| 47 | |
| 48 | for (size_t i = 0; i < startPos.size(); ++i) |
| 49 | { |
| 50 | size_t s = startPos[i], e = (size_t)startPos[i] + length[i]; |
| 51 | startPos[i] = charPos[s]; |
| 52 | length[i] = charPos[e] - charPos[s]; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void char2Byte(const string& str, vector<uint32_t>& startPos, vector<uint16_t>& length) |
| 57 | { |
no test coverage detected