提交 1f5f5162 编写于 作者: S sunyaozu

fix code quality problem

Signed-off-by: Nsunyaozu <sunyaozu@huawei.com>
上级 649f05a7
......@@ -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();
......
......@@ -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);
......
......@@ -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<std::string> GetIndexList();
void AddLocale(const std::string &localeTag);
......
......@@ -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<std::string, std::string> &configs);
virtual ~LocaleInfo();
std::string GetLanguage() const;
......
......@@ -103,6 +103,7 @@ private:
void GetDigitsResolvedOptions(std::map<std::string, std::string> &map);
void InitProperties();
void InitDigitsProperties();
void SetUnit(std::string &preferredUnit);
};
} // namespace I18n
} // namespace Global
......
......@@ -241,6 +241,18 @@ void NumberFormat::ParseDigitsConfigs(std::map<std::string, std::string> &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;
......
......@@ -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<std::chrono::microseconds>(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<std::chrono::microseconds>(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<string> expects = { "Asia/Shanghai", "Asia/Urumqi"};
string country = "CN";
vector<string> 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<std::chrono::microseconds>(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<string> expects = { "Europe/London" };
string country = "GB";
vector<string> 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<std::chrono::microseconds>(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<string> expects = { "Europe/Berlin", "Europe/Busingen" };
string country = "DE";
vector<string> 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<std::chrono::microseconds>(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<string> expects = { "Asia/Shanghai" };
string country = "CN";
vector<string> 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<std::chrono::microseconds>(t2 - t1).count();
......
......@@ -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 }
};
......
......@@ -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 }
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册