未验证 提交 a1f81344 编写于 作者: O openharmony_ci 提交者: Gitee

!174 fix reviewbot warnings

Merge pull request !174 from sunyaozu/master
......@@ -31,7 +31,7 @@ public:
std::string GetIndex(const std::string &String);
private:
icu::AlphabeticIndex *index;
std::unique_ptr<icu::AlphabeticIndex> index;
};
}
}
......
......@@ -59,8 +59,8 @@ private:
std::string styleString = "long";
std::string numeric = "always";
std::string numberingSystem;
LocaleInfo *localeInfo = nullptr;
icu::RelativeDateTimeFormatter *relativeTimeFormat = nullptr;
std::unique_ptr<LocaleInfo> localeInfo;
std::unique_ptr<icu::RelativeDateTimeFormatter> relativeTimeFormat;
UDateRelativeDateTimeFormatterStyle style = UDAT_STYLE_LONG;
static std::unordered_map<std::string, URelativeDateTimeUnit> relativeUnits;
static std::unordered_map<std::string, UDateRelativeDateTimeFormatterStyle> relativeFormatStyle;
......
......@@ -179,7 +179,7 @@ void DateTimeFormat::removeAmPmChar()
if (patternString[i] != 'a') {
continue;
}
if ((i + 1) < patternString.length() && patternString[i+1] == 't') {
if ((i + 1) < patternString.length() && patternString[i + 1] == 't') {
continue;
}
if (i == 0) {
......
......@@ -23,19 +23,15 @@ IndexUtil::IndexUtil(const std::string &localeTag)
UErrorCode status = U_ZERO_ERROR;
if (localeTag == "") {
icu::Locale locale(LocaleConfig::GetSystemLocale().c_str());
index = new icu::AlphabeticIndex(locale, status);
index = std::make_unique<icu::AlphabeticIndex>(locale, status);
} else {
icu::Locale locale(localeTag.c_str());
index = new icu::AlphabeticIndex(locale, status);
index = std::make_unique<icu::AlphabeticIndex>(locale, status);
}
}
IndexUtil::~IndexUtil()
{
if (index != nullptr) {
delete index;
index = nullptr;
}
}
std::vector<std::string> IndexUtil::GetIndexList()
......
......@@ -39,12 +39,12 @@ bool PreferredLanguage::AddPreferredLanguageExist(std::vector<std::string> &pref
}
if (languageIdx < index) {
for (int i = languageIdx; i < index; i++) {
preferredLanguageList[i] = preferredLanguageList[i+1];
preferredLanguageList[i] = preferredLanguageList[i + 1];
}
}
if (languageIdx > index) {
for (int i = languageIdx; i > index; i--) {
preferredLanguageList[i] = preferredLanguageList[i-1];
preferredLanguageList[i] = preferredLanguageList[i - 1];
}
}
preferredLanguageList[index] = language;
......@@ -173,7 +173,7 @@ std::vector<std::string> PreferredLanguage::GetPreferredLanguageList()
list.insert(list.begin(), systemLanguage);
} else {
for (size_t i = (size_t)systemLanguageIdx; i > 0; i--) {
list[i] = list[i-1];
list[i] = list[i - 1];
}
list[0] = systemLanguage;
}
......
......@@ -46,8 +46,8 @@ std::unordered_map<std::string, URelativeDateTimeUnit> RelativeTimeFormat::relat
{ "years", UDAT_REL_UNIT_YEAR },
};
RelativeTimeFormat::RelativeTimeFormat(const std::vector<std::string> &localeTags, std::map<std::string,
std::string> &configs)
RelativeTimeFormat::RelativeTimeFormat(const std::vector<std::string> &localeTags,
std::map<std::string, std::string> &configs)
{
UErrorCode status = U_ZERO_ERROR;
auto builder = std::make_unique<icu::LocaleBuilder>();
......@@ -56,19 +56,19 @@ RelativeTimeFormat::RelativeTimeFormat(const std::vector<std::string> &localeTag
std::string curLocale = localeTags[i];
locale = builder->setLanguageTag(icu::StringPiece(curLocale)).build(status);
if (LocaleInfo::allValidLocales.count(locale.getLanguage()) > 0) {
localeInfo = new LocaleInfo(curLocale, configs);
localeInfo = std::make_unique<LocaleInfo>(curLocale, configs);
locale = localeInfo->GetLocale();
localeBaseName = localeInfo->GetBaseName();
relativeTimeFormat = new icu::RelativeDateTimeFormatter(locale, nullptr, style,
relativeTimeFormat = std::make_unique<icu::RelativeDateTimeFormatter>(locale, nullptr, style,
UDISPCTX_CAPITALIZATION_NONE, status);
break;
}
}
if (localeInfo == nullptr || relativeTimeFormat == nullptr) {
localeInfo = new LocaleInfo(LocaleConfig::GetSystemLocale(), configs);
localeInfo = std::make_unique<LocaleInfo>(LocaleConfig::GetSystemLocale(), configs);
locale = localeInfo->GetLocale();
localeBaseName = localeInfo->GetBaseName();
relativeTimeFormat = new icu::RelativeDateTimeFormatter(locale, nullptr, style,
relativeTimeFormat = std::make_unique<icu::RelativeDateTimeFormatter>(locale, nullptr, style,
UDISPCTX_CAPITALIZATION_NONE, status);
}
numberingSystem = localeInfo->GetNumberingSystem();
......@@ -79,14 +79,6 @@ RelativeTimeFormat::RelativeTimeFormat(const std::vector<std::string> &localeTag
RelativeTimeFormat::~RelativeTimeFormat()
{
if (localeInfo != nullptr) {
delete localeInfo;
localeInfo = nullptr;
}
if (relativeTimeFormat != nullptr) {
delete relativeTimeFormat;
relativeTimeFormat = nullptr;
}
}
void RelativeTimeFormat::ParseConfigs(std::map<std::string, std::string> &configs)
......
......@@ -137,9 +137,9 @@ void I18nAddon::CreateInitProperties(napi_property_descriptor *properties)
properties[19] = DECLARE_NAPI_FUNCTION("getPreferredLanguageList", GetPreferredLanguageList);
// 20 is properties index
properties[20] = DECLARE_NAPI_FUNCTION("getFirstPreferredLanguage", GetFirstPreferredLanguage);
// 21 is properties index
// 21 is properties index
properties[21] = DECLARE_NAPI_FUNCTION("is24HourClock", Is24HourClock);
// 22 is properties index
// 22 is properties index
properties[22] = DECLARE_NAPI_FUNCTION("set24HourClock", Set24HourClock);
}
......
......@@ -31,9 +31,9 @@ public:
static std::string GetPreferredLocale();
private:
static bool AddPreferredLanguageNonExist(std::vector<std::string> &preferredLanguageList, int index,
static bool AddPreferredLanguageNonExist(std::vector<std::string> &preferredLangList, int index,
const std::string& language);
static bool AddPreferredLanguageExist(std::vector<std::string> &preferredLanguageList, int languageIdx, int index,
static bool AddPreferredLanguageExist(std::vector<std::string> &preferredLangList, int languageIdx, int index,
const std::string& language);
static std::set<std::string> GetResources();
static bool IsMatched(const std::string& preferred, const std::string& resource);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册