ClickHouse/dbms/Columns/Collator.h

53 lines
1.2 KiB
C++
Raw Normal View History

2013-05-28 16:56:05 +00:00
#pragma once
#include <string>
#include <vector>
#include <boost/noncopyable.hpp>
2019-12-06 22:22:12 +00:00
#include <unordered_map>
struct UCollator;
2019-12-05 15:31:45 +00:00
/// Class represents available locales for collations.
class AvailableCollationLocales : private boost::noncopyable
{
public:
struct LocaleAndLanguage
{
2019-12-06 22:22:12 +00:00
std::string locale_name; /// ISO locale code
std::optional<std::string> language; /// full language name in English
2019-12-05 15:31:45 +00:00
};
2019-12-06 22:22:12 +00:00
using AvailableLocalesMap = std::unordered_map<std::string, LocaleAndLanguage>;
using LocalesVector = std::vector<LocaleAndLanguage>;
static const AvailableCollationLocales & instance();
2019-12-05 15:31:45 +00:00
2019-12-06 22:22:12 +00:00
/// Get all collations with names in sorted order
LocalesVector getAvailableCollations() const;
2019-12-05 15:31:45 +00:00
/// Check that collation is supported
2019-12-06 22:22:12 +00:00
bool isCollationSupported(const std::string & locale_name) const;
2019-12-05 15:31:45 +00:00
private:
2019-12-06 22:22:12 +00:00
AvailableCollationLocales();
2019-12-05 15:31:45 +00:00
private:
2019-12-06 22:22:12 +00:00
AvailableLocalesMap locales_map;
2019-12-05 15:31:45 +00:00
};
class Collator : private boost::noncopyable
2013-05-28 16:56:05 +00:00
{
public:
explicit Collator(const std::string & locale_);
~Collator();
2017-01-22 09:07:34 +00:00
int compare(const char * str1, size_t length1, const char * str2, size_t length2) const;
2017-01-22 09:07:34 +00:00
const std::string & getLocale() const;
2013-05-28 16:56:05 +00:00
private:
2019-12-05 15:31:45 +00:00
std::string locale;
UCollator * collator;
};