1 | #pragma once |
---|---|
2 | |
3 | #include <string> |
4 | #include <vector> |
5 | #include <boost/noncopyable.hpp> |
6 | #include <unordered_map> |
7 | |
8 | |
9 | struct UCollator; |
10 | |
11 | /// Class represents available locales for collations. |
12 | class AvailableCollationLocales : private boost::noncopyable |
13 | { |
14 | public: |
15 | |
16 | struct LocaleAndLanguage |
17 | { |
18 | std::string locale_name; /// ISO locale code |
19 | std::optional<std::string> language; /// full language name in English |
20 | }; |
21 | |
22 | using AvailableLocalesMap = std::unordered_map<std::string, LocaleAndLanguage>; |
23 | using LocalesVector = std::vector<LocaleAndLanguage>; |
24 | |
25 | static const AvailableCollationLocales & instance(); |
26 | |
27 | /// Get all collations with names in sorted order |
28 | LocalesVector getAvailableCollations() const; |
29 | |
30 | /// Check that collation is supported |
31 | bool isCollationSupported(const std::string & locale_name) const; |
32 | |
33 | private: |
34 | AvailableCollationLocales(); |
35 | private: |
36 | AvailableLocalesMap locales_map; |
37 | }; |
38 | |
39 | class Collator : private boost::noncopyable |
40 | { |
41 | public: |
42 | explicit Collator(const std::string & locale_); |
43 | ~Collator(); |
44 | |
45 | int compare(const char * str1, size_t length1, const char * str2, size_t length2) const; |
46 | |
47 | const std::string & getLocale() const; |
48 | private: |
49 | |
50 | std::string locale; |
51 | UCollator * collator; |
52 | }; |
53 |