From 0b3e18d060d2ca72e1d6bc4cdb71488672dfc57d Mon Sep 17 00:00:00 2001 From: Adonis Ling Date: Wed, 22 Feb 2023 15:04:48 +0800 Subject: [PATCH] [chore](macOS) Support LLVM Clang 15 (#16991) Remove the deprecated classes std::codecvt_utf8_utf16 and std::wstring_convert. Use libiconv to convert UTF-8 strings to UTF-16LE ones. --- be/src/exec/table_connector.cpp | 40 +++++++++++++++++++++++++++--- tools/single-node-cluster/multi-fe | 2 +- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/be/src/exec/table_connector.cpp b/be/src/exec/table_connector.cpp index 2bbaaaabcd..ddaa76f618 100644 --- a/be/src/exec/table_connector.cpp +++ b/be/src/exec/table_connector.cpp @@ -17,9 +17,10 @@ #include "exec/table_connector.h" +#include #include - -#include +#include +#include #include "runtime/define_primitive_type.h" #include "runtime/primitive_type.h" @@ -46,8 +47,39 @@ void TableConnector::init_profile(doris::RuntimeProfile* profile) { } std::u16string TableConnector::utf8_to_u16string(const char* first, const char* last) { - std::wstring_convert, char16_t> utf8_utf16_cvt; - return utf8_utf16_cvt.from_bytes(first, last); + auto deleter = [](auto convertor) { + if (convertor == reinterpret_cast(-1)) { + return; + } + iconv_close(convertor); + }; + std::unique_ptr, decltype(deleter)> convertor( + iconv_open("UTF-16LE", "UTF-8"), deleter); + + char* in = const_cast(first); + size_t inbytesleft = last - first; + + char16_t buffer[1024]; + char* out = reinterpret_cast(&buffer[0]); + size_t outbytesleft = sizeof(buffer); + + std::u16string result; + while (inbytesleft > 0) { + if (iconv(convertor.get(), &in, &inbytesleft, &out, &outbytesleft)) { + if (errno == E2BIG) { + result += std::u16string_view(buffer, + (sizeof(buffer) - outbytesleft) / sizeof(char16_t)); + out = reinterpret_cast(&buffer[0]); + outbytesleft = sizeof(buffer); + } else { + LOG(WARNING) << fmt::format("Failed to convert the UTF-8 string {} to UTF-16LE", + std::string(first, last)); + return result; + } + } + } + result += std::u16string_view(buffer, (sizeof(buffer) - outbytesleft) / sizeof(char16_t)); + return result; } Status TableConnector::append(const std::string& table_name, vectorized::Block* block, diff --git a/tools/single-node-cluster/multi-fe b/tools/single-node-cluster/multi-fe index 762fab14fa..81821a7c1a 100755 --- a/tools/single-node-cluster/multi-fe +++ b/tools/single-node-cluster/multi-fe @@ -72,7 +72,7 @@ ${BASH_SOURCE[0]} start|stop|clean [OPTIONS ...] stop Stop the FE cluster. - clean Stop the data (rm -rf "\$(pwd)"/fe*). + clean Clean the data (rm -rf "\$(pwd)"/fe*). EOF exit 1 }