maartenbreddels commented on a change in pull request #7449: URL: https://github.com/apache/arrow/pull/7449#discussion_r446990168
########## File path: cpp/src/arrow/compute/kernels/scalar_string.cc ########## @@ -30,6 +31,124 @@ namespace internal { namespace { +// lookup tables +std::vector<uint32_t> lut_upper_codepoint; +std::vector<uint32_t> lut_lower_codepoint; +std::once_flag flag_case_luts; + +constexpr uint32_t REPLACEMENT_CHAR = + '?'; // the proper replacement char would be the 0xFFFD codepoint, but that can + // increase string length by a factor of 3 +constexpr int MAX_CODEPOINT_LUT = 0xffff; // up to this codepoint is in a lookup table + +static inline void utf8_encode(uint8_t*& str, uint32_t codepoint) { + if (codepoint < 0x80) { + *str++ = codepoint; + } else if (codepoint < 0x800) { + *str++ = 0xC0 + (codepoint >> 6); + *str++ = 0x80 + (codepoint & 0x3F); + } else if (codepoint < 0x10000) { + *str++ = 0xE0 + (codepoint >> 12); + *str++ = 0x80 + ((codepoint >> 6) & 0x3F); + *str++ = 0x80 + (codepoint & 0x3F); + } else if (codepoint < 0x200000) { + *str++ = 0xF0 + (codepoint >> 18); + *str++ = 0x80 + ((codepoint >> 12) & 0x3F); + *str++ = 0x80 + ((codepoint >> 6) & 0x3F); + *str++ = 0x80 + (codepoint & 0x3F); + } else { + *str++ = codepoint; Review comment: Agree, this is not useful. Now also replacing that by '?', in principle, it should not happen, it can only happen when there is an internal bug (e.g. uppercase gives the wrong codepoint), but now it's more informative. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org