消除代码差别

Signed-off-by: 王剑 <wangjian497@huawei.com>
This commit is contained in:
王剑 2023-08-23 09:25:46 +00:00
parent d887b9fc7a
commit a13bab1f0b
16 changed files with 60 additions and 56 deletions

View File

@ -113,7 +113,8 @@ public:
private:
void SortLocaleItemList(std::vector<LocaleItem> &localeItemList, const SortOptions &options);
static void SortTimezoneCityItemList(const std::string &locale, std::vector<TimeZoneCityItem> &timezoneCityItemList);
static void SortTimezoneCityItemList(const std::string &locale,
std::vector<TimeZoneCityItem> &timezoneCityItemList);
std::unique_ptr<TabooUtils> tabooUtils;
static const char* SIM_COUNTRY_CODE_KEY;
static constexpr int CONFIG_LEN = 128;

View File

@ -15,8 +15,8 @@
#include "holiday_manager.h"
#include "hilog/log.h"
#include <algorithm>
#include <climits>
#include <ctime>
#include <limits.h>
#include <filesystem>
#include <format>
#include <fstream>
@ -65,7 +65,6 @@ HolidayManager::HolidayManager(const char* path)
HolidayManager::~HolidayManager()
{
}
void HolidayManager::SetHolidayData(std::map<std::string, std::vector<HolidayInfoItem>> holidayDataMap)
@ -96,7 +95,9 @@ std::string HolidayManager::Format(int32_t year, int32_t month, int32_t day)
{
std::string formated;
formated += std::to_string(year);
// Numbers less than 10 are one digit
formated += month < 10 ? ("0" + std::to_string(month)) : std::to_string(month);
// Numbers less than 10 are one digit
formated += day < 10 ? ("0" + std::to_string(day)) : std::to_string(day);
return formated;
}
@ -152,15 +153,16 @@ std::vector<HolidayInfoItem> HolidayManager::ReadHolidayFile(const char* path)
std::vector<HolidayInfoItem> items;
while (getline(fin, line)) {
line = Trim(line);
if (line.compare(ITEM_BEGIN_TAG) == 0) {
struct HolidayInfoItem holidayItem;
while (getline(fin, line)) {
line = Trim(line);
ParseFileLine(line, &(holidayItem));
if (line.compare(ITEM_END_TAG) == 0) {
items.push_back(holidayItem);
break;
}
if (line.compare(ITEM_BEGIN_TAG) != 0) {
continue;
}
struct HolidayInfoItem holidayItem;
while (getline(fin, line)) {
line = Trim(line);
ParseFileLine(line, &(holidayItem));
if (line.compare(ITEM_END_TAG) == 0) {
items.push_back(holidayItem);
break;
}
}
}

View File

@ -203,7 +203,7 @@ bool LocaleCompare::IsSameEnglishScript(const std::string& scriptTag1, const std
}
bool LocaleCompare::HasMapRelation(const std::string& languageTag, const std::string& localeTag1,
const std::string& localeTag2)
const std::string& localeTag2)
{
if (scriptLocales.find(languageTag) == scriptLocales.end()) {
return false;

View File

@ -117,6 +117,7 @@ void NumberFormat::InitProperties()
}
}
if (!styleString.empty() && styleString == "percent") {
// 2 is the power of ten
numberFormat = numberFormat.unit(icu::NoUnit::percent()).scale(icu::number::Scale::powerOfTen(2)).precision(
icu::number::Precision::fixedFraction(0));
}

View File

@ -47,7 +47,7 @@ SystemLocaleManager::~SystemLocaleManager()
* 4. Sort the languages use locale displayName, local displyName and suggestion infomation.
*/
std::vector<LocaleItem> SystemLocaleManager::GetLanguageInfoArray(const std::vector<std::string> &languages,
const SortOptions &options)
const SortOptions &options)
{
std::unordered_set<std::string> blockedLanguages = LocaleConfig::GetBlockedLanguages();
std::vector<LocaleItem> localeItemList;

View File

@ -13,9 +13,9 @@
* limitations under the License.
*/
#include <cstring>
#include <filesystem>
#include <sys/stat.h>
#include <string.h>
#include "hilog/log.h"
#include "libxml/globals.h"
#include "libxml/tree.h"
@ -252,12 +252,12 @@ void Taboo::ReadResourceList()
std::string Taboo::GetLanguageFromFileName(const std::string& fileName)
{
if (fileName.length() == 3) {
if (fileName.length() == 3) { // 3 is the length of file 'xml'
return "en";
}
std::string language = fileName.substr(4);
if (language[0] == 'b' && language[1] == '+') {
language = language.substr(2);
language = language.substr(2); // 2 is the length of "b+"
}
size_t pos = language.find("+");
if (pos != std::string::npos) {
@ -265,7 +265,7 @@ std::string Taboo::GetLanguageFromFileName(const std::string& fileName)
}
pos = language.find("-r");
if (pos != std::string::npos) {
language = language.replace(pos, 2, "-");
language = language.replace(pos, 2, "-"); // 2 is the length of "-r"
}
return language;
}

View File

@ -17,9 +17,15 @@
#include <map>
#include <vector>
#include "collator.h"
#include "character.h"
#include "collator.h"
#include "date_time_format.h"
#include "holiday_manager.h"
#include "i18n_break_iterator.h"
#include "i18n_calendar.h"
#include "i18n_timezone.h"
#include "i18n_types.h"
#include "index_util.h"
#include "locale_compare.h"
#include "locale_config.h"
#include "locale_info.h"
@ -29,17 +35,10 @@
#include "plural_rules.h"
#include "preferred_language.h"
#include "relative_time_format.h"
#include "utils.h"
#include "i18n_break_iterator.h"
#include "i18n_calendar.h"
#include "i18n_timezone.h"
#include "i18n_types.h"
#include "index_util.h"
#include "intl_test.h"
#include "system_locale_manager.h"
#include "taboo_utils.h"
#include "utils.h"
#include "holiday_manager.h"
#include "intl_test.h"
using namespace OHOS::Global::I18n;
using testing::ext::TestSize;
@ -607,7 +606,6 @@ HWTEST_F(IntlTest, IntlFuncTest0017, TestSize.Level1)
const string param2 = "";
CompareResult result = collator->Compare(param1, param2);
EXPECT_EQ(result, CompareResult::SMALLER);
map<string, string> options;
collator->ResolvedOptions(options);
EXPECT_EQ(options.size(), 8);
@ -1878,11 +1876,11 @@ HWTEST_F(IntlTest, IntlFuncTest0046, TestSize.Level1)
EXPECT_TRUE(Urumqi.size() == 2);
bool containsShanghai = false;
bool containsUrumqi = false;
for(unsigned int i = 0; i < Urumqi.size(); i++){
if(Urumqi[i] == "Asia/Shanghai"){
for (unsigned int i = 0; i < Urumqi.size(); i++) {
if (Urumqi[i] == "Asia/Shanghai") {
containsShanghai = true;
}
if(Urumqi[i] == "Asia/Urumqi"){
if (Urumqi[i] == "Asia/Urumqi") {
containsUrumqi = true;
}
}
@ -2016,7 +2014,7 @@ HWTEST_F(IntlTest, IntlFuncTest0052, TestSize.Level1)
delete indexUtil;
delete indexUtil2;
IndexUtil indexUtil3("");
IndexUtil indexUtil3("");
indexUtil3.AddLocale("en-US");
indexStr = indexUtil3.GetIndex("A");
EXPECT_EQ(indexStr, "A");

View File

@ -233,13 +233,13 @@ bool ZoneUtil::Init()
CountryResult ZoneUtil::LookupTimezoneByCountryAndNITZ(std::string &region, NITZData &nitzData)
{
std::vector<std::string> zones;
bool isBoosted = false;
std::string defaultTimezone;
std::string systemTimezone = ReadSystemParameter(TIMEZONE_KEY, SYS_PARAM_LEN);
if (systemTimezone.length() == 0) {
systemTimezone = DEFAULT_TIMEZONE;
}
if (CheckFileExist()) {
bool isBoosted = false;
HiLog::Info(LABEL, "ZoneUtil::LookupTimezoneByCountryAndNITZ use tzlookup.xml");
GetCountryZones(region, defaultTimezone, isBoosted, zones);
} else {

View File

@ -273,7 +273,7 @@ HWTEST_F(ZoneUtilTest, ZoneUtilFuncTest011, TestSize.Level1)
region = "AR";
CountryResult result3 = util.LookupTimezoneByCountry(region, currentMillis);
EXPECT_EQ(result3.timezoneId, "America/Argentina/Buenos_Aires");
EXPECT_TRUE(result3.quality == 0 || result3.quality == 2);
EXPECT_TRUE(result3.quality == 0 || result3.quality == 2);
region = "AM";
CountryResult result4 = util.LookupTimezoneByCountry(region, currentMillis);

View File

@ -77,7 +77,6 @@ private:
static napi_value SetUsingLocalDigitAddonImpl(napi_env env, napi_callback_info info, bool throwError);
static bool ParseStringParam(napi_env env, napi_value argv, bool throwError, std::string &strParam);
};
} // namespace I18n
} // namespace Global

View File

@ -153,7 +153,8 @@ napi_value HolidayManagerAddon::IsHoliday(napi_env env, napi_callback_info info)
bool res = false;
if (flag) {
std::vector<int> list = ValidateParamDate(env, argv[0]);
if (list.size() == 3) {
if (list.size() == 3) { // 3 is the number of parameters
// 0, 1, and 2 indicate that the first, second, and third parameters of the list are read
res = obj->holidayManager_->IsHoliday(list.at(0), list.at(1), list.at(2));
}
} else {
@ -288,7 +289,8 @@ napi_value HolidayManagerAddon::CreateHolidayItem(napi_env env, const HolidayInf
HiLog::Error(LABEL, "Create Holiday Item object failed.");
return nullptr;
}
status = napi_set_named_property(env, result, "baseName", VariableConvertor::CreateString(env, holidayItem.baseName));
status = napi_set_named_property(env, result, "baseName",
VariableConvertor::CreateString(env, holidayItem.baseName));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element baseName.");
return nullptr;
@ -305,8 +307,8 @@ napi_value HolidayManagerAddon::CreateHolidayItem(napi_env env, const HolidayInf
HiLog::Error(LABEL, "Failed to set element month.");
return nullptr;
}
status = napi_set_named_property(env, result, "day",
VariableConvertor::CreateNumber(env, holidayItem.day));
status = napi_set_named_property(env, result, "day",
VariableConvertor::CreateNumber(env, holidayItem.day));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element day.");
return nullptr;
@ -337,18 +339,18 @@ napi_value HolidayManagerAddon::HolidayLocaleNameItem(napi_env env, const std::v
HiLog::Error(LABEL, "Create HolidayLocaleName Item object failed.");
return nullptr;
}
status = napi_set_named_property(env, localNameItem, "language",
VariableConvertor::CreateString(env, localNames[i].language));
status = napi_set_named_property(env, localNameItem, "language",
VariableConvertor::CreateString(env, localNames[i].language));
if (status != napi_ok) {
HiLog::Error(LABEL, "Create HolidayLocaleName.language Item object failed.");
return nullptr;
}
status = napi_set_named_property(env, localNameItem, "name",
VariableConvertor::CreateString(env, localNames[i].name));
}
status = napi_set_named_property(env, localNameItem, "name",
VariableConvertor::CreateString(env, localNames[i].name));
if (status != napi_ok) {
HiLog::Error(LABEL, "Create HolidayLocaleName.name Item object failed.");
return nullptr;
}
}
status = napi_set_element(env, result, i, localNameItem);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set HolidayLocaleName element.");

View File

@ -15,22 +15,21 @@
#include <unordered_map>
#include <vector>
#include "error_util.h"
#include "hilog/log.h"
#include "holiday_manager_addon.h"
#include "i18n_calendar_addon.h"
#include "i18n_normalizer_addon.h"
#include "i18n_system_addon.h"
#include "i18n_timezone_addon.h"
#include "i18n_unicode_addon.h"
#include "node_api.h"
#include "system_locale_manager_addon.h"
#include "holiday_manager_addon.h"
#include "unicode/locid.h"
#include "unicode/datefmt.h"
#include "unicode/locid.h"
#include "unicode/smpdtfmt.h"
#include "unicode/translit.h"
#include "node_api.h"
#include "variable_convertor.h"
#include "error_util.h"
#include "i18n_addon.h"
namespace OHOS {
@ -386,7 +385,8 @@ bool I18nAddon::IsValidLocaleTag(icu::Locale &locale)
return true;
}
void I18nAddon::GetAllValidLocalesTag() {
void I18nAddon::GetAllValidLocalesTag()
{
static bool init = false;
if (init) {
return;

View File

@ -34,7 +34,7 @@ const char *I18nNormalizerAddon::NORMALIZER_MODE_NFKD_NAME = "NFKD";
I18nNormalizerAddon::I18nNormalizerAddon() {}
I18nNormalizerAddon::~I18nNormalizerAddon()
{
{
}
void I18nNormalizerAddon::Destructor(napi_env env, void *nativeObject, void *hint)

View File

@ -76,8 +76,8 @@ napi_value SystemLocaleManagerAddon::SystemLocaleManagerConstructor(napi_env env
return nullptr;
}
std::unique_ptr<SystemLocaleManagerAddon> obj = std::make_unique<SystemLocaleManagerAddon>();
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), SystemLocaleManagerAddon::Destructor, nullptr, nullptr);
status = napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), SystemLocaleManagerAddon::Destructor,
nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "Wrap SystemLocaleManagerAddon failed");
return nullptr;

View File

@ -63,7 +63,8 @@ void VariableConvertor::GetOptionValue(napi_env env, napi_value options, const s
}
}
bool VariableConvertor::GetBoolOptionValue(napi_env env, napi_value &options, const std::string &optionName, bool &boolVal)
bool VariableConvertor::GetBoolOptionValue(napi_env env, napi_value &options, const std::string &optionName,
bool &boolVal)
{
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, options, &type);

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python
# coding=utf-8
# coding=utf-8
"""
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");