• 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 
16 #ifndef OHOS_RESTOOL_REFERENCE_PARSER_H
17 #define OHOS_RESTOOL_REFERENCE_PARSER_H
18 
19 #include "id_worker.h"
20 #include "resource_item.h"
21 
22 namespace OHOS {
23 namespace Global {
24 namespace Restool {
25 class ReferenceParser {
26 public:
27     ReferenceParser();
28     virtual ~ReferenceParser();
29     uint32_t ParseRefInResources(std::map<int32_t, std::vector<ResourceItem>> &items, const std::string &output);
30     uint32_t ParseRefInResourceItem(ResourceItem &resourceItem) const;
31     uint32_t ParseRefInJsonFile(ResourceItem &resourceItem, const std::string &output, const bool isIncrement = false);
32     uint32_t ParseRefInString(std::string &value, bool &update) const;
33 private:
34     bool ParseRefJson(const std::string &from, const std::string &to) const;
35     bool ParseRefResourceItemData(const ResourceItem &resourceItem, std::string &data, bool &update) const;
36     bool IsStringOfResourceItem(ResType resType) const;
37     bool IsArrayOfResourceItem(ResType resType) const;
38     bool IsElementRef(const ResourceItem &resourceItem) const;
39     bool IsMediaRef(const ResourceItem &resourceItem) const;
40     bool IsProfileRef(const ResourceItem &resourceItem) const;
41     bool ParseRefString(std::string &key) const;
42     bool ParseRefString(std::string &key, bool &update) const;
43     bool ParseRefImpl(std::string &key, const std::map<std::string, ResType> &refs, bool isSystem) const;
44     bool ParseRefJsonImpl(Json::Value &root, bool &needSave) const;
45     const IdWorker &idWorker_;
46     static const std::map<std::string, ResType> ID_REFS;
47     static const std::map<std::string, ResType> ID_OHOS_REFS;
48 };
49 }
50 }
51 }
52 #endif