airborne12 commented on code in PR #109: URL: https://github.com/apache/doris-thirdparty/pull/109#discussion_r1278737430
########## src/core/CLucene/util/stringUtil.h: ########## @@ -234,35 +234,62 @@ class StringUtil { int32_t surplus_bytes = 0; uint32_t codepoint = 0; for (uint8_t c : str) { - if (bytes_in_char == 0) { - if ((c & 0x80) == 0) { - codepoint = c; - continue; - } else if ((c & 0xE0) == 0xC0) { - codepoint = c & 0x1F; - bytes_in_char = 1; - } else if ((c & 0xF0) == 0xE0) { - codepoint = c & 0x0F; - bytes_in_char = 2; - } else if ((c & 0xF8) == 0xF0) { - codepoint = c & 0x07; - bytes_in_char = 3; + if (bytes_in_char == 0) { + if ((c & 0x80) == 0) { + codepoint = c; + continue; + } else if ((c & 0xE0) == 0xC0) { + codepoint = c & 0x1F; + bytes_in_char = 1; + } else if ((c & 0xF0) == 0xE0) { + codepoint = c & 0x0F; + bytes_in_char = 2; + } else if ((c & 0xF8) == 0xF0) { + codepoint = c & 0x07; + bytes_in_char = 3; + } else { + return -1; + } + surplus_bytes = 1; } else { - return -1; + if ((c & 0xC0) != 0x80) return -1; + codepoint = (codepoint << 6) | (c & 0x3F); + if (!is_valid_codepoint(codepoint)) { + return -1; + } + bytes_in_char--; + surplus_bytes++; } - surplus_bytes = 1; - } else { - if ((c & 0xC0) != 0x80) return -1; - codepoint = (codepoint << 6) | (c & 0x3F); - if (!is_valid_codepoint(codepoint)) { - return -1; - } - bytes_in_char--; - surplus_bytes++; - } } return bytes_in_char == 0 ? 0 : surplus_bytes; } + + // utf8: 1-4 char = 1 wchar_t, invalid utf8: 1 char = 1 wchar_t Review Comment: may be need some unitest for this function -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For additional commands, e-mail: dev-h...@doris.apache.org