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_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; +} + } } }