• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef GLOBAL_i18n_COLLATOR_H
16 #define GLOBAL_i18n_COLLATOR_H
17 
18 #include <string>
19 #include <map>
20 #include <vector>
21 #include <set>
22 
23 #include "locale_info.h"
24 #include "memory"
25 #include "unicode/coll.h"
26 #include "unicode/locid.h"
27 #include "utypes.h"
28 
29 namespace OHOS {
30 namespace Global {
31 namespace I18n {
32 typedef enum CompareResult {
33     INVALID = -2,
34     SMALLER,
35     EQUAL,
36     GREATER,
37 } CompareResult;
38 
39 class Collator {
40 public:
41     Collator(std::vector<std::string> &localeTags, std::map<std::string, std::string> &options);
42     ~Collator();
43     CompareResult Compare(const std::string &first, const std::string &second);
44     void ResolvedOptions(std::map<std::string, std::string> &options);
45 
46 private:
47     std::string localeStr;
48     std::string localeMatcher;
49     std::string usage;
50     std::string sensitivity;
51     std::string ignorePunctuation;
52     std::string numeric;
53     std::string caseFirst;
54     std::string collation;
55 
56     std::unique_ptr<LocaleInfo> localeInfo = nullptr;
57     icu::Locale locale;
58     icu::Collator *collatorPtr = nullptr;
59     bool createSuccess = false;
60 
61     std::set<std::string> GetValidLocales();
62     std::string ParseOption(std::map<std::string, std::string> &options, const std::string &key);
63     void ParseAllOptions(std::map<std::string, std::string> &options);
64     bool IsValidCollation(std::string &collation);
65     void SetCollation();
66     void SetUsage();
67     void SetNumeric();
68     void SetCaseFirst();
69     void SetSensitivity();
70     void SetIgnorePunctuation();
71     bool InitCollator();
72 };
73 } // namespace I18n
74 } // namespace Global
75 } // namespace OHOS
76 #endif
77