• 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_STANDARD_COLLATOR_H
16 #define GLOBAL_I18N_STANDARD_COLLATOR_H
17 
18 #include <string>
19 #include <map>
20 #include <vector>
21 #include <set>
22 
23 #include "unicode/locid.h"
24 #include "unicode/coll.h"
25 
26 #include "locale_info.h"
27 
28 namespace OHOS {
29 namespace Global {
30 namespace I18n {
31 typedef enum CompareResult {
32     INVALID = -2,
33     SMALLER,
34     EQUAL,
35     GREATER,
36 } CompareResult;
37 
38 class Collator {
39 public:
40     Collator(std::vector<std::string> &localeTags, std::map<std::string, std::string> &options);
41     ~Collator();
42     CompareResult Compare(const std::string &first, const std::string &second);
43     void ResolvedOptions(std::map<std::string, std::string> &options);
44 
45 private:
46     std::string localeStr;
47     std::string localeMatcher;
48     std::string usage;
49     std::string sensitivity;
50     std::string ignorePunctuation;
51     std::string numeric;
52     std::string caseFirst;
53     std::string collation;
54 
55     std::unique_ptr<LocaleInfo> localeInfo = nullptr;
56     icu::Locale locale;
57     icu::Collator *collatorPtr = nullptr;
58 
59     std::set<std::string> GetValidLocales();
60     std::string ParseOption(std::map<std::string, std::string> &options, const std::string &key);
61     void ParseAllOptions(std::map<std::string, std::string> &options);
62     bool IsValidCollation(std::string &collation, UErrorCode &status);
63     void SetCollation(UErrorCode &status);
64     void SetUsage(UErrorCode &status);
65     void SetNumeric(UErrorCode &status);
66     void SetCaseFirst(UErrorCode &status);
67     void SetSensitivity(UErrorCode &status);
68     void SetIgnorePunctuation(UErrorCode &status);
69     bool InitCollator();
70 };
71 } // namespace I18n
72 } // namespace Global
73 } // namespace OHOS
74 #endif
75