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 
16 #ifndef OHOS_RESTOOL_KEY_PARSER_H
17 #define OHOS_RESTOOL_KEY_PARSER_H
18 
19 #include <vector>
20 #include "resource_data.h"
21 
22 namespace OHOS {
23 namespace Global {
24 namespace Restool {
25 class KeyParser {
26 public:
27     static bool Parse(const std::string &folderName, std::vector<KeyParam> &keyparams);
28     static bool ParseLimit(const std::string &func, std::vector<std::string> &limitValues,
29         TargetConfig &targetConfig);
30 
31 private:
32     typedef bool (*parse_key_founction)(const std::string &folderName, std::vector<KeyParam> &keyparams);
33     static bool ParseMatch(const std::vector<std::string> &keys,
34         std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
35     static bool ParseMatchBySeq(const std::vector<std::string> &keys,
36         std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
37 
38     static bool ParseMccMnc(const std::string &folderName, std::vector<KeyParam> &keyparams);
39     static bool ParseMcc(const std::string &folderName, std::vector<KeyParam> &keyparams);
40     static bool ParseMnc(const std::string &folderName, std::vector<KeyParam> &keyparams);
41     static bool ParseLSR(const std::string &folderName, std::vector<KeyParam> &keyparams);
42     static bool ParseLanguage(const std::string &folderName, std::vector<KeyParam> &keyparams);
43     static bool ParseScript(const std::string &folderName, std::vector<KeyParam> &keyparams);
44     static bool ParseRegion(const std::string &folderName, std::vector<KeyParam> &keyparams);
45     static bool ParseOrientation(const std::string &folderName, std::vector<KeyParam> &keyparams);
46     static bool ParseDeviceType(const std::string &folderName, std::vector<KeyParam> &keyparams);
47     static bool ParseNightMode(const std::string &folderName, std::vector<KeyParam> &keyparams);
48     static bool ParseInputDevice(const std::string &folderName, std::vector<KeyParam> &keyparams);
49     static bool ParseResolution(const std::string &folderName, std::vector<KeyParam> &keyparams);
50 
51     static void PushMccMnc(const std::string &folderName, KeyType type, std::vector<KeyParam> &keyparams);
52     static void PushLSR(const std::string &folderName, KeyType type, std::vector<KeyParam> &keyparams);
53     static void PushValue(uint32_t value, KeyType type, std::vector<KeyParam> &keyparams);
54     static const int32_t MCC_MNC_KEY_LENGHT = 3;
55     static const int32_t SCRIPT_LENGHT = 4;
56     static const int32_t MIN_REGION_LENGHT = 2;
57     static const int32_t MAX_REGION_LENGHT = 3;
58     static std::map<std::string, std::vector<KeyParam>> caches_;
59 };
60 }
61 }
62 }
63 #endif
64