aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Columns/Collator.h
blob: dd61b66a2ca11d68972f173fc4344602ff39574f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once

#include <string>
#include <optional>
#include <vector>
#include <boost/noncopyable.hpp>
#include <unordered_map>


struct UCollator;

/// Class represents available locales for collations.
class AvailableCollationLocales : private boost::noncopyable
{
public:

    struct LocaleAndLanguage
    {
        std::string locale_name; /// ISO locale code
        std::optional<std::string> language; /// full language name in English
    };

    using AvailableLocalesMap = std::unordered_map<std::string, LocaleAndLanguage>;
    using LocalesVector = std::vector<LocaleAndLanguage>;

    static const AvailableCollationLocales & instance();

    /// Get all collations with names in sorted order
    LocalesVector getAvailableCollations() const;

    /// Check that collation is supported
    bool isCollationSupported(const std::string & locale_name) const;

private:
    AvailableCollationLocales();

    AvailableLocalesMap locales_map;
};

class Collator : private boost::noncopyable
{
public:
    explicit Collator(const std::string & locale_);
    ~Collator();

    int compare(const char * str1, size_t length1, const char * str2, size_t length2) const;

    const std::string & getLocale() const;

    bool operator==(const Collator & other) const { return this->getLocale() == other.getLocale(); }

private:
    std::string locale;
    UCollator * collator;
};