提交 f890af1f 编写于 作者: P proller 提交者: alexey-milovidov

Remove code and includes from Collator.h, fix including <unicode/...> in dbms (#395)

上级 8c0e81f8
......@@ -172,10 +172,13 @@ else ()
endif ()
include (cmake/find_openssl.cmake)
include (cmake/find_icu4c.cmake)
include (cmake/find_boost.cmake)
include (cmake/find_poco.cmake)
include (cmake/find_libtool.cmake)
include (cmake/find_rt.cmake)
include (cmake/find_readline_edit.cmake)
if (ENABLE_LIBTCMALLOC)
include (cmake/find_gperftools.cmake)
endif ()
......
#pragma once
#pragma GCC diagnostic push
#ifdef __APPLE__
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include <unicode/ucol.h>
#pragma GCC diagnostic pop
#include <DB/Common/Exception.h>
#include <DB/IO/WriteHelpers.h>
#include <common/Common.h>
#include <Poco/String.h>
#include <string>
#include <boost/noncopyable.hpp>
struct UCollator;
namespace DB
{
......@@ -30,48 +18,12 @@ namespace DB
class Collator : private boost::noncopyable
{
public:
explicit Collator(const std::string & locale_) : locale(Poco::toLower(locale_))
{
UErrorCode status = U_ZERO_ERROR;
explicit Collator(const std::string & locale_);
~Collator();
collator = ucol_open(locale.c_str(), &status);
if (status != U_ZERO_ERROR)
{
ucol_close(collator);
throw DB::Exception("Unsupported collation locale: " + locale, DB::ErrorCodes::UNSUPPORTED_COLLATION_LOCALE);
}
}
~Collator()
{
ucol_close(collator);
}
int compare(const char * str1, size_t length1, const char * str2, size_t length2) const;
int compare(const char * str1, size_t length1, const char * str2, size_t length2) const
{
UCharIterator iter1, iter2;
uiter_setUTF8(&iter1, str1, length1);
uiter_setUTF8(&iter2, str2, length2);
UErrorCode status = U_ZERO_ERROR;
UCollationResult compare_result = ucol_strcollIter(collator, &iter1, &iter2, &status);
if (status != U_ZERO_ERROR)
throw DB::Exception("ICU collation comparison failed with error code: " + DB::toString(status),
DB::ErrorCodes::COLLATION_COMPARISON_FAILED);
/** Values of enum UCollationResult are equals to what exactly we need:
* UCOL_EQUAL = 0
* UCOL_GREATER = 1
* UCOL_LESS = -1
*/
return compare_result;
}
const std::string & getLocale() const
{
return locale;
}
const std::string & getLocale() const;
private:
std::string locale;
......
include (${CMAKE_SOURCE_DIR}/cmake/find_readline_edit.cmake)
add_library (clickhouse-client Client.cpp)
target_link_libraries (clickhouse-client dbms ${LINE_EDITING_LIBS} ${Boost_PROGRAM_OPTIONS_LIBRARY})
install (FILES config.xml DESTINATION ${CLICKHOUSE_ETC_DIR}/clickhouse-client COMPONENT clickhouse-client)
......
#include <DB/Common/Collator.h>
#pragma GCC diagnostic push
#ifdef __APPLE__
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include <unicode/ucol.h>
#pragma GCC diagnostic pop
#include <DB/Common/Exception.h>
#include <DB/IO/WriteHelpers.h>
#include <common/Common.h>
#include <Poco/String.h>
Collator::Collator(const std::string & locale_) : locale(Poco::toLower(locale_))
{
UErrorCode status = U_ZERO_ERROR;
collator = ucol_open(locale.c_str(), &status);
if (status != U_ZERO_ERROR)
{
ucol_close(collator);
throw DB::Exception("Unsupported collation locale: " + locale, DB::ErrorCodes::UNSUPPORTED_COLLATION_LOCALE);
}
}
Collator::~Collator()
{
ucol_close(collator);
}
int Collator::compare(const char * str1, size_t length1, const char * str2, size_t length2) const
{
UCharIterator iter1, iter2;
uiter_setUTF8(&iter1, str1, length1);
uiter_setUTF8(&iter2, str2, length2);
UErrorCode status = U_ZERO_ERROR;
UCollationResult compare_result = ucol_strcollIter(collator, &iter1, &iter2, &status);
if (status != U_ZERO_ERROR)
throw DB::Exception("ICU collation comparison failed with error code: " + DB::toString(status),
DB::ErrorCodes::COLLATION_COMPARISON_FAILED);
/** Values of enum UCollationResult are equals to what exactly we need:
* UCOL_EQUAL = 0
* UCOL_GREATER = 1
* UCOL_LESS = -1
*/
return compare_result;
}
const std::string & Collator::getLocale() const
{
return locale;
}
#include <sstream>
#include <DB/Core/SortDescription.h>
#include <DB/Common/Collator.h>
......
include (${CMAKE_SOURCE_DIR}/cmake/find_icu4c.cmake)
SET(CONFIG_VERSION ${CMAKE_CURRENT_BINARY_DIR}/include/common/config_version.h)
SET(CONFIG_COMMON ${CMAKE_CURRENT_BINARY_DIR}/include/common/config_common.h)
......
include (${CMAKE_SOURCE_DIR}/cmake/find_readline_edit.cmake)
add_executable(zkutil_test zkutil_test.cpp)
target_link_libraries(zkutil_test zkutil dbms ${LINE_EDITING_LIBS})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册