mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-19 11:31:44 -04:00
@@ -57,6 +57,7 @@ private:
|
||||
bool ParseAttribute(const Json::Value &arrayItem, const ResourceItem &resourceItem,
|
||||
std::vector<std::string> &values) const;
|
||||
bool CheckPluralValue(const Json::Value &arrayItem, const ResourceItem &resourceItem) const;
|
||||
bool CheckColorValue(const char *s) const;
|
||||
std::map<ResType, HandleResource> handles_;
|
||||
static const std::string TAG_NAME;
|
||||
static const std::string TAG_VALUE;
|
||||
|
||||
@@ -298,6 +298,11 @@ bool JsonCompiler::CheckJsonStringValue(const Json::Value &valueNode, const Reso
|
||||
|
||||
string value = valueNode.asString();
|
||||
ResType type = resourceItem.GetResType();
|
||||
if (type == ResType::COLOR && !CheckColorValue(value.c_str())) {
|
||||
string error = "invaild color '" + value + "', in " + resourceItem.GetFilePath();
|
||||
cerr << "Error: " << error << endl;
|
||||
return false;
|
||||
}
|
||||
regex ref("^\\$.+:");
|
||||
smatch result;
|
||||
if (regex_search(value, result, ref) && !regex_match(result[0].str(), regex(REFS.at(type)))) {
|
||||
@@ -464,6 +469,19 @@ bool JsonCompiler::CheckPluralValue(const Json::Value &arrayItem, const Resource
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonCompiler::CheckColorValue(const char *s) const
|
||||
{
|
||||
if (s == nullptr) {
|
||||
return false;
|
||||
}
|
||||
// color regex
|
||||
string regColor = "^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$";
|
||||
if (regex_match(s, regex("^\\$.*")) || regex_match(s, regex(regColor))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +267,7 @@ string ResourceUtil::RealPath(const string &path)
|
||||
{
|
||||
return FileEntry::RealPath(path);
|
||||
}
|
||||
|
||||
bool ResourceUtil::IslegalPath(const string &path)
|
||||
{
|
||||
return path == "element" || path == "media" || path == "profile";
|
||||
|
||||
Reference in New Issue
Block a user