mirror of
https://github.com/openharmony/global_i18n_lite.git
synced 2026-07-01 01:37:55 -04:00
@@ -108,7 +108,7 @@ private:
|
||||
bool ReadHeader(int32_t infile);
|
||||
bool PrepareData(int32_t infile);
|
||||
int32_t BinarySearchLocale(const uint32_t mask, unsigned char *locales);
|
||||
bool GetStringFromStringPool(char *configs, const uint32_t configsSize, int32_t infile, LocaleDataType type);
|
||||
bool GetStringFromStringPool(char *configs, int32_t infile, LocaleDataType type);
|
||||
uint32_t ConvertUint(unsigned char *src);
|
||||
uint32_t ConvertUChar(unsigned char *src);
|
||||
char *GetString2(DataResourceType type) const;
|
||||
@@ -120,12 +120,12 @@ private:
|
||||
char *locales);
|
||||
void GetFallbackAndDefaultInfo(const int32_t &fallbackLocaleIndex, const int32_t &defaultLocaleIndex,
|
||||
uint32_t &fallbackConfigOffset, uint32_t &defaultConfigOffset, char *locales);
|
||||
bool Retrieve(char *configs, const uint32_t configsSize, int32_t infile, const uint32_t originalCount,
|
||||
bool Retrieve(char *configs, int32_t infile, const uint32_t originalCount,
|
||||
LocaleDataType type);
|
||||
bool PrepareLocaleData(int32_t infile, uint32_t configOffset, uint32_t count, LocaleDataType type);
|
||||
bool FullLoaded();
|
||||
void GetType(char** &adjustResource, uint32_t* &adjustResourceIndex, uint32_t &count, LocaleDataType type);
|
||||
uint32_t GetFinalCount(char *configs, uint32_t configSize, LocaleDataType type);
|
||||
uint32_t GetFinalCount(char *configs, LocaleDataType type);
|
||||
void FreeResource();
|
||||
bool IsTypeNeeded(int32_t index, uint32_t count);
|
||||
bool ApplyForResource(uint32_t **index, char ***wanted, uint32_t totalCount);
|
||||
|
||||
@@ -79,9 +79,8 @@ private:
|
||||
void Format(const struct tm &time, const std::string &pattern, std::string &appendTo, I18nStatus &status) const;
|
||||
void ZeroPadding(std::string &appendTo, uint32_t minValue, uint32_t maxValue, int32_t value) const;
|
||||
void Process(const tm &time, std::string &append, char pre, uint32_t count, I18nStatus &status) const;
|
||||
void ProcessTime(const tm &time, std::string &append, char pre, uint32_t count, I18nStatus &status) const;
|
||||
void ProcessWeekDayYear(const tm &time, std::string &appendTo, char pre,
|
||||
uint32_t count, I18nStatus &status) const;
|
||||
void ProcessTime(const tm &time, std::string &append, char pre, uint32_t count) const;
|
||||
void ProcessWeekDayYear(const tm &time, std::string &appendTo, char pre, uint32_t count) const;
|
||||
bool IsTimeChar(char ch) const;
|
||||
int32_t ParseZoneInfo(const std::string &zoneInfo) const;
|
||||
char *GetNoAmPmPattern(const std::string &patternString, int8_t &ret) const;
|
||||
|
||||
@@ -41,9 +41,9 @@ private:
|
||||
int maxDecimalLength = -1;
|
||||
int minDecimalLength = -1;
|
||||
void CheckStatus(const errno_t rc, int &status) const;
|
||||
int DelMoreZero(const StyleData &style, int decLen, int lastLen, bool hasDec, char *&result) const;
|
||||
int DelMoreZero(int decLen, int lastLen, bool hasDec, char *&result) const;
|
||||
std::string InnerFormat(double num, bool hasDec, bool isShowGroup, bool isPercent, int &status) const;
|
||||
std::string ConvertSignAndNum(const char *content, int len, NumberData *data, StyleData &style) const;
|
||||
std::string ConvertSignAndNum(const char *content, int len, NumberData *data) const;
|
||||
int ConvertNum(std::string &strContent, char currentChar, const NumberData *data, int index, int off) const;
|
||||
int DelZero(char *target, int len, int delNum, bool onlyZero) const;
|
||||
void AddGroup(char *targetAndSource[], const int len[], const char *decimal, bool hasDec, int decLen) const;
|
||||
|
||||
@@ -41,11 +41,9 @@ private:
|
||||
bool CompareResult(const std::string &rule, const int ruleSize, int &index, const int number) const;
|
||||
bool CompareNotEqualResult(const std::string &rule, const int ruleSize, int &index, const int number) const;
|
||||
int ParseNumber(const std::string &rule, const int ruleSize, int &index) const;
|
||||
bool ParseDecimalRule(const std::string &rule, const int ruleSize, const int *numberInfo,
|
||||
const int numberInfoSize) const;
|
||||
bool ParseDecimalFormula(const std::string &rule, const int ruleSize, int &index, const int *numberInfo,
|
||||
const int numberInfoSize) const;
|
||||
void ComputeDecimalInfo(double number, int integerNumber, int *numberInfo, const int numberInfoSize) const;
|
||||
bool ParseDecimalRule(const std::string &rule, const int ruleSize, const int *numberInfo) const;
|
||||
bool ParseDecimalFormula(const std::string &rule, const int ruleSize, int &index, const int *numberInfo) const;
|
||||
void ComputeDecimalInfo(double number, int integerNumber, int *numberInfo) const;
|
||||
PluralRules *InitPluralRules(std::string unprocessedPluralData);
|
||||
bool CheckContainsIntegerRule() const;
|
||||
const int SYMBOL_LENGTH = 1;
|
||||
|
||||
@@ -282,16 +282,16 @@ bool DataResource::PrepareLocaleData(int32_t infile, uint32_t configOffset, uint
|
||||
return false;
|
||||
}
|
||||
int32_t readSize = read(infile, configs, resourceSize);
|
||||
if (readSize != resourceSize) {
|
||||
if (readSize != static_cast<int32_t>(resourceSize)) {
|
||||
I18nFree(static_cast<void *>(configs));
|
||||
return false;
|
||||
}
|
||||
bool ret = GetStringFromStringPool(configs, resourceSize, infile, type);
|
||||
bool ret = GetStringFromStringPool(configs, infile, type);
|
||||
I18nFree(static_cast<void *>(configs));
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t DataResource::GetFinalCount(char *configs, uint32_t configSize, LocaleDataType type)
|
||||
uint32_t DataResource::GetFinalCount(char *configs, LocaleDataType type)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
switch (type) {
|
||||
@@ -323,10 +323,10 @@ uint32_t DataResource::GetFinalCount(char *configs, uint32_t configSize, LocaleD
|
||||
return finalCount;
|
||||
}
|
||||
|
||||
bool DataResource::GetStringFromStringPool(char *configs, const uint32_t configsSize, int32_t infile,
|
||||
bool DataResource::GetStringFromStringPool(char *configs, int32_t infile,
|
||||
LocaleDataType type)
|
||||
{
|
||||
uint32_t finalCount = GetFinalCount(configs, configsSize, type);
|
||||
uint32_t finalCount = GetFinalCount(configs, type);
|
||||
if (finalCount == 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -359,7 +359,7 @@ bool DataResource::GetStringFromStringPool(char *configs, const uint32_t configs
|
||||
if (!ApplyForResource(index, wanted, finalCount)) {
|
||||
return false;
|
||||
}
|
||||
return Retrieve(configs, configsSize, infile, originalCount, type);
|
||||
return Retrieve(configs, infile, originalCount, type);
|
||||
}
|
||||
|
||||
void DataResource::GetType(char** &adjustResource, uint32_t* &adjustResourceIndex, uint32_t &count,
|
||||
@@ -387,7 +387,7 @@ void DataResource::GetType(char** &adjustResource, uint32_t* &adjustResourceInde
|
||||
}
|
||||
}
|
||||
|
||||
bool DataResource::Retrieve(char *configs, uint32_t configsSize, int32_t infile, const uint32_t orginalCount,
|
||||
bool DataResource::Retrieve(char *configs, int32_t infile, const uint32_t orginalCount,
|
||||
LocaleDataType type)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
@@ -405,7 +405,7 @@ bool DataResource::Retrieve(char *configs, uint32_t configsSize, int32_t infile,
|
||||
uint32_t length = ConvertUChar(reinterpret_cast<unsigned char*>(configs + i *
|
||||
GLOBAL_RESOURCE_CONFIG_SIZE + GLOBAL_RESOURCE_MASK_OFFSET));
|
||||
int32_t seekSize = lseek(infile, stringPoolOffset + offset, SEEK_SET);
|
||||
if ((length == 0) || (seekSize != static_cast<uint32_t>(stringPoolOffset + offset))) {
|
||||
if ((length == 0) || (seekSize != static_cast<int32_t>(stringPoolOffset + offset))) {
|
||||
adjustResource[currentIndex] = nullptr;
|
||||
adjustResourceIndex[currentIndex] = index;
|
||||
} else {
|
||||
|
||||
@@ -79,7 +79,7 @@ string DateTimeData::GetDayName(int32_t index, DateTimeDataType type)
|
||||
}
|
||||
}
|
||||
|
||||
string DateTimeData::GetAmPmMarker(int32_t index, DateTimeDataType type)
|
||||
string DateTimeData::GetAmPmMarker(int32_t index, DateTimeDataType /* type */)
|
||||
{
|
||||
if ((index < 0) || (index >= AM_SIZE) || amPmMarkers == nullptr) {
|
||||
return "";
|
||||
|
||||
@@ -53,7 +53,7 @@ string DateTimeFormatImpl::AddSeconds(const string &hmPattern) const
|
||||
if (size == 0 || data == nullptr) {
|
||||
return "";
|
||||
}
|
||||
int32_t i = hmPattern.size() - 1;
|
||||
int32_t i = static_cast<int32_t>(hmPattern.size() - 1);
|
||||
string out;
|
||||
out.reserve(DECIMAL_COUNT); // allocate ten more bytes
|
||||
while (i >= 0) {
|
||||
@@ -227,7 +227,7 @@ int32_t DateTimeFormatImpl::ParseZoneInfo(const string &zoneInfo) const
|
||||
if (!isHour && (temp != 0)) {
|
||||
minute = temp;
|
||||
}
|
||||
ret = SECONDS_IN_HOUR * hour + minute * SECONDS_IN_MINUTE;
|
||||
ret = static_cast<int32_t>(SECONDS_IN_HOUR * hour + minute * SECONDS_IN_MINUTE);
|
||||
|
||||
if (!sign) {
|
||||
return -ret;
|
||||
@@ -244,7 +244,7 @@ void DateTimeFormatImpl::Process(const tm &time, string &appendTo, char pre, uin
|
||||
return;
|
||||
}
|
||||
if (IsTimeChar(pre)) {
|
||||
ProcessTime(time, appendTo, pre, count, status);
|
||||
ProcessTime(time, appendTo, pre, count);
|
||||
return;
|
||||
}
|
||||
switch (pre) {
|
||||
@@ -271,13 +271,13 @@ void DateTimeFormatImpl::Process(const tm &time, string &appendTo, char pre, uin
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ProcessWeekDayYear(time, appendTo, pre, count, status);
|
||||
ProcessWeekDayYear(time, appendTo, pre, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DateTimeFormatImpl::ProcessWeekDayYear(const tm &time, string &appendTo, char pre,
|
||||
uint32_t count, I18nStatus &status) const
|
||||
uint32_t count) const
|
||||
{
|
||||
switch (pre) {
|
||||
case 'c': {
|
||||
@@ -332,7 +332,7 @@ bool DateTimeFormatImpl::IsTimeChar(char ch) const
|
||||
}
|
||||
|
||||
void DateTimeFormatImpl::ProcessTime(const tm &time, string &appendTo, char pre,
|
||||
uint32_t count, I18nStatus &status) const
|
||||
uint32_t count) const
|
||||
{
|
||||
switch (pre) {
|
||||
case 'a': {
|
||||
@@ -421,7 +421,7 @@ uint32_t DateTimeFormatImpl::GetLength(int32_t value) const
|
||||
return 1;
|
||||
}
|
||||
uint32_t count = 0;
|
||||
uint32_t temp = value;
|
||||
uint32_t temp = static_cast<uint32_t>(value);
|
||||
while (temp) {
|
||||
++count;
|
||||
temp = temp / DECIMAL_COUNT;
|
||||
|
||||
@@ -274,12 +274,12 @@ LocaleInfo LocaleInfo::ForLanguageTag(const char *languageTag, I18nStatus &statu
|
||||
status = IERROR;
|
||||
return locale;
|
||||
}
|
||||
ParseLanguageTag(locale, languageTag, status);
|
||||
ParseLanguageTag(locale, languageTag);
|
||||
locale.InitIdstr();
|
||||
return locale;
|
||||
}
|
||||
|
||||
void LocaleInfo::ParseLanguageTag(LocaleInfo &locale, const char *languageTag, I18nStatus &status)
|
||||
void LocaleInfo::ParseLanguageTag(LocaleInfo &locale, const char *languageTag)
|
||||
{
|
||||
const char *tag = languageTag;
|
||||
uint16_t options = OPT_LANG;
|
||||
|
||||
@@ -189,10 +189,10 @@ bool MeasureFormatImpl::Init(const DataResource &resource)
|
||||
bool MeasureFormatImpl::InitMeasureFormat(std::string &unprocessedMeasureData)
|
||||
{
|
||||
int end = 0;
|
||||
while (end < unprocessedMeasureData.length() && unprocessedMeasureData[end] != PLURAL_SEP) {
|
||||
while (end < static_cast<int>(unprocessedMeasureData.length()) && unprocessedMeasureData[end] != PLURAL_SEP) {
|
||||
end++;
|
||||
}
|
||||
unitCount = std::stoi(std::string(unprocessedMeasureData, 0, end));
|
||||
unitCount = std::atoi(std::string(unprocessedMeasureData, 0, end).c_str());
|
||||
int itemCount = MEASURE_BASE_ITEM_COUNT + unitCount * MEASURE_SINGLE_UNIT_COUNT;
|
||||
std::string *items = new std::string[itemCount];
|
||||
if (items == nullptr) {
|
||||
@@ -239,7 +239,7 @@ bool MeasureFormatImpl::ParseUnits(std::string &unitsList)
|
||||
}
|
||||
int begin = 0;
|
||||
int end = 0;
|
||||
int unitsLength = unitsList.length();
|
||||
int unitsLength = static_cast<int>(unitsList.length());
|
||||
int count = 0;
|
||||
while (count < unitCount) {
|
||||
while (end < unitsLength && unitsList[end] != MEASURE_UNIT_SEP) {
|
||||
|
||||
@@ -219,7 +219,7 @@ void NumberData::ParseOtherPerPattern(const char *pattern, const int len, const
|
||||
type = "%s%%";
|
||||
}
|
||||
I18nFree(static_cast<void *>(style.entireFormat));
|
||||
int typeLen = type.size();
|
||||
int typeLen = static_cast<int>(type.size());
|
||||
style.entireFormat = I18nNewCharString(type.data(), typeLen);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
using namespace OHOS::I18N;
|
||||
|
||||
std::string NumberFormatImpl::ConvertSignAndNum(const char *content, int len, NumberData *data, StyleData &style) const
|
||||
std::string NumberFormatImpl::ConvertSignAndNum(const char *content, int len, NumberData *data) const
|
||||
{
|
||||
if (content == nullptr) {
|
||||
return "";
|
||||
@@ -89,7 +89,7 @@ bool NumberFormatImpl::Init(const DataResource &resource)
|
||||
}
|
||||
std::string origin = split[NUM_PERCENT_PAT_INDEX];
|
||||
const char *pat = split[NUM_PAT_INDEX].c_str();
|
||||
int size = origin.size();
|
||||
size_t size = origin.size();
|
||||
std::string adjust = origin;
|
||||
// strip "0x80 0xe2 0x8f" these three bytes in pat
|
||||
if (size >= 3 && // check the last 3 character
|
||||
@@ -162,14 +162,14 @@ std::string NumberFormatImpl::InnerFormat(double num, bool hasDec, bool isShowGr
|
||||
}
|
||||
}
|
||||
// del more zero
|
||||
lastLen = DelMoreZero(defaultData->style, decLen, lastLen, adjustHasDec, result);
|
||||
lastLen = DelMoreZero(decLen, lastLen, adjustHasDec, result);
|
||||
// if percent
|
||||
if (isPercent && !DealWithPercent(buff, result, status, defaultData->style, lastLen)) {
|
||||
I18nFree(static_cast<void *>(result));
|
||||
return "";
|
||||
}
|
||||
// if have native number to convert
|
||||
std::string outStr = ConvertSignAndNum(result, lastLen, defaultData, defaultData->style);
|
||||
std::string outStr = ConvertSignAndNum(result, lastLen, defaultData);
|
||||
I18nFree(static_cast<void *>(result));
|
||||
if (num < 0) {
|
||||
outStr.insert(0, defaultData->GetMinusSign());
|
||||
@@ -209,7 +209,7 @@ bool NumberFormatImpl::DealWithPercent(char *buff, char *&result, int &status, S
|
||||
}
|
||||
|
||||
|
||||
int NumberFormatImpl::DelMoreZero(const StyleData &style, int decLen, int lastLen, bool hasDec, char *&result) const
|
||||
int NumberFormatImpl::DelMoreZero(int decLen, int lastLen, bool hasDec, char *&result) const
|
||||
{
|
||||
int num = 0;
|
||||
if (decLen > 1) {
|
||||
|
||||
@@ -86,21 +86,21 @@ int PluralFormatImpl::GetPluralRuleIndex(double number, I18nStatus status) const
|
||||
}
|
||||
int integerNumber = (int)number;
|
||||
int numberInfo[NUMBER_INFO_SIZE];
|
||||
ComputeDecimalInfo(number, integerNumber, numberInfo, NUMBER_INFO_SIZE);
|
||||
ComputeDecimalInfo(number, integerNumber, numberInfo);
|
||||
if ((mDecimalPluralRules->mZeroRuleSize > 0) && ParseDecimalRule(mDecimalPluralRules->mZeroRule,
|
||||
mDecimalPluralRules->mZeroRuleSize, numberInfo, NUMBER_INFO_SIZE)) {
|
||||
mDecimalPluralRules->mZeroRuleSize, numberInfo)) {
|
||||
return PluralRuleType::ZERO;
|
||||
} else if ((mDecimalPluralRules->mOneRuleSize > 0) && ParseDecimalRule(mDecimalPluralRules->mOneRule,
|
||||
mDecimalPluralRules->mOneRuleSize, numberInfo, NUMBER_INFO_SIZE)) {
|
||||
mDecimalPluralRules->mOneRuleSize, numberInfo)) {
|
||||
return PluralRuleType::ONE;
|
||||
} else if ((mDecimalPluralRules->mTwoRuleSize > 0) && ParseDecimalRule(mDecimalPluralRules->mTwoRule,
|
||||
mDecimalPluralRules->mTwoRuleSize, numberInfo, NUMBER_INFO_SIZE)) {
|
||||
mDecimalPluralRules->mTwoRuleSize, numberInfo)) {
|
||||
return PluralRuleType::TWO;
|
||||
} else if ((mDecimalPluralRules->mFewRuleSize > 0) && ParseDecimalRule(mDecimalPluralRules->mFewRule,
|
||||
mDecimalPluralRules->mFewRuleSize, numberInfo, NUMBER_INFO_SIZE)) {
|
||||
mDecimalPluralRules->mFewRuleSize, numberInfo)) {
|
||||
return PluralRuleType::FEW;
|
||||
} else if ((mDecimalPluralRules->mManyRuleSize > 0) && ParseDecimalRule(mDecimalPluralRules->mManyRule,
|
||||
mDecimalPluralRules->mManyRuleSize, numberInfo, NUMBER_INFO_SIZE)) {
|
||||
mDecimalPluralRules->mManyRuleSize, numberInfo)) {
|
||||
return PluralRuleType::MANY;
|
||||
} else {
|
||||
if (!CheckContainsIntegerRule() && numberInfo[FRACTION_NUMBER_INDEX] == 0) {
|
||||
@@ -132,8 +132,7 @@ bool PluralFormatImpl::CheckContainsIntegerRule() const
|
||||
}
|
||||
}
|
||||
|
||||
void PluralFormatImpl::ComputeDecimalInfo(double number, int integerNumber, int *numberInfo,
|
||||
const int numberInfoSize) const
|
||||
void PluralFormatImpl::ComputeDecimalInfo(double number, int integerNumber, int *numberInfo) const
|
||||
{
|
||||
int fractionNumber = 0;
|
||||
int numOfFraction = 0;
|
||||
@@ -160,12 +159,11 @@ void PluralFormatImpl::ComputeDecimalInfo(double number, int integerNumber, int
|
||||
numberInfo[NUM_OF_FRACTION_INDEX] = numOfFraction;
|
||||
}
|
||||
|
||||
bool PluralFormatImpl::ParseDecimalRule(const std::string &rule, const int ruleSize, const int *numberInfo,
|
||||
const int numberInfoSize) const
|
||||
bool PluralFormatImpl::ParseDecimalRule(const std::string &rule, const int ruleSize, const int *numberInfo) const
|
||||
{
|
||||
bool tempResult = true;
|
||||
for (int i = 0; i < ruleSize; i++) {
|
||||
bool curResult = ParseDecimalFormula(rule, ruleSize, i, numberInfo, numberInfoSize);
|
||||
bool curResult = ParseDecimalFormula(rule, ruleSize, i, numberInfo);
|
||||
int nextSymbolIndex = i + SYMBOL_LENGTH;
|
||||
if (curResult && tempResult) {
|
||||
// If next symbol is or and current result and temp result are true, the final result should be true.
|
||||
@@ -192,7 +190,7 @@ bool PluralFormatImpl::ParseDecimalRule(const std::string &rule, const int ruleS
|
||||
i += SKIP_SYMBOL_LENGTH;
|
||||
tempResult = false;
|
||||
} else if ((nextSymbolIndex >= ruleSize) &&
|
||||
!ParseDecimalFormula(rule, ruleSize, i, numberInfo, numberInfoSize)) {
|
||||
!ParseDecimalFormula(rule, ruleSize, i, numberInfo)) {
|
||||
tempResult = false;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +199,7 @@ bool PluralFormatImpl::ParseDecimalRule(const std::string &rule, const int ruleS
|
||||
}
|
||||
|
||||
bool PluralFormatImpl::ParseDecimalFormula(const std::string &rule, const int ruleSize, int &index,
|
||||
const int *numberInfo, const int numberInfoSize) const
|
||||
const int *numberInfo) const
|
||||
{
|
||||
int currentNumber = 0;
|
||||
if ((index < ruleSize) && (rule[index] == NUM_OF_FRACTION)) {
|
||||
|
||||
@@ -194,7 +194,7 @@ private:
|
||||
void FreeResource();
|
||||
static void ProcessExtension(LocaleInfo &locale, const char *key, const char *value);
|
||||
static void ConfirmTagType(const char *start, size_t length, uint8_t &type, const char* &key, const char* &value);
|
||||
static void ParseLanguageTag(LocaleInfo &locale, const char *languageTag, I18nStatus &status);
|
||||
static void ParseLanguageTag(LocaleInfo &locale, const char *languageTag);
|
||||
static bool ParseNormalSubTag(LocaleInfo &locale, const char *start, size_t tagLength, uint16_t &options,
|
||||
uint8_t &type);
|
||||
static bool IsLanguage(const char *start, uint8_t length);
|
||||
|
||||
@@ -60,7 +60,7 @@ void InitLocaleModule(JSIValue exports)
|
||||
JSI::SetModuleAPI(exports, "getLocale", LocaleModule::GetLocale);
|
||||
}
|
||||
|
||||
JSIValue LocaleModule::GetLocale(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum)
|
||||
JSIValue LocaleModule::GetLocale(const JSIValue /* thisVal */, const JSIValue* /* args */, uint8_t /* argsNum */)
|
||||
{
|
||||
JSIValue result = JSI::CreateObject();
|
||||
char *lang = GetLanguage();
|
||||
|
||||
Reference in New Issue
Block a user