mirror of
https://gitee.com/openharmony/global_i18n
synced 2024-11-27 09:11:40 +00:00
代码规范问题2
Signed-off-by: zhangdd_ewan <zhangdongdong50@huawei.com>
This commit is contained in:
parent
00628b7401
commit
6a8773c0cb
@ -12,8 +12,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef GLOBAL_i18n_COLLATOR_H
|
||||
#define GLOBAL_i18n_COLLATOR_H
|
||||
#ifndef GLOBAL_I18n_COLLATOR_H
|
||||
#define GLOBAL_I18n_COLLATOR_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
@ -25,8 +25,8 @@ namespace I18n {
|
||||
class MatchedDateTimeInfo {
|
||||
public:
|
||||
MatchedDateTimeInfo() : _begin(-1), _end(-1), type(0), isTimePeriod(false) {}
|
||||
MatchedDateTimeInfo(int begin, int end, std::string& regex) :
|
||||
_begin(begin), _end(end), regex(regex), type(0), isTimePeriod(false) {}
|
||||
MatchedDateTimeInfo(int begin, int end, std::string& regex)
|
||||
: _begin(begin), _end(end), regex(regex), type(0), isTimePeriod(false) {}
|
||||
~MatchedDateTimeInfo() {}
|
||||
|
||||
void SetIsTimePeriod(bool is)
|
||||
|
@ -40,6 +40,8 @@ public:
|
||||
private:
|
||||
void InitRule(std::string& xmlPath);
|
||||
void FreePointer(std::vector<RegexRule*> &ruleList);
|
||||
void SetRules(std::string& category, icu::UnicodeString& content, std::string& valid,
|
||||
std::string& handle,std::string& insensitive,std::string& type);
|
||||
|
||||
std::vector<RegexRule*> negativeRules;
|
||||
std::vector<RegexRule*> positiveRules;
|
||||
|
@ -50,11 +50,14 @@ private:
|
||||
void ReadResourceList();
|
||||
std::string GetLanguageFromFileName(const std::string& fileName);
|
||||
|
||||
static std::set<std::string> supportedRegions; // Indicates which regions support name replacement using taboo data.
|
||||
static std::set<std::string> supportedLanguages; // Indicates which languages support name replacement using taboo data.
|
||||
// Indicates which regions support name replacement using taboo data.
|
||||
static std::set<std::string> supportedRegions;
|
||||
// Indicates which languages support name replacement using taboo data.
|
||||
static std::set<std::string> supportedLanguages;
|
||||
// cache the name replacement taboo data of different locale.
|
||||
std::map<std::string, std::map<std::string, std::string>> localeTabooData;
|
||||
static std::map<std::string, std::string> RESOURCES; // Indicates which locales are supported to find taboo data.
|
||||
// Indicates which locales are supported to find taboo data.
|
||||
static std::map<std::string, std::string> RESOURCES;
|
||||
|
||||
std::string tabooDataPath = "";
|
||||
std::string tabooConfigFileName = "taboo-config.xml";
|
||||
|
@ -122,7 +122,7 @@ std::vector<MatchedDateTimeInfo> DateRuleInit::GetMatches(icu::UnicodeString& me
|
||||
}
|
||||
|
||||
void DateRuleInit::GetMatchedInfo(std::vector<MatchedDateTimeInfo>& matches, MatchedDateTimeInfo& match,
|
||||
icu::UnicodeString& message)
|
||||
icu::UnicodeString& message)
|
||||
{
|
||||
// splitting results based on subRules.
|
||||
if (subDetectsMap.find(match.GetRegex()) != subDetectsMap.end()) {
|
||||
|
@ -52,7 +52,11 @@ HolidayManager::HolidayManager(const char* path)
|
||||
for (size_t i = 0; i < items.size(); i++) {
|
||||
struct tm tmObj = {.tm_mday = items[i].day, .tm_mon = items[i].month, .tm_year = items[i].year};
|
||||
char strDate[10];
|
||||
strftime(strDate, sizeof(strDate), "%Y%m%d", &tmObj);
|
||||
size_t resCode = strftime(strDate, sizeof(strDate), "%Y%m%d", &tmObj);
|
||||
if (resCode == 0) {
|
||||
HiLog::Error(LABEL, "Failed: strftime error:%{public}d .", resCode);
|
||||
return;
|
||||
}
|
||||
std::string startDate(strDate);
|
||||
items[i].year += YEAR_START;
|
||||
items[i].month += MONTH_GREATER_ONE;
|
||||
@ -133,7 +137,8 @@ std::vector<HolidayInfoItem> HolidayManager::GetHolidayInfoItemArray(int32_t yea
|
||||
|
||||
std::string HolidayManager::ValidateHolidayFilePath(const char* path)
|
||||
{
|
||||
char *realpathRes = realpath(path, nullptr);
|
||||
char realPathBuffer[PATH_MAX];
|
||||
char *realpathRes = realpath(path, realPathBuffer);
|
||||
if (realpathRes == NULL) {
|
||||
free(realpathRes);
|
||||
return "the holiday resource file not exists.";
|
||||
|
@ -342,7 +342,7 @@ std::map<int, std::string> I18nTimeZone::categoryNum2TimezoneEN {
|
||||
{ 97, "Asia/Tashkent" },
|
||||
{ 98, "Asia/Tbilisi" },
|
||||
{ 99, "Asia/Tehran" },
|
||||
{ 100, "Asia/Thimphu" },
|
||||
{ 100, "Asia/Thimbu" },
|
||||
{ 101, "Asia/Tokyo" },
|
||||
{ 102, "Asia/Tomsk" },
|
||||
{ 103, "Asia/Ulaanbaatar" },
|
||||
@ -980,11 +980,12 @@ std::string I18nTimeZone::GetFallBack(std::string &localeStr)
|
||||
}
|
||||
size_t begin = 0;
|
||||
std::vector<std::string> localeParts;
|
||||
while (true) {
|
||||
bool breakFlag = true;
|
||||
while (breakFlag) {
|
||||
size_t end = localeStr.find('_', begin);
|
||||
localeParts.push_back(localeStr.substr(begin, end - begin));
|
||||
if (end == std::string::npos) {
|
||||
break;
|
||||
breakFlag = false;
|
||||
}
|
||||
begin = end + 1;
|
||||
}
|
||||
@ -1087,7 +1088,8 @@ std::vector<std::string> I18nTimeZone::GetTimezoneIdByLocation(const double x, c
|
||||
if (preferredPath == "") {
|
||||
return tzIdList;
|
||||
}
|
||||
uint32_t width, height;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
GetTzDataWidth(filePaths, &width, &height);
|
||||
double calculateX = y * width / (TZ_X_PLUS * 1.0) + width / (TZ_HALF_OF_SIZE * 1.0);
|
||||
double calculateY = x * ((height * fileCount) / (TZ_X_PLUS * TZ_HALF_OF_SIZE * 1.0)) +
|
||||
|
@ -431,22 +431,19 @@ PhoneNumberMatch* PhoneNumberMatched::HandleCodesRule(PhoneNumberMatch* phoneNum
|
||||
PhoneNumberMatch* match = phoneNumberMatch;
|
||||
std::vector<RegexRule*> rules = phoneNumberRule->GetCodesRules();
|
||||
bool isVaild = true;
|
||||
if (rules.size() != 0) {
|
||||
for (RegexRule* rule : rules) {
|
||||
PhoneNumberMatch* tempmatch = rule->IsValid(match, message);
|
||||
if (tempmatch == nullptr) {
|
||||
isVaild = false;
|
||||
break;
|
||||
} else {
|
||||
match = tempmatch;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isVaild) {
|
||||
return match;
|
||||
} else {
|
||||
if (rules.size() == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
for (RegexRule* rule : rules) {
|
||||
PhoneNumberMatch* tempmatch = rule->IsValid(match, message);
|
||||
if (tempmatch == nullptr) {
|
||||
isVaild = false;
|
||||
break;
|
||||
} else {
|
||||
match = tempmatch;
|
||||
}
|
||||
}
|
||||
return isVaild ? match : nullptr;
|
||||
}
|
||||
|
||||
// Add phone numbers that meet the positive rule to the result
|
||||
|
@ -109,17 +109,7 @@ void PhoneNumberRule::InitRule(std::string& xmlPath)
|
||||
content += tempContent;
|
||||
xmlFree(contentPtr);
|
||||
}
|
||||
if (category == "negative" || (category == "common" && commonExit)) {
|
||||
negativeRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
} else if (category == "positive") {
|
||||
positiveRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
} else if (category == "border") {
|
||||
borderRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
} else if (category == "codes") {
|
||||
codesRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
} else if (category == "find_number") {
|
||||
findRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
}
|
||||
SetRules(category, content, valid, handle, insensitive, type);
|
||||
rule = rule->next;
|
||||
}
|
||||
cur = cur->next;
|
||||
@ -127,6 +117,22 @@ void PhoneNumberRule::InitRule(std::string& xmlPath)
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
|
||||
void PhoneNumberRule::SetRules(std::string& category, icu::UnicodeString& content, std::string& valid,
|
||||
std::string& handle,std::string& insensitive,std::string& type)
|
||||
{
|
||||
if (category == "negative" || (category == "common" && commonExit)) {
|
||||
negativeRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
} else if (category == "positive") {
|
||||
positiveRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
} else if (category == "border") {
|
||||
borderRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
} else if (category == "codes") {
|
||||
codesRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
} else if (category == "find_number") {
|
||||
findRules.push_back(new RegexRule(content, valid, handle, insensitive, type));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<RegexRule*> PhoneNumberRule::GetBorderRules()
|
||||
{
|
||||
return borderRules;
|
||||
|
@ -54,7 +54,7 @@ std::vector<MatchedDateTimeInfo> RulesEngine::Match(icu::UnicodeString& message)
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::UnicodeString regex = this->patterns[key];
|
||||
icu::RegexPattern* pattern = icu::RegexPattern::compile(regex,
|
||||
URegexpFlag::UREGEX_CASE_INSENSITIVE, status);
|
||||
URegexpFlag::UREGEX_CASE_INSENSITIVE, status);
|
||||
if (pattern == nullptr) {
|
||||
HiLog::Error(LABEL, "Match failed because pattern is nullptr.");
|
||||
return matches;
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <climits>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
@ -59,14 +60,14 @@ int32_t ConvertString2Int(const string &numberStr, int32_t& status)
|
||||
{
|
||||
try {
|
||||
return std::stoi(numberStr);
|
||||
} catch(const std::invalid_argument& except) {
|
||||
status = -1;
|
||||
HiLog::Error(LABEL, "ConvertString2Int: invalid argument");
|
||||
return -1;
|
||||
} catch (const std::out_of_range& except) {
|
||||
} catch(const std::out_of_range& except) {
|
||||
status = -1;
|
||||
HiLog::Error(LABEL, "ConvertString2Int: invalid argument out of range");
|
||||
return -1;
|
||||
} catch (const std::invalid_argument& except) {
|
||||
status = -1;
|
||||
HiLog::Error(LABEL, "ConvertString2Int: invalid argument");
|
||||
return -1;
|
||||
} catch (...) {
|
||||
status = -1;
|
||||
return -1;
|
||||
@ -101,8 +102,9 @@ void GetAllValidLocalesTag(std::unordered_set<std::string>& allValidLocalesLangu
|
||||
|
||||
bool CheckTzDataFilePath(const std::string &filePath)
|
||||
{
|
||||
char realPathBuffer[PATH_MAX];
|
||||
char *realpathRes = nullptr;
|
||||
realpathRes = realpath(filePath.c_str(), nullptr);
|
||||
realpathRes = realpath(filePath.c_str(), realPathBuffer);
|
||||
if (realpathRes == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace OHOS {
|
||||
holidayManager->IsHoliday();
|
||||
holidayManager->IsHoliday(size, size, size);
|
||||
holidayManager->GetHolidayInfoItemArray();
|
||||
holidayManager->GetHolidayInfoItemArray(size);
|
||||
holidayManager->GetHolidayInfoItemArray(size);
|
||||
delete holidayManager;
|
||||
return true;
|
||||
}
|
||||
|
@ -31,10 +31,8 @@ IcsFileWriter::~IcsFileWriter()
|
||||
|
||||
std::string IcsFileWriter::GenerateFile()
|
||||
{
|
||||
using namespace std;
|
||||
std::string filePath = "/data/log/TR.ics";
|
||||
ofstream fstream(filePath);
|
||||
//fstream.open(filePath, ios::out);
|
||||
std::ofstream fstream(filePath);
|
||||
if (!fstream.is_open()) {
|
||||
printf("file can't access.\r\n");
|
||||
return filePath;
|
||||
@ -61,7 +59,6 @@ std::string IcsFileWriter::GenerateFile()
|
||||
for (size_t i = 0; i < list.size(); i++) {
|
||||
fstream << list[i] << endl;
|
||||
}
|
||||
|
||||
fstream.close();
|
||||
return filePath;
|
||||
}
|
||||
|
@ -26,7 +26,8 @@
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
extern "C" __attribute__((used)) bool QueryWithProxy(const std::string& key, std::string& value, sptr<IRemoteObject> &proxy);
|
||||
extern "C" __attribute__((used)) bool QueryWithProxy(const std::string& key,
|
||||
std::string& value, sptr<IRemoteObject> &proxy);
|
||||
__attribute__((used)) static Uri AssembleUri(const std::string& key);
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
|
@ -29,7 +29,8 @@ const std::string SETTINGS_DATA_COLUMN_VALUE = "VALUE";
|
||||
|
||||
bool QueryWithProxy(const std::string& key, std::string& value, sptr<IRemoteObject> &proxy)
|
||||
{
|
||||
std::shared_ptr<DataShare::DataShareHelper> dataShareHelper = DataShare::DataShareHelper::Creator(proxy, SETTINGS_DATASHARE_URI, SETTINGS_DATA_EXT_URI);
|
||||
std::shared_ptr<DataShare::DataShareHelper> dataShareHelper =
|
||||
DataShare::DataShareHelper::Creator(proxy, SETTINGS_DATASHARE_URI, SETTINGS_DATA_EXT_URI);
|
||||
std::vector<std::string> columns = {SETTINGS_DATA_COLUMN_VALUE};
|
||||
DataShare::DataSharePredicates predicates;
|
||||
predicates.EqualTo(SETTINGS_DATA_COLUMN_KEYWORD, key);
|
||||
|
@ -278,7 +278,8 @@ napi_value I18nTimeZoneAddon::GetTimezonesByLocation(napi_env env, napi_callback
|
||||
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
|
||||
return nullptr;
|
||||
}
|
||||
double x, y;
|
||||
double x;
|
||||
double y;
|
||||
status = napi_get_value_double(env, argv[0], &x);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "GetTimezonesByLocation: Parse first argument x failed");
|
||||
|
@ -31,7 +31,8 @@ I18nServiceAbilityProxy::I18nServiceAbilityProxy(const sptr<IRemoteObject> &impl
|
||||
|
||||
I18nErrorCode I18nServiceAbilityProxy::SetSystemLanguage(const std::string &language)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DESCRIPTOR);
|
||||
data.WriteString(language);
|
||||
@ -42,7 +43,8 @@ I18nErrorCode I18nServiceAbilityProxy::SetSystemLanguage(const std::string &lang
|
||||
|
||||
I18nErrorCode I18nServiceAbilityProxy::SetSystemRegion(const std::string ®ion)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DESCRIPTOR);
|
||||
data.WriteString(region);
|
||||
@ -53,7 +55,8 @@ I18nErrorCode I18nServiceAbilityProxy::SetSystemRegion(const std::string ®ion
|
||||
|
||||
I18nErrorCode I18nServiceAbilityProxy::SetSystemLocale(const std::string &locale)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DESCRIPTOR);
|
||||
data.WriteString(locale);
|
||||
@ -64,7 +67,8 @@ I18nErrorCode I18nServiceAbilityProxy::SetSystemLocale(const std::string &locale
|
||||
|
||||
I18nErrorCode I18nServiceAbilityProxy::Set24HourClock(bool flag)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DESCRIPTOR);
|
||||
data.WriteBool(flag);
|
||||
@ -75,7 +79,8 @@ I18nErrorCode I18nServiceAbilityProxy::Set24HourClock(bool flag)
|
||||
|
||||
I18nErrorCode I18nServiceAbilityProxy::SetUsingLocalDigit(bool flag)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DESCRIPTOR);
|
||||
data.WriteBool(flag);
|
||||
@ -86,7 +91,8 @@ I18nErrorCode I18nServiceAbilityProxy::SetUsingLocalDigit(bool flag)
|
||||
|
||||
I18nErrorCode I18nServiceAbilityProxy::AddPreferredLanguage(const std::string &language, int32_t index)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DESCRIPTOR);
|
||||
data.WriteString(language);
|
||||
@ -98,7 +104,8 @@ I18nErrorCode I18nServiceAbilityProxy::AddPreferredLanguage(const std::string &l
|
||||
|
||||
I18nErrorCode I18nServiceAbilityProxy::RemovePreferredLanguage(int32_t index)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DESCRIPTOR);
|
||||
data.WriteInt32(index);
|
||||
|
Loading…
Reference in New Issue
Block a user