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_RESOURCE_MANAGER_LOCALEMATCHER_H
16 #define OHOS_RESOURCE_MANAGER_LOCALEMATCHER_H
17 #include "res_locale.h"
18 
19 namespace OHOS {
20 namespace Global {
21 namespace Resource {
22 class LocaleMatcher {
23 public:
24     static int8_t IsMoreSuitable(const ResLocale *current,
25         const ResLocale *other,
26         const ResLocale *request);
27 
28     /**
29      * Whether the current ResLocale same to the other ResLocale
30      * @param current the current ResLocale
31      * @param other the other ResLocale
32      * @return true if the current ResLocale same to the other ResLocale, else false
33      */
34     static bool Match(const ResLocale *current, const ResLocale *other);
35 
36     /**
37      * Whether the string is the language tag
38      * @param str the tag string
39      * @param len the tag length
40      * @return true if the str is language tag, else false
41      */
42     static bool IsLanguageTag(const char *str, int32_t len);
43 
44     /**
45      * Whether the string is the script tag
46      * @param str the tag string
47      * @param len the tag length
48      * @return true if the str is script tag, else false
49      */
50     static bool IsScriptTag(const char *str, int32_t len);
51 
52     /**
53      * Whether the string is the Region tag
54      * @param str the tag string
55      * @param len the tag length
56      * @return true if the str is Region tag, else false
57      */
58     static bool IsRegionTag(const char *str, int32_t len);
59 
60     /**
61      * Get the resLocale script
62      * @param resLocale the resLocale information
63      * @return true if get the resLocale script, else false
64      */
65     static bool Normalize(ResLocale *resLocale);
66 
67     /**
68      * Whether the current resLocale more specific than target resLocale
69      * @param current the current resLocale
70      * @param target the target resLocale
71      * @return 0 means current resLocale same to target resLocale,
72      *         1 means current resLocale more specific than target resLocale, else -1
73      */
74     static int8_t IsMoreSpecificThan(const ResLocale *current, const ResLocale *target);
75 
76 public:
77     static uint64_t EN_US_ENCODE;
78     static uint64_t EN_GB_ENCODE;
79     static uint64_t EN_QAAG_ENCODE;
80     static uint64_t ZH_HANT_MO_ENCODE;
81     static uint64_t ZH_HK_ENCODE;
82     static uint32_t HANT_ENCODE;
83     static constexpr uint64_t ROOT_LOCALE = 0x0;
84     static constexpr uint16_t NULL_LANGUAGE = 0x0;
85     static constexpr uint16_t NULL_REGION = 0x0;
86     static constexpr uint16_t NULL_SCRIPT = 0x0;
87     static constexpr uint64_t NULL_LOCALE = 0x0;
88     static constexpr uint8_t TRACKPATH_ARRAY_SIZE = 5;
89 };
90 } // namespace Resource
91 } // namespace Global
92 } // namespace OHOS
93 #endif
94