diff --git a/frameworks/resmgr_lite/include/res_common.h b/frameworks/resmgr_lite/include/res_common.h index 5cebb9a514e08b0c0ebf2ba4c734ba40e5b8d8a8..a3e93ffbee53c7a16a3dae968e657dca8a191835 100644 --- a/frameworks/resmgr_lite/include/res_common.h +++ b/frameworks/resmgr_lite/include/res_common.h @@ -16,8 +16,6 @@ #ifndef OHOS_RES_COMMON_H #define OHOS_RES_COMMON_H -#include - namespace OHOS { namespace Global { namespace Resource { diff --git a/frameworks/resmgr_lite/include/utils/date_utils.h b/frameworks/resmgr_lite/include/utils/date_utils.h index 555f50e9d3b1e2c0946e217f0430528ce7fb9c59..3937ca14586643af2398d1c462a231972d8a7e27 100644 --- a/frameworks/resmgr_lite/include/utils/date_utils.h +++ b/frameworks/resmgr_lite/include/utils/date_utils.h @@ -17,7 +17,6 @@ #define RESOURCE_MANAGER_DATEUTILS_H #include -#include #include "common.h" namespace OHOS { diff --git a/frameworks/resmgr_lite/src/hap_manager.cpp b/frameworks/resmgr_lite/src/hap_manager.cpp index b5f5e40b9a9aa7b84581139ad647ec36d6479d89..b387c0cd48a5edfafd293f574bc08b4e6398d6ee 100644 --- a/frameworks/resmgr_lite/src/hap_manager.cpp +++ b/frameworks/resmgr_lite/src/hap_manager.cpp @@ -133,16 +133,17 @@ const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueByName( for (i = 0; i < len; i++) { HapResource::ValueUnderQualifierDir *path = paths[i]; const ResConfigImpl *resConfig = path->GetResConfig(); - if (this->resConfig_->Match(resConfig)) { - if (bestResConfig == nullptr) { - bestIndex = i; - bestResConfig = resConfig; - } else if (bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { - continue; - } else { - bestResConfig = resConfig; - bestIndex = i; - } + if (!this->resConfig_->Match(resConfig)) { + continue; + } + if (bestResConfig == nullptr) { + bestIndex = i; + bestResConfig = resConfig; + continue; + } + if (!bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { + bestResConfig = resConfig; + bestIndex = i; } } return paths[bestIndex]; @@ -164,18 +165,17 @@ const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueById(ui for (i = 0; i < len; i++) { HapResource::ValueUnderQualifierDir *path = paths[i]; const ResConfigImpl *resConfig = path->GetResConfig(); - if (this->resConfig_->Match(resConfig)) { - if (bestResConfig == nullptr) { - bestIndex = i; - bestResConfig = resConfig; - } else { - if (bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { - continue; - } else { - bestResConfig = resConfig; - bestIndex = i; - } - } + if (!this->resConfig_->Match(resConfig)) { + continue; + } + if (bestResConfig == nullptr) { + bestIndex = i; + bestResConfig = resConfig; + continue; + } + if (!bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { + bestResConfig = resConfig; + bestIndex = i; } } return paths[bestIndex]; diff --git a/frameworks/resmgr_lite/src/locale_matcher.cpp b/frameworks/resmgr_lite/src/locale_matcher.cpp index 7ccac934819e7ce519adfae1f6b4a9de0db8a3ec..b54f05946ba9cf4e5e14939111a2a253541e3639 100644 --- a/frameworks/resmgr_lite/src/locale_matcher.cpp +++ b/frameworks/resmgr_lite/src/locale_matcher.cpp @@ -232,7 +232,7 @@ size_t ComputeTrackPathDistance(const uint64_t *requestPaths, } } } - return len * 2; + return len * 2; } int8_t CompareRegionWhenQaag(const ResLocale *current, @@ -269,6 +269,7 @@ bool CompareLanguage(const ResLocale *current, const ResLocale *other) Utils::EncodeLanguageByResLocale(current); uint16_t otherEncodedLanguage = Utils::EncodeLanguageByResLocale( other); + // 0-4 NEW/OLD language code means iw/he,tl/fil,ji/yi,jw/jv,in/id return ((currentEncodedLanguage == otherEncodedLanguage) || ((currentEncodedLanguage == NEW_LANGUAGES_CODES[0]) && (otherEncodedLanguage == OLD_LANGUAGES_CODES[0])) || @@ -687,9 +688,11 @@ bool LocaleMatcher::IsRegionTag(const char *str, int32_t len) if (len < 0) { len = strlen(str); } + // region is 2 letters if is alpha string if (len == 2 && Utils::IsAlphaString(str, len)) { return true; } + // region is 3 letters if is numeric string if (len == 3 && Utils::IsNumericString(str, len)) { return true; } diff --git a/frameworks/resmgr_lite/src/res_desc.cpp b/frameworks/resmgr_lite/src/res_desc.cpp index d143db0e6ead64846a9d6ea89fec76a858c06ded..81c7b1b88ac3af7874229f6dc981cb997a2d7070 100644 --- a/frameworks/resmgr_lite/src/res_desc.cpp +++ b/frameworks/resmgr_lite/src/res_desc.cpp @@ -13,9 +13,6 @@ * limitations under the License. */ #include "res_desc.h" - -#include - #include "hilog_wrapper.h" #include "securec.h" #include "utils/common.h" @@ -91,7 +88,9 @@ const std::string KeyParam::ConvertToStr() const HILOG_ERROR("memcpy_s error : %d", eret); } int j = 0; + // 4 means langauages/region/script key value max length for (int i = 0; i < 4; ++i) { + // 3 means reverse temp value to temp2 if (tmp[3 - i]) { tmp2[j++] = tmp[3 - i]; } @@ -145,6 +144,8 @@ bool IdItem::HaveParent() const if (!(resType_ == THEME || resType_ == PATTERN)) { return false; } + // the values_ storage map(key, value) and parent ref + // if have parent, size would be odd number return (values_.size() % 2 == 1); } @@ -156,6 +157,7 @@ bool IdItem::IsRef(const std::string &value, ResType &resType, int &id) return false; } auto index = value.find(":"); + // there are atleast one letter between '$' and ':' if (index == std::string::npos || index < 2) { return false; } diff --git a/frameworks/resmgr_lite/src/resource_manager_impl.cpp b/frameworks/resmgr_lite/src/resource_manager_impl.cpp index b2c466597b76d61f345d64fa5b2f5ab3eec2a043..65c55928ed70bed856e54acac4e92cec2b962a21 100644 --- a/frameworks/resmgr_lite/src/resource_manager_impl.cpp +++ b/frameworks/resmgr_lite/src/resource_manager_impl.cpp @@ -240,6 +240,7 @@ RState ResourceManagerImpl::GetPluralString(const HapResource::ValueUnderQualifi size_t startIdx = 0; size_t loop = idItem->values_.size() / 2; for (size_t i = 0; i < loop; ++i) { + // 2 means key and value appear in pairs std::string key(idItem->values_[startIdx + i * 2]); std::string value(idItem->values_[startIdx + i * 2 + 1]); auto iter = map.find(key); @@ -331,18 +332,20 @@ RState ResourceManagerImpl::ResolveParentReference(const IdItem *idItem, std::ma // this make sure child covers parent size_t loop = currItem->values_.size() / 2; for (size_t i = 0; i < loop; ++i) { + // 2 means key and value appear in pairs std::string key(currItem->values_[startIdx + i * 2]); std::string value(currItem->values_[startIdx + i * 2 + 1]); auto iter = outValue.find(key); - if (iter == outValue.end()) { - std::string resolvedValue; - RState rrRet = ResolveReference(value, resolvedValue); - if (rrRet != SUCCESS) { - HILOG_ERROR("ResolveReference failed, value:%s", value.c_str()); - return ERROR; - } - outValue[key] = resolvedValue; + if (iter != outValue.end()) { + continue; } + std::string resolvedValue; + RState rrRet = ResolveReference(value, resolvedValue); + if (rrRet != SUCCESS) { + HILOG_ERROR("ResolveReference failed, value:%s", value.c_str()); + return ERROR; + } + outValue[key] = resolvedValue; } if (haveParent) { // get parent diff --git a/frameworks/resmgr_lite/src/utils/utils.cpp b/frameworks/resmgr_lite/src/utils/utils.cpp index f636f8dccb158e347d3a892a2c05fb93bad04d8f..490eec9620be25ba976d6615a61dff969e51ab42 100644 --- a/frameworks/resmgr_lite/src/utils/utils.cpp +++ b/frameworks/resmgr_lite/src/utils/utils.cpp @@ -197,40 +197,33 @@ uint16_t Utils::EncodeLanguageOrRegion(const char *str, char base) bool Utils::StrCompare(const char *left, const char *right, size_t len, bool isCaseSensitive) { - if (left == nullptr) { - if (right == nullptr) { + if (left == nullptr && right == nullptr) { + return true; + } + if (left == nullptr || right == nullptr) { + return false; + } + int rc; + unsigned char c1, c2; + while (len--) { + c1 = (unsigned char)*left; + c2 = (unsigned char)*right; + if (c1 == 0 && c2 == 0) { return true; - } else { + } + if (c1 == 0 || c2 == 0) { return false; } - } else if (right == nullptr) { - return false; - } else { - int rc; - unsigned char c1, c2; - while (len--) { - c1 = (unsigned char)*left; - c2 = (unsigned char)*right; - if (c1 == 0) { - if (c2 == 0) { - return true; - } - return false; - } else if (c2 == 0) { - return false; - } else { - if (isCaseSensitive) { - rc = (int)(c1) - (int)(c2); - } else { - rc = tolower(c1) - tolower(c2); - } - if (rc != 0) { - return false; - } - } - ++left; - ++right; + if (isCaseSensitive) { + rc = (int)(c1) - (int)(c2); + } else { + rc = tolower(c1) - tolower(c2); + } + if (rc != 0) { + return false; } + ++left; + ++right; } return true; } @@ -274,7 +267,7 @@ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue) RState parseState = SUCCESS; size_t len = strlen(s); if (*s == '#') { - if (len == 4) { + if (len == 4) { // 4 means #rgb color |= 0xFF000000; color |= ParseHex(s[1], parseState) << 20; color |= ParseHex(s[1], parseState) << 16; @@ -282,7 +275,7 @@ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue) color |= ParseHex(s[2], parseState) << 8; color |= ParseHex(s[3], parseState) << 4; color |= ParseHex(s[3], parseState); - } else if (len == 5) { + } else if (len == 5) { // 5 means #argb color |= ParseHex(s[1], parseState) << 28; color |= ParseHex(s[1], parseState) << 24; color |= ParseHex(s[2], parseState) << 20; @@ -291,7 +284,7 @@ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue) color |= ParseHex(s[3], parseState) << 8; color |= ParseHex(s[4], parseState) << 4; color |= ParseHex(s[4], parseState); - } else if (len == 7) { + } else if (len == 7) { // 7 means #rrggbb color |= 0xFF000000; color |= ParseHex(s[1], parseState) << 20; color |= ParseHex(s[2], parseState) << 16; @@ -299,7 +292,7 @@ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue) color |= ParseHex(s[4], parseState) << 8; color |= ParseHex(s[5], parseState) << 4; color |= ParseHex(s[6], parseState); - } else if (len == 9) { + } else if (len == 9) { // 9 means #aarrggbb color |= ParseHex(s[1], parseState) << 28; color |= ParseHex(s[2], parseState) << 24; color |= ParseHex(s[3], parseState) << 20;