mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 17:24:42 -04:00
Merge branch 'master' of gitee.com:openharmony/developtools_global_resource_tool into master
Signed-off-by: 张婷 <zhangting201@huawei.com>
This commit is contained in:
@@ -32,7 +32,6 @@ public:
|
||||
std::vector<ResourceId> 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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user