From 547d1d4c05afde17f479f3ebfe7b96f87fb51276 Mon Sep 17 00:00:00 2001 From: fangyunzhong Date: Mon, 26 Feb 2024 10:46:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=B5=84=E6=BA=90=E5=8E=BB?= =?UTF-8?q?=E9=99=A4OHOS=E5=89=8D=E7=BC=80=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangyunzhong --- include/id_worker.h | 1 - include/resource_data.h | 3 +-- include/resource_util.h | 13 +++++++------ src/i_resource_compiler.cpp | 2 +- src/id_defined_parser.cpp | 2 +- src/id_worker.cpp | 12 ------------ src/resource_util.cpp | 18 +++++++++--------- 7 files changed, 19 insertions(+), 32 deletions(-) diff --git a/include/id_worker.h b/include/id_worker.h index b7705fd..fcaac91 100644 --- a/include/id_worker.h +++ b/include/id_worker.h @@ -32,7 +32,6 @@ public: std::vector GetHeaderId() const; int32_t GetId(ResType resType, const std::string &name) const; int32_t GetSystemId(ResType resType, const std::string &name) const; - bool IsValidName(const std::string &name) const; bool PushCache(ResType resType, const std::string &name, int32_t id); void PushDelId(int32_t id); diff --git a/include/resource_data.h b/include/resource_data.h index 7c3319a..4113625 100644 --- a/include/resource_data.h +++ b/include/resource_data.h @@ -37,10 +37,9 @@ const static std::string SEPARATOR = "/"; const static std::string WIN_SEPARATOR = "\\"; const static std::string NEW_LINE_PATH = "\nat "; const static std::string LONG_PATH_HEAD = "\\\\?\\"; -const static std::string ID_DEFINED_INDENTATION = " "; const static int32_t VERSION_MAX_LEN = 128; const static int32_t INT_TO_BYTES = sizeof(uint32_t); -static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.000" }; +static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.001" }; const static int32_t TAG_LEN = 4; enum class KeyType { diff --git a/include/resource_util.h b/include/resource_util.h index 666d9c1..59497a4 100644 --- a/include/resource_util.h +++ b/include/resource_util.h @@ -222,17 +222,18 @@ public: */ static void RemoveSpaces(std::string &str); - /** - * @brief Check whether the system resource name is valid - * @param str system resource name - */ - static bool IsValidSystemName(const std::string &name); - /** * @brief Check whether the value is int * @param snode cJSON node */ static bool IsIntValue(const cJSON *node); + + /** + * @brief Check whether the resource name is valid + * @param str resource name + */ + static bool IsValidName(const std::string &name); + private: enum class IgnoreType { IGNORE_FILE, diff --git a/src/i_resource_compiler.cpp b/src/i_resource_compiler.cpp index cab2f7c..ad89d9e 100644 --- a/src/i_resource_compiler.cpp +++ b/src/i_resource_compiler.cpp @@ -124,7 +124,7 @@ uint32_t IResourceCompiler::PostCommit() bool IResourceCompiler::MergeResourceItem(const ResourceItem &resourceItem) { string idName = ResourceUtil::GetIdName(resourceItem.GetName(), resourceItem.GetResType()); - if (!IdWorker::GetInstance().IsValidName(idName)) { + if (!ResourceUtil::IsValidName(idName)) { cerr << "Error: invalid idName '" << idName << "'."<< NEW_LINE_PATH << resourceItem.GetFilePath() << endl; return false; } diff --git a/src/id_defined_parser.cpp b/src/id_defined_parser.cpp index 9ae5cd5..129cd4c 100755 --- a/src/id_defined_parser.cpp +++ b/src/id_defined_parser.cpp @@ -231,7 +231,7 @@ bool IdDefinedParser::ParseName(const cJSON *name, ResourceId &resourceId) } resourceId.name = name->valuestring; if (type_ == ResourceIdCluster::RES_ID_SYS && - (resourceId.id & START_SYS_ID) == START_SYS_ID && !ResourceUtil::IsValidSystemName(resourceId.name)) { + (resourceId.id & START_SYS_ID) == START_SYS_ID && !ResourceUtil::IsValidName(resourceId.name)) { cerr << "Error: id_defined.json."<< endl; return false; } diff --git a/src/id_worker.cpp b/src/id_worker.cpp index 0bd259d..fe49190 100644 --- a/src/id_worker.cpp +++ b/src/id_worker.cpp @@ -84,18 +84,6 @@ int32_t IdWorker::GetSystemId(ResType resType, const string &name) const return result->second.id; } -bool IdWorker::IsValidName(const string &name) const -{ - if (!regex_match(name, regex("[a-zA-z0-9_]+"))) { - cerr << "Error: '" << name << "' only contain [a-zA-z0-9_]." << endl; - return false; - } - if (type_ != ResourceIdCluster::RES_ID_SYS) { - return true; - } - return ResourceUtil::IsValidSystemName(name); -} - bool IdWorker::PushCache(ResType resType, const string &name, int32_t id) { auto result = cacheIds_.emplace(make_pair(resType, name), id); diff --git a/src/resource_util.cpp b/src/resource_util.cpp index 7e10039..d6a9fab 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -431,15 +431,6 @@ void ResourceUtil::RemoveSpaces(string &str) str.erase(str.find_last_not_of(" ") + 1); // move back one place } -bool ResourceUtil::IsValidSystemName(const string &name) -{ - if (regex_match(name, regex("^ohos.+"))) { - return true; - } - cerr << "Error: '" << name << "' must start with 'ohos'" << endl; - return false; -} - bool ResourceUtil::IsIntValue(const cJSON *node) { if (node && cJSON_IsNumber(node)) { @@ -453,6 +444,15 @@ bool ResourceUtil::IsIntValue(const cJSON *node) return false; } +bool ResourceUtil::IsValidName(const string &name) +{ + if (!regex_match(name, regex("[a-zA-Z0-9_]+"))) { + cerr << "Error: '" << name << "' only contain [a-zA-Z0-9_]." << endl; + return false; + } + return true; +} + } } }