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 29 private: 30 typedef bool (*parse_key_founction)(const std::string &folderName, std::vector<KeyParam> &keyparams); 31 static bool ParseMatch(const std::vector<std::string> &keys, 32 std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions); 33 static bool ParseMatchBySeq(const std::vector<std::string> &keys, 34 std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions); 35 36 static bool ParseMccMnc(const std::string &folderName, std::vector<KeyParam> &keyparams); 37 static bool ParseMcc(const std::string &folderName, std::vector<KeyParam> &keyparams); 38 static bool ParseMnc(const std::string &folderName, std::vector<KeyParam> &keyparams); 39 static bool ParseLSR(const std::string &folderName, std::vector<KeyParam> &keyparams); 40 static bool ParseLanguage(const std::string &folderName, std::vector<KeyParam> &keyparams); 41 static bool ParseScript(const std::string &folderName, std::vector<KeyParam> &keyparams); 42 static bool ParseRegion(const std::string &folderName, std::vector<KeyParam> &keyparams); 43 static bool ParseOrientation(const std::string &folderName, std::vector<KeyParam> &keyparams); 44 static bool ParseDeviceType(const std::string &folderName, std::vector<KeyParam> &keyparams); 45 static bool ParseNightMode(const std::string &folderName, std::vector<KeyParam> &keyparams); 46 static bool ParseInputDevice(const std::string &folderName, std::vector<KeyParam> &keyparams); 47 static bool ParseResolution(const std::string &folderName, std::vector<KeyParam> &keyparams); 48 49 static void PushMccMnc(const std::string &folderName, KeyType type, std::vector<KeyParam> &keyparams); 50 static void PushLSR(const std::string &folderName, KeyType type, std::vector<KeyParam> &keyparams); 51 static void PushValue(uint32_t value, KeyType type, std::vector<KeyParam> &keyparams); 52 static const int32_t MCC_MNC_KEY_LENGHT = 3; 53 static const int32_t SCRIPT_LENGHT = 4; 54 static const int32_t MIN_REGION_LENGHT = 2; 55 static const int32_t MAX_REGION_LENGHT = 3; 56 static std::map<std::string, std::vector<KeyParam>> caches_; 57 }; 58 } 59 } 60 } 61 #endif 62