• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 OHOS_GLOBAL_I18N_LOCALE_INFO_H
16 #define OHOS_GLOBAL_I18N_LOCALE_INFO_H
17 
18 #include <map>
19 #include <set>
20 #include <cstdint>
21 
22 #include "iosfwd"
23 #include "string"
24 #include "unicode/locid.h"
25 
26 namespace OHOS {
27 namespace Global {
28 namespace I18n {
29 class LocaleInfo {
30 public:
31     explicit LocaleInfo(const std::string &localeTag);
32     LocaleInfo(const std::string &localeTag, std::map<std::string, std::string> &configs);
33     virtual ~LocaleInfo();
34     std::string GetLanguage() const;
35     std::string GetScript() const;
36     std::string GetRegion() const;
37     std::string GetBaseName() const;
38     std::string GetCalendar() const;
39     std::string GetCollation() const;
40     std::string GetHourCycle() const;
41     std::string GetNumberingSystem() const;
42     std::string Maximize();
43     std::string Minimize();
44     std::string GetNumeric() const;
45     std::string GetCaseFirst() const;
46     std::string ToString() const;
47     icu::Locale GetLocale() const;
48     bool InitSuccess() const;
49     static const uint32_t SCRIPT_LEN = 4;
50     static const uint32_t REGION_LEN = 2;
51     static std::set<std::string> allValidLocales;
52     static std::set<std::string> GetValidLocales();
53 private:
54     std::string language;
55     std::string region;
56     std::string script;
57     std::string baseName;
58     std::string calendar;
59     std::string collation;
60     std::string hourCycle;
61     std::string numberingSystem;
62     std::string numeric;
63     std::string caseFirst;
64     std::string finalLocaleTag;
65     icu::Locale locale;
66     bool localeStatus = false;
67     std::string calendarTag = "-ca-";
68     std::string collationTag = "-co-";
69     std::string hourCycleTag = "-hc-";
70     std::string numberingSystemTag = "-nu-";
71     std::string numericTag = "-kn-";
72     std::string caseFirstTag = "-kf-";
73     static bool icuInitialized;
74     static bool Init();
75     static const uint32_t CONFIG_TAG_LEN = 4;
76     std::map<std::string, std::string> configs;
77     void ComputeFinalLocaleTag(const std::string &localeTag);
78     void ParseConfigs();
79     void ParseLocaleTag(const std::string &localeTag);
80     void ResetFinalLocaleStatus();
81     void InitLocaleInfo(const std::string &localeTag, std::map<std::string, std::string> &configMap);
82 };
83 } // namespace I18n
84 } // namespace Global
85 } // namespace OHOS
86 #endif