• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_UTIL_H
16 #define OHOS_GLOBAL_I18N_LOCALE_UTIL_H
17 
18 #include <string>
19 #include "locale_info.h"
20 
21 namespace OHOS {
22 namespace Global {
23 namespace I18n {
24 class LocaleUtil {
25 public:
26    static bool IsRTL(const std::string &locale);
27    static uint16_t EncodeLanguageByLocaleInfo(const LocaleInfo *locale);
28    static uint32_t EncodeScriptByLocaleInfo(const LocaleInfo *locale);
29    static uint16_t EncodeRegionByLocaleInfo(const LocaleInfo *locale);
30    static uint16_t EncodeLanguage(const char *language);
31    static uint32_t EncodeScript(const char *script);
32    static uint16_t EncodeRegion(const char *region);
33    static uint64_t EncodeLocale(const char *language, const char *script, const char *region);
34    static bool IsStrEmpty(const char *s);
35    static void DecodeScript(uint32_t encodeScript, char *outValue);
36    static bool IsAlphaString(const char *s, int32_t len);
37    static bool IsNumericString(const char *s, int32_t len);
38 
39 private:
40    static uint16_t EncodeLanguageOrRegion(const char *str, char base);
41    static constexpr uint16_t NULL_LANGUAGE = 0x00;
42    static constexpr uint16_t NULL_REGION = 0x00;
43    static constexpr uint16_t NULL_SCRIPT = 0x0000;
44 };
45 } // namespace I18n
46 } // namespace Global
47 } // namespace OHOS
48 #endif
49