diff --git a/frameworks/intl/include/i18n_break_iterator.h b/frameworks/intl/include/i18n_break_iterator.h index d1409c83678caffa118766d8834216d088384dcc..b937f9770b1c148cab30672271fa2db253a3ea26 100644 --- a/frameworks/intl/include/i18n_break_iterator.h +++ b/frameworks/intl/include/i18n_break_iterator.h @@ -22,7 +22,7 @@ namespace Global { namespace I18n { class I18nBreakIterator { public: - I18nBreakIterator(std::string lcoaleTag); + explicit I18nBreakIterator(std::string lcoaleTag); virtual ~I18nBreakIterator(); int32_t current(); int32_t first(); diff --git a/frameworks/intl/include/i18n_calendar.h b/frameworks/intl/include/i18n_calendar.h index 6517a82237c3303ad9b07e3eaa60c81b90d233de..3d89d183aa986c32f5c39127a1538a10bf22563e 100644 --- a/frameworks/intl/include/i18n_calendar.h +++ b/frameworks/intl/include/i18n_calendar.h @@ -39,7 +39,7 @@ enum CalendarType { class I18nCalendar { public: - I18nCalendar(std::string localeTag); + explicit I18nCalendar(std::string localeTag); I18nCalendar(std::string localeTag, CalendarType type); virtual ~I18nCalendar(); void SetTime(double time); diff --git a/frameworks/intl/include/index_util.h b/frameworks/intl/include/index_util.h index a0e41fac1db35f2d1499b4777e4e60a738aad11d..41a6cef2299474fcd178a6f33ab875fa6d48b6fc 100644 --- a/frameworks/intl/include/index_util.h +++ b/frameworks/intl/include/index_util.h @@ -24,7 +24,7 @@ namespace Global { namespace I18n { class IndexUtil { public: - IndexUtil(const std::string &localeTag); + explicit IndexUtil(const std::string &localeTag); ~IndexUtil(); std::vector GetIndexList(); void AddLocale(const std::string &localeTag); diff --git a/frameworks/intl/include/locale_info.h b/frameworks/intl/include/locale_info.h index d5d3d7110d757ef4af66b7094486c7661eec8e97..29f384bbc98ff9bf492f89e0f665bb47863db042 100644 --- a/frameworks/intl/include/locale_info.h +++ b/frameworks/intl/include/locale_info.h @@ -26,7 +26,7 @@ namespace Global { namespace I18n { class LocaleInfo { public: - LocaleInfo(std::string locale); + explicit LocaleInfo(std::string locale); LocaleInfo(const std::string &localeTag, std::map &configs); virtual ~LocaleInfo(); std::string GetLanguage() const; diff --git a/frameworks/intl/include/number_format.h b/frameworks/intl/include/number_format.h index 51f21ac1ca2ed57c459ec23b9ccb3edde52cc2f4..1a2c9ef48ec29f952309d39de82453f8d0bc36cd 100644 --- a/frameworks/intl/include/number_format.h +++ b/frameworks/intl/include/number_format.h @@ -103,6 +103,7 @@ private: void GetDigitsResolvedOptions(std::map &map); void InitProperties(); void InitDigitsProperties(); + void SetUnit(std::string &preferredUnit); }; } // namespace I18n } // namespace Global diff --git a/frameworks/intl/src/number_format.cpp b/frameworks/intl/src/number_format.cpp index fcc197ef3decd13c94be036e459914c1e7d7ab9d..3ad769a3bbd9a8fc858a30e798b1c0259875f1cc 100644 --- a/frameworks/intl/src/number_format.cpp +++ b/frameworks/intl/src/number_format.cpp @@ -241,6 +241,18 @@ void NumberFormat::ParseDigitsConfigs(std::map &config } } +void NumberFormat::SetUnit(std::string &preferredUnit) +{ + if (preferredUnit.empty()) { + return; + } + for (icu::MeasureUnit curUnit : unitArray) { + if (!strcmp(curUnit.getSubtype(), preferredUnit.c_str())) { + numberFormat = numberFormat.unit(curUnit); + } + } +} + std::string NumberFormat::Format(double number) { double finalNumber = number; @@ -273,13 +285,7 @@ std::string NumberFormat::Format(double number) finalNumber = preferredValuesUnderOne.rbegin()->first; preferredUnit = preferredValuesUnderOne.rbegin()->second; } - if (!preferredUnit.empty()) { - for (icu::MeasureUnit curUnit : unitArray) { - if (!strcmp(curUnit.getSubtype(), preferredUnit.c_str())) { - numberFormat = numberFormat.unit(curUnit); - } - } - } + SetUnit(preferredUnit); } std::string result; UErrorCode status = U_ZERO_ERROR; diff --git a/frameworks/zone/test/unittest/zone_util_performance_test.cpp b/frameworks/zone/test/unittest/zone_util_performance_test.cpp index b39e9f35b228e24d0577a6037761d68483f22228..75a868dcb6e67219f3b4e90a4d3967a91ad9b68e 100644 --- a/frameworks/zone/test/unittest/zone_util_performance_test.cpp +++ b/frameworks/zone/test/unittest/zone_util_performance_test.cpp @@ -52,7 +52,7 @@ void ZoneUtilPerformanceTest::TearDown(void) */ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest001, TestSize.Level1) { - unsigned long long total = 0; + uint64_t total = 0; double average = 0; string expects[] = { "Asia/Shanghai", "America/New_York" }; string countries[] = { "JP", "KR" }; @@ -60,7 +60,7 @@ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest001, TestSize.Leve ZoneUtil util; for (int k = 0; k < 1000; ++k) { for (int i = 0; i < count; ++i) { - auto t1= std::chrono::high_resolution_clock::now(); + auto t1 = std::chrono::high_resolution_clock::now(); string out = util.GetDefaultZone(countries[i].c_str()); auto t2 = std::chrono::high_resolution_clock::now(); total += std::chrono::duration_cast(t2 - t1).count(); @@ -77,7 +77,7 @@ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest001, TestSize.Leve */ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest002, TestSize.Level1) { - unsigned long long total = 0; + uint64_t total = 0; double average = 0; string expects[] = { "Asia/Shanghai", "America/Detroit" }; int32_t offsets[] = { 3600 * 1000 * 8, -3600 * 1000 * 5 }; @@ -86,7 +86,7 @@ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest002, TestSize.Leve ZoneUtil util; for (int k = 0; k < 1000; ++k) { for (int i = 0; i < count; ++i) { - auto t1= std::chrono::high_resolution_clock::now(); + auto t1 = std::chrono::high_resolution_clock::now(); string out = util.GetDefaultZone(countries[i].c_str(), offsets[i]); auto t2 = std::chrono::high_resolution_clock::now(); total += std::chrono::duration_cast(t2 - t1).count(); @@ -103,14 +103,14 @@ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest002, TestSize.Leve */ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest003, TestSize.Level1) { - unsigned long long total = 0; + uint64_t total = 0; double average = 0; vector expects = { "Asia/Shanghai", "Asia/Urumqi"}; string country = "CN"; vector out; ZoneUtil util; for (int k = 0; k < 1000; ++k) { - auto t1= std::chrono::high_resolution_clock::now(); + auto t1 = std::chrono::high_resolution_clock::now(); util.GetZoneList(country, out); auto t2 = std::chrono::high_resolution_clock::now(); total += std::chrono::duration_cast(t2 - t1).count(); @@ -126,14 +126,14 @@ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest003, TestSize.Leve */ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest004, TestSize.Level1) { - unsigned long long total = 0; + uint64_t total = 0; double average = 0; vector expects = { "Europe/London" }; string country = "GB"; vector out; ZoneUtil util; for (int k = 0; k < 1000; ++k) { - auto t1= std::chrono::high_resolution_clock::now(); + auto t1 = std::chrono::high_resolution_clock::now(); util.GetZoneList(country, out); auto t2 = std::chrono::high_resolution_clock::now(); total += std::chrono::duration_cast(t2 - t1).count(); @@ -149,14 +149,14 @@ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest004, TestSize.Leve */ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest005, TestSize.Level1) { - unsigned long long total = 0; + uint64_t total = 0; double average = 0; vector expects = { "Europe/Berlin", "Europe/Busingen" }; string country = "DE"; vector out; ZoneUtil util; for (int k = 0; k < 1000; ++k) { - auto t1= std::chrono::high_resolution_clock::now(); + auto t1 = std::chrono::high_resolution_clock::now(); util.GetZoneList(country, out); auto t2 = std::chrono::high_resolution_clock::now(); total += std::chrono::duration_cast(t2 - t1).count(); @@ -172,14 +172,14 @@ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest005, TestSize.Leve */ HWTEST_F(ZoneUtilPerformanceTest, ZoneUtilPerformanceFuncTest006, TestSize.Level1) { - unsigned long long total = 0; + uint64_t total = 0; double average = 0; vector expects = { "Asia/Shanghai" }; string country = "CN"; vector out; ZoneUtil util; for (int k = 0; k < 1000; ++k) { - auto t1= std::chrono::high_resolution_clock::now(); + auto t1 = std::chrono::high_resolution_clock::now(); util.GetZoneList(country, 3600 * 1000 * 8, out); auto t2 = std::chrono::high_resolution_clock::now(); total += std::chrono::duration_cast(t2 - t1).count(); diff --git a/interfaces/js/kits/src/i18n_addon.cpp b/interfaces/js/kits/src/i18n_addon.cpp index 59c348867628a33df5e0dd0cc50c953a56ce9159..9fbcb17ecdf35ed92639dbb08a16693bfe172c64 100644 --- a/interfaces/js/kits/src/i18n_addon.cpp +++ b/interfaces/js/kits/src/i18n_addon.cpp @@ -2701,7 +2701,7 @@ static napi_module g_i18nModule = { .nm_filename = nullptr, .nm_register_func = Init, .nm_modname = "i18n", - .nm_priv = ((void *)0), + .nm_priv = nullptr, .reserved = { 0 } }; diff --git a/interfaces/js/kits/src/intl_addon.cpp b/interfaces/js/kits/src/intl_addon.cpp index 7f25ce6437cbb81a6fc59d5837f78b0a7c478989..01005d6b2fc1f807d8c17a322c6b464c282cdb70 100644 --- a/interfaces/js/kits/src/intl_addon.cpp +++ b/interfaces/js/kits/src/intl_addon.cpp @@ -1982,7 +1982,7 @@ static napi_module g_intlModule = { .nm_filename = nullptr, .nm_register_func = Init, .nm_modname = "intl", - .nm_priv = ((void *)0), + .nm_priv = nullptr, .reserved = { 0 } };