diff --git a/BUILD.gn b/BUILD.gn index b9b009b..10aa5b1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -49,7 +49,6 @@ ohos_executable("restool") { include_dirs = [ "include", - "//third_party/jsoncpp/include", "//third_party/bounds_checking_function/include", ] diff --git a/src/file_manager.cpp b/src/file_manager.cpp index d85b83a..c1faae5 100644 --- a/src/file_manager.cpp +++ b/src/file_manager.cpp @@ -72,20 +72,16 @@ uint32_t FileManager::ParseReference(const string &output) void FileManager::CheckAllItems(vector> &noBaseResource) { for (const auto &item : items_) { - bool flag = false; - for (const auto &iter : item.second) { - if (iter.GetLimitKey() == "base") { - flag = true; - break; - } - } - if (!flag) { + bool found = any_of(item.second.begin(), item.second.end(), [](const auto &iter) { + return iter.GetLimitKey() == "base"; + }); + if (!found) { auto firstItem = item.second.front(); - auto ret = find_if(noBaseResource.begin(), noBaseResource.end(), [firstItem](auto &iterItem) { + bool ret = any_of(noBaseResource.begin(), noBaseResource.end(), [firstItem](const auto &iterItem) { return (firstItem.GetResType() == iterItem.first) && (firstItem.GetName() == iterItem.second); }); - if (ret == noBaseResource.end()) { + if (!ret) { noBaseResource.push_back(make_pair(firstItem.GetResType(), firstItem.GetName())); } } diff --git a/src/resource_append.cpp b/src/resource_append.cpp index 25fd829..8c39226 100644 --- a/src/resource_append.cpp +++ b/src/resource_append.cpp @@ -679,20 +679,16 @@ bool ResourceAppend::IsBaseIdDefined(const FileInfo &fileInfo) void ResourceAppend::CheckAllItems(vector> &noBaseResource) { for (const auto &item : items_) { - bool flag = false; - for (const auto &iter : item.second) { - if (iter->GetLimitKey() == "base") { - flag = true; - break; - } - } - if (!flag) { + bool found = any_of(item.second.begin(), item.second.end(), [](const auto &iter) { + return iter->GetLimitKey() == "base"; + }); + if (!found) { auto firstItem = item.second.front(); - auto ret = find_if(noBaseResource.begin(), noBaseResource.end(), [firstItem](auto &iterItem) { + bool ret = any_of(noBaseResource.begin(), noBaseResource.end(), [firstItem](const auto &iterItem) { return (firstItem->GetResType() == iterItem.first) && (firstItem->GetName() == iterItem.second); }); - if (ret == noBaseResource.end()) { + if (!ret) { noBaseResource.push_back(make_pair(firstItem->GetResType(), firstItem->GetName())); } } diff --git a/src/resource_util.cpp b/src/resource_util.cpp index bb88d23..223e102 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -80,8 +80,8 @@ bool ResourceUtil::OpenJsonFile(const string &path, cJSON **root) string jsonString((istreambuf_iterator(ifs)), istreambuf_iterator()); *root = cJSON_Parse(jsonString.c_str()); - if (!root) { - cerr << "Error: cJSON_Parse failed." << NEW_LINE_PATH << path; + if (!*root) { + cerr << "Error: cJSON_Parse failed, please check the JSON file." << NEW_LINE_PATH << path; cerr << "\n" << cJSON_GetErrorPtr() << endl; ifs.close(); return false; diff --git a/src/translatable_parser.cpp b/src/translatable_parser.cpp index 8bf5cd4..aed9675 100755 --- a/src/translatable_parser.cpp +++ b/src/translatable_parser.cpp @@ -116,7 +116,7 @@ bool TranslatableParse::CheckBaseStringPriority(const cJSON *attrNode) string priorityValue = priorityNode->valuestring; if (find(PRIORITY_ATTRS.begin(), PRIORITY_ATTRS.end(), priorityValue) == PRIORITY_ATTRS.end()) { string message("[ "); - for (auto &value : PRIORITY_ATTRS) { + for (const auto &value : PRIORITY_ATTRS) { message.append("'" + value + "' "); } message.append("]"); @@ -148,11 +148,9 @@ bool TranslatableParse::GetReplaceStringTranslate(string &str) return false; } size_t startIndex = 0; - size_t endIndex = 0; string tmp; for (size_t index = 0; index < posData.size(); index++) { - endIndex = posData[index]; - tmp.append(str, startIndex, endIndex - startIndex); + tmp.append(str, startIndex, posData[index] - startIndex); startIndex = posData[++index]; } str = tmp.append(str, posData.back());