diff --git a/include/json_compiler.h b/include/json_compiler.h index 7760268..f24891c 100644 --- a/include/json_compiler.h +++ b/include/json_compiler.h @@ -45,10 +45,12 @@ private: bool HandleTheme(const Json::Value &objectNode, ResourceItem &resourceItem) const; bool HandlePattern(const Json::Value &objectNode, ResourceItem &resourceItem) const; bool HandlePlural(const Json::Value &objectNode, ResourceItem &resourceItem) const; + bool HandleSymbol(const Json::Value &objectNode, ResourceItem &resourceItem) const; bool PushString(const std::string &value, ResourceItem &resourceItem) const; bool CheckJsonStringValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const; bool CheckJsonIntegerValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const; + bool CheckJsonSymbolValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const; using HandleValue = std::function&)>; bool ParseValueArray(const Json::Value &objectNode, ResourceItem &resourceItem, const std::vector &extra, HandleValue callback) const; diff --git a/include/resource_data.h b/include/resource_data.h index b22511d..7926605 100644 --- a/include/resource_data.h +++ b/include/resource_data.h @@ -39,7 +39,7 @@ 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 4.102" }; +static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 4.103" }; const static int32_t TAG_LEN = 4; enum class KeyType { @@ -73,6 +73,7 @@ enum class ResType { MEDIA = 19, PROF = 20, PATTERN = 22, + SYMBOL = 23, INVALID_RES_TYPE = -1, }; @@ -192,7 +193,8 @@ const std::map g_contentClusterMap = { { "boolean", ResType::BOOLEAN }, { "pattern", ResType::PATTERN }, { "theme", ResType::THEME }, - { "float", ResType::FLOAT } + { "float", ResType::FLOAT }, + { "symbol", ResType::SYMBOL } }; const std::map g_resTypeMap = { @@ -211,6 +213,7 @@ const std::map g_resTypeMap = { { static_cast(ResType::MEDIA), ResType::MEDIA}, { static_cast(ResType::PROF), ResType::PROF}, { static_cast(ResType::PATTERN), ResType::PATTERN}, + { static_cast(ResType::SYMBOL), ResType::SYMBOL}, { static_cast(ResType::INVALID_RES_TYPE), ResType::INVALID_RES_TYPE}, }; diff --git a/include/resource_util.h b/include/resource_util.h index 63bbc11..31d9cef 100644 --- a/include/resource_util.h +++ b/include/resource_util.h @@ -209,6 +209,13 @@ public: */ static uint32_t GetNormalSize(const std::vector &keyParams, uint32_t index); + /** + * @brief Check if the Unicode code belongs to the 15 plane or 16 plane + * @param int unicode + * @return ture Unicode code belongs to the 15 plane or 16 plane, other false; + */ + static bool isUnicodeInPlane15or16(int unicode); + private: enum class IgnoreType { IGNORE_FILE, diff --git a/src/json_compiler.cpp b/src/json_compiler.cpp index f435bb6..24691c7 100644 --- a/src/json_compiler.cpp +++ b/src/json_compiler.cpp @@ -90,6 +90,7 @@ void JsonCompiler::InitParser() handles_.emplace(ResType::THEME, bind(&JsonCompiler::HandleTheme, this, _1, _2)); handles_.emplace(ResType::PATTERN, bind(&JsonCompiler::HandlePattern, this, _1, _2)); handles_.emplace(ResType::PLURAL, bind(&JsonCompiler::HandlePlural, this, _1, _2)); + handles_.emplace(ResType::SYMBOL, bind(&JsonCompiler::HandleSymbol, this, _1, _2)); } bool JsonCompiler::ParseJsonArrayLevel(const Json::Value &arrayNode, const FileInfo &fileInfo) @@ -273,6 +274,15 @@ bool JsonCompiler::HandlePlural(const Json::Value &objectNode, ResourceItem &res return true; } +bool JsonCompiler::HandleSymbol(const Json::Value &objectNode, ResourceItem &resourceItem) const +{ + Json::Value valueNode = objectNode[TAG_VALUE]; + if (!CheckJsonSymbolValue(valueNode, resourceItem)) { + return false; + } + return PushString(valueNode.asString(), resourceItem); +} + bool JsonCompiler::PushString(const string &value, ResourceItem &resourceItem) const { if (!resourceItem.SetData(reinterpret_cast(value.c_str()), value.length())) { @@ -333,6 +343,26 @@ bool JsonCompiler::CheckJsonIntegerValue(const Json::Value &valueNode, const Res return true; } +bool JsonCompiler::CheckJsonSymbolValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const +{ + if (!valueNode.isString()) { + cerr << "Error: '" << resourceItem.GetName() << "' value not string."; + cerr << NEW_LINE_PATH << resourceItem.GetFilePath() << endl; + return false; + } + string unicodeStr = valueNode.asString(); + if (regex_match(unicodeStr, regex("^\\$(ohos:)?symbol:.*"))) { + return true; + } + int unicode = strtol(unicodeStr.c_str(), nullptr, 16); + if (!ResourceUtil::isUnicodeInPlane15or16(unicode)) { + cerr << "Error: '" << resourceItem.GetName() << "' value must in 0xF0000 ~ 0xFFFFF or 0x100000 ~ 0x10FFFF."; + cerr << NEW_LINE_PATH << resourceItem.GetFilePath() << endl; + return false; + } + return true; +} + bool JsonCompiler::ParseValueArray(const Json::Value &objectNode, ResourceItem &resourceItem, const vector &extra, HandleValue callback) const { diff --git a/src/reference_parser.cpp b/src/reference_parser.cpp index 6194099..02d9b5b 100644 --- a/src/reference_parser.cpp +++ b/src/reference_parser.cpp @@ -34,7 +34,8 @@ const map ReferenceParser::ID_REFS = { { "^\\$string:", ResType::STRING }, { "^\\$pattern:", ResType::PATTERN }, { "^\\$plural:", ResType::PLURAL }, - { "^\\$theme:", ResType::THEME } + { "^\\$theme:", ResType::THEME }, + { "^\\$symbol:", ResType::SYMBOL } }; const map ReferenceParser::ID_OHOS_REFS = { @@ -48,7 +49,8 @@ const map ReferenceParser::ID_OHOS_REFS = { { "^\\$ohos:string:", ResType::STRING }, { "^\\$ohos:pattern:", ResType::PATTERN }, { "^\\$ohos:plural:", ResType::PLURAL }, - { "^\\$ohos:theme:", ResType::THEME } + { "^\\$ohos:theme:", ResType::THEME }, + { "^\\$ohos:symbol:", ResType::SYMBOL } }; ReferenceParser::ReferenceParser() : idWorker_(IdWorker::GetInstance()) @@ -197,7 +199,8 @@ bool ReferenceParser::IsStringOfResourceItem(ResType resType) const resType == ResType::INTEGER || resType == ResType::BOOLEAN || resType == ResType::COLOR || - resType == ResType::FLOAT) { + resType == ResType::FLOAT || + resType == ResType::SYMBOL) { return true; } return false; diff --git a/src/resource_util.cpp b/src/resource_util.cpp index 5b8eb4d..802a9f9 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -423,6 +423,11 @@ uint32_t ResourceUtil::GetNormalSize(const vector &keyParams, uint32_t return g_normalIconMap.find(dpi + "-" + device)->second[index]; } +bool ResourceUtil::isUnicodeInPlane15or16(int unicode) +{ + return (unicode >= 0xF0000 && unicode <= 0xFFFFF) || (unicode >= 0x100000 && unicode <= 0x10FFFF); +} + } } }