mirror of
https://gitee.com/openharmony/global_i18n
synced 2024-11-23 07:00:13 +00:00
Merge branch 'master' of gitee.com:openharmony/global_i18n into master
Signed-off-by: 小城茶语 <guorunzhi@huawei.com>
This commit is contained in:
commit
7b64eb5e21
@ -77,122 +77,125 @@ ohos_shared_library("intl_util") {
|
||||
branch_protector_ret = "pac_ret"
|
||||
public_configs = [ ":intl_util_config" ]
|
||||
include_dirs = []
|
||||
sources = [
|
||||
"entity_recognition/date_time_recognition/src/date_rule_init.cpp",
|
||||
"entity_recognition/date_time_recognition/src/date_time_filter.cpp",
|
||||
"entity_recognition/date_time_recognition/src/date_time_matched.cpp",
|
||||
"entity_recognition/date_time_recognition/src/date_time_rule.cpp",
|
||||
"entity_recognition/date_time_recognition/src/date_time_sequence.cpp",
|
||||
"entity_recognition/date_time_recognition/src/rules_engine.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/border_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/code_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/find_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/negative_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/phone_number_matched.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/phone_number_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/positive_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/regex_rule.cpp",
|
||||
"entity_recognition/src/entity_recognizer.cpp",
|
||||
"src/character.cpp",
|
||||
"src/collator.cpp",
|
||||
"src/date_time_format.cpp",
|
||||
"src/holiday_manager.cpp",
|
||||
"src/i18n_break_iterator.cpp",
|
||||
"src/i18n_calendar.cpp",
|
||||
"src/i18n_normalizer.cpp",
|
||||
"src/i18n_timezone.cpp",
|
||||
"src/index_util.cpp",
|
||||
"src/locale_compare.cpp",
|
||||
"src/locale_config.cpp",
|
||||
"src/locale_data.cpp",
|
||||
"src/locale_info.cpp",
|
||||
"src/locale_matcher.cpp",
|
||||
"src/locale_util.cpp",
|
||||
"src/lunar_calendar.cpp",
|
||||
"src/measure_data.cpp",
|
||||
"src/multi_users.cpp",
|
||||
"src/number_format.cpp",
|
||||
"src/phone_number_format.cpp",
|
||||
"src/plural_rules.cpp",
|
||||
"src/relative_time_format.cpp",
|
||||
"src/signature_verifier.cpp",
|
||||
"src/system_locale_manager.cpp",
|
||||
"src/taboo.cpp",
|
||||
"src/taboo_utils.cpp",
|
||||
"src/utils.cpp",
|
||||
sources = [ "src/lunar_calendar.cpp" ]
|
||||
external_deps = [
|
||||
"hilog:libhilog",
|
||||
"icu:shared_icui18n",
|
||||
"icu:shared_icuuc",
|
||||
]
|
||||
version_script = "libintl_util.map"
|
||||
cflags_cc = [
|
||||
"-Wall",
|
||||
"-fPIC",
|
||||
"-frtti",
|
||||
]
|
||||
remove_configs = [ "//build/config/compiler:no_rtti" ]
|
||||
deps = [
|
||||
":CN_phonenumber_xml",
|
||||
":GB_phonenumber_xml",
|
||||
":bo_lang_xml",
|
||||
":common_datetime_xml",
|
||||
":common_phonenumber_xml",
|
||||
":config_locales_xml",
|
||||
":dialect_languages_xml",
|
||||
":en_Latn_lang_xml",
|
||||
":en_Latn_region_xml",
|
||||
":en_datetime_xml",
|
||||
":i18n.para",
|
||||
":i18n.para.dac",
|
||||
":i18n_param_config_xml",
|
||||
":lang_supported_locales",
|
||||
":region_supported_locales_xml",
|
||||
":root_timezone_xml",
|
||||
":timezones_xml",
|
||||
":ug_lang_xml",
|
||||
":zh_Hans_lang_xml",
|
||||
":zh_Hans_region_xml",
|
||||
":zh_Hans_timezone_xml",
|
||||
":zh_Hant_lang_xml",
|
||||
":zh_datetime_xml",
|
||||
]
|
||||
use_exceptions = true
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
"config_policy:configpolicy_util",
|
||||
"hilog:libhilog",
|
||||
"icu:icundk",
|
||||
"icu:shared_icui18n",
|
||||
"icu:shared_icuuc",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"libphonenumber:phonenumber_standard",
|
||||
"libpng:libpng",
|
||||
"libxml2:libxml2",
|
||||
"openssl:libcrypto_shared",
|
||||
"openssl:libssl_shared",
|
||||
"os_account:os_account_innerkits",
|
||||
"preferences:native_preferences",
|
||||
]
|
||||
public_external_deps = []
|
||||
defines = []
|
||||
if (i18n_support_ui) {
|
||||
public_external_deps += [
|
||||
"ability_base:base",
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
if (!build_ohos_sdk) {
|
||||
sources += [
|
||||
"entity_recognition/date_time_recognition/src/date_rule_init.cpp",
|
||||
"entity_recognition/date_time_recognition/src/date_time_filter.cpp",
|
||||
"entity_recognition/date_time_recognition/src/date_time_matched.cpp",
|
||||
"entity_recognition/date_time_recognition/src/date_time_rule.cpp",
|
||||
"entity_recognition/date_time_recognition/src/date_time_sequence.cpp",
|
||||
"entity_recognition/date_time_recognition/src/rules_engine.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/border_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/code_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/find_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/negative_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/phone_number_matched.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/phone_number_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/positive_rule.cpp",
|
||||
"entity_recognition/phone_number_recognition/src/regex_rule.cpp",
|
||||
"entity_recognition/src/entity_recognizer.cpp",
|
||||
"src/character.cpp",
|
||||
"src/collator.cpp",
|
||||
"src/date_time_format.cpp",
|
||||
"src/holiday_manager.cpp",
|
||||
"src/i18n_break_iterator.cpp",
|
||||
"src/i18n_calendar.cpp",
|
||||
"src/i18n_normalizer.cpp",
|
||||
"src/i18n_timezone.cpp",
|
||||
"src/index_util.cpp",
|
||||
"src/locale_compare.cpp",
|
||||
"src/locale_config.cpp",
|
||||
"src/locale_data.cpp",
|
||||
"src/locale_info.cpp",
|
||||
"src/locale_matcher.cpp",
|
||||
"src/locale_util.cpp",
|
||||
"src/measure_data.cpp",
|
||||
"src/multi_users.cpp",
|
||||
"src/number_format.cpp",
|
||||
"src/phone_number_format.cpp",
|
||||
"src/plural_rules.cpp",
|
||||
"src/relative_time_format.cpp",
|
||||
"src/signature_verifier.cpp",
|
||||
"src/system_locale_manager.cpp",
|
||||
"src/taboo.cpp",
|
||||
"src/taboo_utils.cpp",
|
||||
"src/utils.cpp",
|
||||
]
|
||||
version_script = "libintl_util.map"
|
||||
deps = [
|
||||
":CN_phonenumber_xml",
|
||||
":GB_phonenumber_xml",
|
||||
":bo_lang_xml",
|
||||
":common_datetime_xml",
|
||||
":common_phonenumber_xml",
|
||||
":config_locales_xml",
|
||||
":dialect_languages_xml",
|
||||
":en_Latn_lang_xml",
|
||||
":en_datetime_xml",
|
||||
":i18n.para",
|
||||
":i18n.para.dac",
|
||||
":i18n_param_config_xml",
|
||||
":lang_supported_locales",
|
||||
":region_supported_locales_xml",
|
||||
":root_timezone_xml",
|
||||
":timezones_xml",
|
||||
":ug_lang_xml",
|
||||
":zh_Hans_lang_xml",
|
||||
":zh_Hans_timezone_xml",
|
||||
":zh_Hant_HK_lang_xml",
|
||||
":zh_Hant_lang_xml",
|
||||
":zh_datetime_xml",
|
||||
]
|
||||
external_deps += [
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
"config_policy:configpolicy_util",
|
||||
"icu:icundk",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"libphonenumber:phonenumber_standard",
|
||||
"libpng:libpng",
|
||||
"libxml2:libxml2",
|
||||
"openssl:libcrypto_shared",
|
||||
"openssl:libssl_shared",
|
||||
"os_account:os_account_innerkits",
|
||||
"preferences:native_preferences",
|
||||
]
|
||||
defines += [ "SUPPORT_GRAPHICS" ]
|
||||
}
|
||||
if (is_asan) {
|
||||
defines += [ "SUPPORT_ASAN" ]
|
||||
}
|
||||
if (target_platform == "pc") {
|
||||
defines += [ "SUPPORT_MULTI_USER" ]
|
||||
public_external_deps = []
|
||||
defines = []
|
||||
if (i18n_support_ui) {
|
||||
public_external_deps += [
|
||||
"ability_base:base",
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
]
|
||||
external_deps += [
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
]
|
||||
defines += [ "SUPPORT_GRAPHICS" ]
|
||||
}
|
||||
if (is_asan) {
|
||||
defines += [ "SUPPORT_ASAN" ]
|
||||
}
|
||||
if (target_platform == "pc") {
|
||||
defines += [ "SUPPORT_MULTI_USER" ]
|
||||
}
|
||||
}
|
||||
install_images = [ system_base_dir ]
|
||||
relative_install_dir = "platformsdk"
|
||||
@ -292,6 +295,13 @@ ohos_prebuilt_etc("zh_Hant_lang_xml") {
|
||||
subsystem_name = "global"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("zh_Hant_HK_lang_xml") {
|
||||
source = "//base/global/i18n/frameworks/intl/etc/lang/zh-Hant-HK.xml"
|
||||
module_install_dir = "etc/ohos_lang_config/"
|
||||
part_name = "i18n"
|
||||
subsystem_name = "global"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("bo_lang_xml") {
|
||||
source = "//base/global/i18n/frameworks/intl/etc/lang/bo.xml"
|
||||
module_install_dir = "etc/ohos_lang_config/"
|
||||
@ -341,20 +351,6 @@ ohos_prebuilt_etc("region_supported_locales_xml") {
|
||||
subsystem_name = "global"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("zh_Hans_region_xml") {
|
||||
source = "//base/global/i18n/frameworks/intl/etc/region/zh-Hans.xml"
|
||||
module_install_dir = "usr/ohos_locale_config/region/"
|
||||
part_name = "i18n"
|
||||
subsystem_name = "global"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("en_Latn_region_xml") {
|
||||
source = "//base/global/i18n/frameworks/intl/etc/region/en-Latn-US.xml"
|
||||
module_install_dir = "usr/ohos_locale_config/region/"
|
||||
part_name = "i18n"
|
||||
subsystem_name = "global"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("dialect_languages_xml") {
|
||||
source = "//base/global/i18n/frameworks/intl/etc/dialect_languages.xml"
|
||||
module_install_dir = "usr/ohos_locale_config/"
|
||||
|
@ -35,6 +35,10 @@ int DateTimeFilter::GetType(std::string& name)
|
||||
{
|
||||
int32_t status = 0;
|
||||
int key = ConvertString2Int(name, status);
|
||||
if (status == -1) {
|
||||
HILOG_ERROR_I18N("DateTimeFilter::GetType: convert %{public}s to Int failed.", name.c_str());
|
||||
return FilterType::TYPE_NULL;
|
||||
}
|
||||
int type;
|
||||
// 19999 and 30000 are the matching rule numbers.
|
||||
if (key > 19999 && key < 30000) {
|
||||
@ -95,7 +99,7 @@ std::vector<MatchedDateTimeInfo> DateTimeFilter::FilterByRules(icu::UnicodeStrin
|
||||
for (auto& clearMatch : clears) {
|
||||
// remove the time within the filter range.
|
||||
if (match.GetBegin() >= clearMatch.GetBegin() && match.GetEnd() <= clearMatch.GetEnd()) {
|
||||
matches.erase(matchIterator);
|
||||
matchIterator = matches.erase(matchIterator);
|
||||
isDelete = true;
|
||||
break;
|
||||
}
|
||||
@ -181,7 +185,7 @@ std::vector<MatchedDateTimeInfo> DateTimeFilter::FilterOverlaySecond(std::vector
|
||||
// if one time within another time, the larger one is retained.
|
||||
if ((currentMatch.GetBegin() > match.GetBegin() && currentMatch.GetEnd() <= match.GetEnd()) ||
|
||||
(currentMatch.GetBegin() == match.GetBegin() && currentMatch.GetEnd() < match.GetEnd())) {
|
||||
matchList.erase(matchIterator);
|
||||
matchIterator = matchList.erase(matchIterator);
|
||||
continue;
|
||||
} else if (currentMatch.GetBegin() <= match.GetBegin() && currentMatch.GetEnd() >= match.GetEnd()) {
|
||||
valid = false;
|
||||
|
@ -53,7 +53,7 @@ std::vector<MatchedDateTimeInfo> RulesEngine::Match(icu::UnicodeString& message)
|
||||
icu::UnicodeString regex = this->patterns[key];
|
||||
icu::RegexPattern* pattern = icu::RegexPattern::compile(regex,
|
||||
URegexpFlag::UREGEX_CASE_INSENSITIVE, status);
|
||||
if (pattern == nullptr) {
|
||||
if (pattern == nullptr || U_FAILURE(status)) {
|
||||
HILOG_ERROR_I18N("Match failed because pattern is nullptr.");
|
||||
return matches;
|
||||
}
|
||||
|
@ -35,6 +35,9 @@ private:
|
||||
icu::UnicodeString regex;
|
||||
UErrorCode status;
|
||||
std::string insensitive;
|
||||
static const std::string CONTAIN_STR;
|
||||
static const std::string CONTAIN_OR_INTERSECT_STR;
|
||||
static const std::string TRUE_STR;
|
||||
};
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
|
@ -19,13 +19,17 @@
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
const std::string BorderRule::CONTAIN_STR = "CONTAIN";
|
||||
const std::string BorderRule::CONTAIN_OR_INTERSECT_STR = "CONTAIN_OR_INTERSECT";
|
||||
const std::string BorderRule::TRUE_STR = "True";
|
||||
|
||||
BorderRule::BorderRule(icu::UnicodeString& regex, std::string& insensitive, std::string& type)
|
||||
{
|
||||
this->regex = regex;
|
||||
if (type == "CONTAIN") {
|
||||
if (type.compare(CONTAIN_STR) == 0) {
|
||||
// 9 indicates a certain execution logic of the border rule.
|
||||
this->type = 9;
|
||||
} else if (type == "CONTAIN_OR_INTERSECT") {
|
||||
} else if (type.compare(CONTAIN_OR_INTERSECT_STR) == 0) {
|
||||
// 8 indicates a certain execution logic of the border rule.
|
||||
this->type = 8;
|
||||
} else {
|
||||
@ -49,7 +53,7 @@ int BorderRule::GetType()
|
||||
icu::RegexPattern* BorderRule::GetPattern()
|
||||
{
|
||||
// Sets whether regular expression matching is case sensitive
|
||||
if (insensitive == "True") {
|
||||
if (insensitive.compare(TRUE_STR) == 0) {
|
||||
return icu::RegexPattern::compile(this->regex, URegexpFlag::UREGEX_CASE_INSENSITIVE, this->status);
|
||||
} else {
|
||||
return icu::RegexPattern::compile(this->regex, 0, this->status);
|
||||
|
@ -13,7 +13,7 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
<i18n_param_config>
|
||||
<supported_regions>AD,AE,AF,AG,AI,AL,AM,AO,AR,AS,AT,AU,AW,AX,AZ,BA,BB,BD,BE,BF,BG,BH,BI,BJ,BL,BM,BN,BO,BQ,BR,BS,BW,BY,BZ,CA,CC,CD,CF,CG,CH,CI,CK,CL,CM,CN,CO,CR,CU,CV,CW,CX,CY,CZ,DE,DG,DJ,DK,DM,DO,DZ,EA,EC,EE,EG,ER,ES,ET,FI,FJ,FK,FM,FO,FR,GA,GB,GD,GE,GF,GG,GH,GI,GL,GM,GN,GP,GQ,GR,GT,GU,GW,GY,HK,HN,HR,HT,HU,IC,ID,IE,IL,IM,IN,IO,IQ,IR,IS,IT,JE,JM,JO,JP,KE,KG,KH,KI,KM,KN,KR,KW,KY,KZ,LA,LB,LC,LI,LK,LR,LS,LT,LU,LV,LY,MA,MC,MD,ME,MF,MG,MH,MK,ML,MM,MN,MO,MP,MQ,MR,MS,MT,MU,MV,MW,MX,MY,MZ,NA,NC,NE,NF,NG,NI,NL,NO,NP,NR,NU,NZ,OM,PA,PE,PF,PG,PH,PK,PL,PM,PN,PR,PS,PT,PW,PY,QA,RE,RO,RS,RU,RW,SA,SB,SC,SD,SE,SG,SH,SI,SJ,SK,SL,SM,SN,SO,SR,SS,ST,SV,SX,SY,SZ,TC,TD,TG,TH,TJ,TK,TL,TM,TN,TO,TR,TT,TV,TW,TZ,UA,UG,UM,US,UY,UZ,VA,VC,VE,VG,VI,VN,VU,WF,WS,YE,YT,ZA,ZM,ZW</supported_regions>
|
||||
<supported_regions>AD,AE,AF,AG,AI,AL,AM,AO,AR,AS,AT,AU,AW,AX,AZ,BA,BB,BD,BE,BF,BG,BH,BI,BJ,BL,BM,BN,BO,BQ,BR,BS,BT,BW,BY,BZ,CA,CC,CD,CF,CG,CH,CI,CK,CL,CM,CN,CO,CR,CU,CV,CW,CX,CY,CZ,DE,DG,DJ,DK,DM,DO,DZ,EA,EC,EE,EG,ER,ES,ET,FI,FJ,FK,FM,FO,FR,GA,GB,GD,GE,GF,GG,GH,GI,GL,GM,GN,GP,GQ,GR,GT,GU,GW,GY,HK,HN,HR,HT,HU,IC,ID,IE,IL,IM,IN,IO,IQ,IR,IS,IT,JE,JM,JO,JP,KE,KG,KH,KI,KM,KN,KR,KW,KY,KZ,LA,LB,LC,LI,LK,LR,LS,LT,LU,LV,LY,MA,MC,MD,ME,MF,MG,MH,MK,ML,MM,MN,MO,MP,MQ,MR,MS,MT,MU,MV,MW,MX,MY,MZ,NA,NC,NE,NF,NG,NI,NL,NO,NP,NR,NU,NZ,OM,PA,PE,PF,PG,PH,PK,PL,PM,PN,PR,PS,PT,PW,PY,QA,RE,RO,RS,RU,RW,SA,SB,SC,SD,SE,SG,SH,SI,SJ,SK,SL,SM,SN,SO,SR,SS,ST,SV,SX,SY,SZ,TC,TD,TG,TH,TJ,TK,TL,TM,TN,TO,TR,TT,TV,TW,TZ,UA,UG,UM,US,UY,UZ,VA,VC,VE,VG,VI,VN,VU,WF,WS,YE,YT,ZA,ZM,ZW</supported_regions>
|
||||
<white_languages>zh-Hans,en-Latn-US,zh-Hant,bo,ug</white_languages>
|
||||
<forbidden_regions></forbidden_regions>
|
||||
<forbidden_languages></forbidden_languages>
|
||||
|
@ -25,6 +25,10 @@
|
||||
<id>zh-Hant</id>
|
||||
<display_name>བརྡ་རྙིང་རྒྱ་ཡིག</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>zh-Hant-HK</id>
|
||||
<display_name>བརྡ་རྙིང་རྒྱ་ཡིག(ཀྲུང་གོའི་ཞང་ཀང་།)</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>ro</id>
|
||||
<display_name>རོ་མ་ནི་ཡའི་སྐད།</display_name>
|
||||
|
@ -25,6 +25,10 @@
|
||||
<id>zh-Hant</id>
|
||||
<display_name>Traditional Chinese</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>zh-Hant-HK</id>
|
||||
<display_name>Traditional Chinese(Hong Kong, China)</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>ro</id>
|
||||
<display_name>Romanian</display_name>
|
||||
|
@ -16,6 +16,7 @@
|
||||
<item>en-Latn</item>
|
||||
<item>zh-Hans</item>
|
||||
<item>zh-Hant</item>
|
||||
<item>zh-Hant-HK</item>
|
||||
<item>bo</item>
|
||||
<item>ug</item>
|
||||
</supported_locales>
|
@ -17,6 +17,10 @@
|
||||
<id>zh-Hant</id>
|
||||
<display_name>ئەنئەنىۋىي خەنزۇچە</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>zh-Hant-HK</id>
|
||||
<display_name>ئەنئەنىۋىي خەنزۇچە (جۇڭگو شياڭگاڭ)</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>ro</id>
|
||||
<display_name>رومىنچە</display_name>
|
||||
|
@ -25,6 +25,10 @@
|
||||
<id>zh-Hant</id>
|
||||
<display_name>繁体中文</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>zh-Hant-HK</id>
|
||||
<display_name>繁体中文(中国香港)</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>ro</id>
|
||||
<display_name>罗马尼亚文</display_name>
|
||||
|
@ -1,28 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<regions>
|
||||
<region>
|
||||
<id>HK</id>
|
||||
<display_name>Hong Kong (China)</display_name>
|
||||
</region>
|
||||
<region>
|
||||
<id>MO</id>
|
||||
<display_name>Macao (China)</display_name>
|
||||
</region>
|
||||
<region>
|
||||
<id>TW</id>
|
||||
<display_name>Taiwan (China)</display_name>
|
||||
</region>
|
||||
</regions>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<languages>
|
||||
<lang>
|
||||
<id>zh</id>
|
||||
<display_name>中文</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>zh-Hans</id>
|
||||
<display_name>簡體中文</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>zh-Hant</id>
|
||||
<display_name>繁體中文</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>zh-Hant-HK</id>
|
||||
<display_name>繁體中文(中國香港)</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>ro</id>
|
||||
<display_name>羅馬尼亞文</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>fa</id>
|
||||
<display_name>波斯文</display_name>
|
||||
</lang>
|
||||
</languages>
|
@ -25,6 +25,10 @@
|
||||
<id>zh-Hant</id>
|
||||
<display_name>繁體中文</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>zh-Hant-HK</id>
|
||||
<display_name>繁體中文(中國香港)</display_name>
|
||||
</lang>
|
||||
<lang>
|
||||
<id>ro</id>
|
||||
<display_name>羅馬尼亞文</display_name>
|
||||
|
@ -13,6 +13,4 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
<supported_regions>
|
||||
<item>en-Latn-US</item>
|
||||
<item>zh-Hans</item>
|
||||
</supported_regions>
|
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<regions>
|
||||
<region>
|
||||
<id>HK</id>
|
||||
<display_name>中国香港</display_name>
|
||||
</region>
|
||||
<region>
|
||||
<id>MO</id>
|
||||
<display_name>中国澳门</display_name>
|
||||
</region>
|
||||
<region>
|
||||
<id>TW</id>
|
||||
<display_name>中国台湾</display_name>
|
||||
</region>
|
||||
</regions>
|
@ -152,6 +152,7 @@ private:
|
||||
static const char *DIALECT_LANGS_PATH;
|
||||
static const char *DIALECT_LANGS_NAME;
|
||||
static const char *REGION_PATH;
|
||||
static const std::string HOUR_EVENT_DATA;
|
||||
static std::mutex dialectLocaleMutex;
|
||||
static std::mutex region2DisplayNameMutex;
|
||||
static std::mutex locale2DisplayNameMutex;
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/calendar.h"
|
||||
#include "unicode/ucal.h"
|
||||
#include "unicode/utypes.h"
|
||||
@ -39,6 +38,7 @@ public:
|
||||
|
||||
private:
|
||||
bool VerifyDate(int32_t year, int32_t month, int32_t day);
|
||||
void ConvertDate(int32_t& year, int32_t& month, int32_t& day);
|
||||
void CalcDaysFromBaseDate();
|
||||
void SolorDateToLunarDate();
|
||||
void AdjustLeapMonth(int32_t& i, int32_t tempDaysCounts, int32_t leapMonth);
|
||||
@ -46,7 +46,7 @@ private:
|
||||
bool IsGregorianLeapYear(int32_t year);
|
||||
static std::unordered_map<int32_t, int32_t> daysOfMonth;
|
||||
static std::unordered_map<int32_t, int32_t> accDaysOfMonth;
|
||||
static std::vector<int> lunarDateInfo;
|
||||
static std::vector<uint32_t> lunarDateInfo;
|
||||
static const int32_t VALID_START_YEAR = 1900;
|
||||
static const int32_t VALID_END_YEAR = 2100;
|
||||
static const int32_t VALID_START_MONTH = 1;
|
||||
@ -73,8 +73,7 @@ private:
|
||||
bool isLeapMonth = false;
|
||||
bool isGregorianLeapYear = false;
|
||||
bool isValidDate = false;
|
||||
|
||||
// icu::Calendar* gregorianCalendar;
|
||||
icu::Calendar* calendar_;
|
||||
};
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
|
@ -64,7 +64,7 @@ private:
|
||||
UDateRelativeDateTimeFormatterStyle style = UDAT_STYLE_LONG;
|
||||
bool createSuccess = false;
|
||||
static const char *DEVICE_TYPE_NAME;
|
||||
static const int BUFFER_LEN = 10;
|
||||
static constexpr int CONFIG_LEN = 128;
|
||||
static std::unordered_map<std::string, URelativeDateTimeUnit> relativeUnits;
|
||||
static std::unordered_map<std::string, UDateRelativeDateTimeFormatterStyle> relativeFormatStyle;
|
||||
static std::unordered_map<std::string, std::string> defaultFormatStyle;
|
||||
|
@ -52,6 +52,7 @@ bool CheckSystemPermission();
|
||||
size_t ConvertBytesToSizeT(const char *byteArray);
|
||||
std::set<std::string> GetTimeZoneAvailableIDs(I18nErrorCode &errorCode);
|
||||
bool RegexSearchNoExcept(const std::string& str, std::smatch& match, const std::regex& regex);
|
||||
std::string LocaleEncode(const std::string& locale);
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
@ -78,7 +78,7 @@ Collator::Collator(std::vector<std::string> &localeTags, std::map<std::string, s
|
||||
for (size_t i = 0; i < localeTags.size(); i++) {
|
||||
std::string curLocale = localeTags[i];
|
||||
locale = icu::Locale::forLanguageTag(icu::StringPiece(curLocale), status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ I18nCalendar::I18nCalendar(std::string localeTag)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale tempLocale = icu::Locale::forLanguageTag(localeTag, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
calendar_ = new icu::GregorianCalendar(status);
|
||||
if (!U_SUCCESS(status)) {
|
||||
if (calendar_ != nullptr) {
|
||||
@ -54,7 +54,7 @@ I18nCalendar::I18nCalendar(std::string localeTag)
|
||||
return;
|
||||
}
|
||||
calendar_ = icu::Calendar::createInstance(tempLocale, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
if (calendar_ != nullptr) {
|
||||
delete calendar_;
|
||||
}
|
||||
@ -66,7 +66,7 @@ I18nCalendar::I18nCalendar(std::string localeTag, CalendarType type)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale tempLocale = icu::Locale::forLanguageTag(localeTag, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
calendar_ = new icu::GregorianCalendar(status);
|
||||
if (!U_SUCCESS(status)) {
|
||||
if (calendar_ != nullptr) {
|
||||
@ -310,7 +310,7 @@ std::string I18nCalendar::GetDisplayName(std::string &displayLocaleTag)
|
||||
}
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale displayLocale = icu::Locale::forLanguageTag(displayLocaleTag, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return PseudoLocalizationProcessor("");
|
||||
}
|
||||
icu::LocaleDisplayNames *dspName = icu::LocaleDisplayNames::createInstance(displayLocale);
|
||||
|
@ -656,7 +656,7 @@ int32_t I18nTimeZone::GetOffset(double date)
|
||||
return 0;
|
||||
}
|
||||
timezone->getOffset(date, (UBool)local, rawOffset, dstOffset, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return 0;
|
||||
}
|
||||
return rawOffset + dstOffset;
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
#include "index_util.h"
|
||||
|
||||
#include "i18n_hilog.h"
|
||||
#include "locale_config.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "string"
|
||||
@ -27,8 +28,13 @@ namespace I18n {
|
||||
IndexUtil::IndexUtil(const std::string &localeTag)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
if (localeTag == "") {
|
||||
icu::Locale locale(LocaleConfig::GetSystemLocale().c_str());
|
||||
if (localeTag.empty()) {
|
||||
std::string sysLocale = LocaleConfig::GetSystemLocale();
|
||||
if (sysLocale.empty()) {
|
||||
HILOG_ERROR_I18N("IndexUtil::IndexUtil: get system locale failed.");
|
||||
return;
|
||||
}
|
||||
icu::Locale locale(sysLocale.c_str());
|
||||
index = std::make_unique<icu::AlphabeticIndex>(locale, status);
|
||||
} else {
|
||||
icu::Locale locale(localeTag.c_str());
|
||||
|
@ -81,6 +81,7 @@ const char *LocaleConfig::secondRootTag = "lang";
|
||||
const char *LocaleConfig::rootRegion = "regions";
|
||||
const char *LocaleConfig::secondRootRegion = "region";
|
||||
const char *LocaleConfig::NUMBER_SYSTEM_KEY = "-nu-";
|
||||
const std::string LocaleConfig::HOUR_EVENT_DATA = "24HourChange";
|
||||
unordered_set<string> LocaleConfig::supportedLocales;
|
||||
unordered_set<string> LocaleConfig::supportLocales;
|
||||
unordered_set<string> LocaleConfig::supportedRegions;
|
||||
@ -213,6 +214,7 @@ static unordered_map<string, string> g_languageMap = {
|
||||
{ "my-Qaag", "my-Qaag" },
|
||||
{ "es-Latn-419", "es-419" },
|
||||
{ "es-Latn-US", "es-419" },
|
||||
{ "es-US", "es-419" },
|
||||
{ "az-Latn", "az-Latn" },
|
||||
{ "bs-Latn", "bs-Latn" },
|
||||
{ "en-Latn-US", "en" },
|
||||
@ -247,13 +249,13 @@ string GetDisplayLanguageInner(const string &language, const string &displayLoca
|
||||
if (!language.compare(0, 2, "zh") || !language.compare(0, 2, "fa") || !language.compare(0, 2, "ro")) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale displayLocale = icu::Locale::forLanguageTag(displayLocaleTag.c_str(), status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
icu::LocaleDisplayNames *dspNames = icu::LocaleDisplayNames::createInstance(displayLocale,
|
||||
UDialectHandling::ULDN_DIALECT_NAMES);
|
||||
icu::Locale tempLocale = icu::Locale::forLanguageTag(language.c_str(), status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
if (dspNames != nullptr) {
|
||||
@ -263,11 +265,11 @@ string GetDisplayLanguageInner(const string &language, const string &displayLoca
|
||||
} else {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale displayLoc = icu::Locale::forLanguageTag(displayLocaleTag, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
icu::Locale locale = icu::Locale::forLanguageTag(language, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
locale.getDisplayName(displayLoc, unistr);
|
||||
@ -637,21 +639,21 @@ string LocaleConfig::GetMainLanguage(const string &language)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale origin = icu::Locale::forLanguageTag(language, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
origin.addLikelySubtags(status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
icu::LocaleBuilder builder = icu::LocaleBuilder().setLanguage(origin.getLanguage()).
|
||||
setScript(origin.getScript()).setRegion(origin.getCountry());
|
||||
icu::Locale temp = builder.setExtension('u', "").build(status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
string fullLanguage = temp.toLanguageTag<string>(status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
if (dialectMap.find(fullLanguage) != dialectMap.end()) {
|
||||
@ -659,11 +661,11 @@ string LocaleConfig::GetMainLanguage(const string &language)
|
||||
}
|
||||
builder.setRegion("");
|
||||
temp = builder.build(status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
fullLanguage = temp.toLanguageTag<string>(status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
return fullLanguage;
|
||||
@ -676,11 +678,11 @@ string LocaleConfig::GetDisplayLanguage(const string &language, const string &di
|
||||
if (adjust == language) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale displayLoc = icu::Locale::forLanguageTag(displayLocale, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return PseudoLocalizationProcessor("");
|
||||
}
|
||||
icu::Locale locale = icu::Locale::forLanguageTag(language, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return PseudoLocalizationProcessor("");
|
||||
}
|
||||
icu::UnicodeString unistr;
|
||||
@ -907,7 +909,7 @@ string LocaleConfig::GetDisplayOverrideRegion(const std::string ®ion, const s
|
||||
return region2DisplayName.at(region);
|
||||
} else {
|
||||
icu::Locale locale = icu::Locale::forLanguageTag(displayLocale, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
if (IsValidRegion(region)) {
|
||||
@ -937,11 +939,11 @@ string LocaleConfig::GetDisplayRegion(const string ®ion, const string &displa
|
||||
if (country.length() == 0) {
|
||||
return PseudoLocalizationProcessor("");
|
||||
}
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return PseudoLocalizationProcessor("");
|
||||
}
|
||||
icu::Locale locale = icu::Locale::forLanguageTag(displayLocale, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return PseudoLocalizationProcessor("");
|
||||
}
|
||||
icu::UnicodeString unistr;
|
||||
@ -1197,6 +1199,8 @@ I18nErrorCode LocaleConfig::SetSystemLanguage(const std::string &languageTag)
|
||||
languageTag.c_str());
|
||||
return I18nErrorCode::INVALID_LANGUAGE_TAG;
|
||||
}
|
||||
std::string languageCode = LocaleEncode(languageTag);
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemLanguage: set language %{public}s.", languageCode.c_str());
|
||||
// save old language, reset system language to old language if update locale failed.
|
||||
std::string oldLanguageTag = GetSystemLanguage();
|
||||
if (SetParameter(LANGUAGE_KEY, languageTag.data()) != 0) {
|
||||
@ -1222,6 +1226,8 @@ I18nErrorCode LocaleConfig::SetSystemRegion(const std::string ®ionTag)
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion %{public}s is not valid region tag.", regionTag.c_str());
|
||||
return I18nErrorCode::INVALID_REGION_TAG;
|
||||
}
|
||||
std::string regionCode = LocaleEncode(regionTag);
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion: set region %{public}s.", regionCode.c_str());
|
||||
return SetSystemLocale(UpdateRegionOfLocale(regionTag));
|
||||
}
|
||||
|
||||
@ -1231,6 +1237,8 @@ I18nErrorCode LocaleConfig::SetSystemLocale(const std::string &localeTag)
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemLocale %{public}s is not a valid locale tag.", localeTag.c_str());
|
||||
return I18nErrorCode::INVALID_LOCALE_TAG;
|
||||
}
|
||||
std::string localeCode = LocaleEncode(localeTag);
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion: set locale %{public}s.", localeCode.c_str());
|
||||
if (SetParameter(LOCALE_KEY, localeTag.data()) != 0) {
|
||||
return I18nErrorCode::UPDATE_SYSTEM_LOCALE_FAILED;
|
||||
}
|
||||
@ -1259,6 +1267,7 @@ I18nErrorCode LocaleConfig::Set24HourClock(const std::string &option)
|
||||
HILOG_ERROR_I18N("LocaleConfig::Set24HourClock invalid 24 Hour clock tag: %{public}s", option.c_str());
|
||||
return I18nErrorCode::INVALID_24_HOUR_CLOCK_TAG;
|
||||
}
|
||||
HILOG_ERROR_I18N("LocaleConfig::Set24HourClock: update 24 hour clock %{public}s", option.c_str());
|
||||
if (SetParameter(HOUR_KEY, option.data()) != 0) {
|
||||
HILOG_ERROR_I18N("LocaleConfig::Set24HourClock update 24 hour clock failed with option=%{public}s",
|
||||
option.c_str());
|
||||
@ -1351,6 +1360,9 @@ I18nErrorCode LocaleConfig::PublishCommonEvent(const std::string &eventType)
|
||||
OHOS::AAFwk::Want localeChangeWant;
|
||||
localeChangeWant.SetAction(eventType);
|
||||
OHOS::EventFwk::CommonEventData event(localeChangeWant);
|
||||
if (EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED.compare(eventType) == 0) {
|
||||
event.SetData(HOUR_EVENT_DATA);
|
||||
}
|
||||
if (!OHOS::EventFwk::CommonEventManager::PublishCommonEvent(event)) {
|
||||
HILOG_ERROR_I18N("LocaleConfig::PublishCommonEvent Failed to Publish event %{public}s",
|
||||
localeChangeWant.GetAction().c_str());
|
||||
|
@ -63,14 +63,14 @@ void LocaleInfo::InitLocaleInfo(const std::string &localeTag, std::map<std::stri
|
||||
ComputeFinalLocaleTag(localeTag);
|
||||
locale = icu::Locale::forLanguageTag(icu::StringPiece(finalLocaleTag), status);
|
||||
}
|
||||
if (localeTag == "" || status != U_ZERO_ERROR) {
|
||||
if (localeTag == "" || U_FAILURE(status)) {
|
||||
std::string defaultLocaleTag = LocaleConfig::GetSystemLocale();
|
||||
ResetFinalLocaleStatus();
|
||||
ComputeFinalLocaleTag(defaultLocaleTag);
|
||||
status = U_ZERO_ERROR;
|
||||
locale = icu::Locale::forLanguageTag(icu::StringPiece(finalLocaleTag), status);
|
||||
}
|
||||
if (status == U_ZERO_ERROR) {
|
||||
if (U_SUCCESS(status)) {
|
||||
localeStatus = true;
|
||||
language = locale.getLanguage();
|
||||
script = locale.getScript();
|
||||
@ -260,7 +260,7 @@ std::string LocaleInfo::Maximize()
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Locale curLocale = locale;
|
||||
curLocale.addLikelySubtags(status);
|
||||
if (status == U_ZERO_ERROR) {
|
||||
if (U_SUCCESS(status)) {
|
||||
std::string restConfigs = "";
|
||||
if (finalLocaleTag.find("-u-") != std::string::npos) {
|
||||
restConfigs = finalLocaleTag.substr(finalLocaleTag.find("-u-"));
|
||||
@ -281,7 +281,7 @@ std::string LocaleInfo::Minimize()
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Locale curLocale = locale;
|
||||
curLocale.minimizeSubtags(status);
|
||||
if (status == U_ZERO_ERROR) {
|
||||
if (U_SUCCESS(status)) {
|
||||
std::string restConfigs = "";
|
||||
if (finalLocaleTag.find("-u-") != std::string::npos) {
|
||||
restConfigs = finalLocaleTag.substr(finalLocaleTag.find("-u-"));
|
||||
|
@ -13,12 +13,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "locale_util.h"
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
bool LocaleUtil::IsRTL(const std::string &locale)
|
||||
{
|
||||
if (locale.empty()) {
|
||||
HILOG_ERROR_I18N("LocaleUtil::IsRTL: locale is empty.");
|
||||
return false;
|
||||
}
|
||||
icu::Locale curLocale(locale.c_str());
|
||||
return curLocale.isRightToLeft();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "i18n_hilog.h"
|
||||
#include "unicode/gregocal.h"
|
||||
#include "lunar_calendar.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -48,7 +49,7 @@ std::unordered_map<int32_t, int32_t> LunarCalendar::accDaysOfMonth {
|
||||
{ 12, 334 }
|
||||
};
|
||||
|
||||
std::vector<int32_t> LunarCalendar::lunarDateInfo {
|
||||
std::vector<uint32_t> LunarCalendar::lunarDateInfo {
|
||||
0x4bd8, 0x4ae0, 0xa570, 0x54d5, 0xd260, 0xd950, 0x5554, 0x56af, 0x9ad0, 0x55d2,
|
||||
0x4ae0, 0xa5b6, 0xa4d0, 0xd250, 0xd295, 0xb54f, 0xd6a0, 0xada2, 0x95b0, 0x4977,
|
||||
0x497f, 0xa4b0, 0xb4b5, 0x6a50, 0x6d40, 0xab54, 0x2b6f, 0x9570, 0x52f2, 0x4970,
|
||||
@ -74,14 +75,28 @@ std::vector<int32_t> LunarCalendar::lunarDateInfo {
|
||||
|
||||
LunarCalendar::LunarCalendar()
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
calendar_ = new icu::GregorianCalendar(status);
|
||||
if (U_FAILURE(status)) {
|
||||
HILOG_ERROR_I18N("LunarCalendar: create GregorianCalendar failed");
|
||||
if (calendar_ != nullptr) {
|
||||
delete calendar_;
|
||||
}
|
||||
calendar_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
LunarCalendar::~LunarCalendar()
|
||||
{
|
||||
if (calendar_ != nullptr) {
|
||||
delete calendar_;
|
||||
}
|
||||
calendar_ = nullptr;
|
||||
}
|
||||
|
||||
bool LunarCalendar::SetGregorianDate(int32_t year, int32_t month, int32_t day)
|
||||
{
|
||||
ConvertDate(year, month, day);
|
||||
isGregorianLeapYear = false;
|
||||
isValidDate = VerifyDate(year, month, day);
|
||||
if (!isValidDate) {
|
||||
@ -95,6 +110,33 @@ bool LunarCalendar::SetGregorianDate(int32_t year, int32_t month, int32_t day)
|
||||
return true;
|
||||
}
|
||||
|
||||
void LunarCalendar::ConvertDate(int32_t& year, int32_t& month, int32_t& day)
|
||||
{
|
||||
if (calendar_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
calendar_->set(year, month - 1, day);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int32_t tempYear = calendar_->get(UCAL_YEAR, status);
|
||||
if (U_FAILURE(status)) {
|
||||
HILOG_ERROR_I18N("ConvertDate: get year failed");
|
||||
return;
|
||||
}
|
||||
int32_t tempMonth = calendar_->get(UCAL_MONTH, status) + 1;
|
||||
if (U_FAILURE(status)) {
|
||||
HILOG_ERROR_I18N("ConvertDate: get month failed");
|
||||
return;
|
||||
}
|
||||
int32_t tempDay = calendar_->get(UCAL_DATE, status);
|
||||
if (U_FAILURE(status)) {
|
||||
HILOG_ERROR_I18N("ConvertDate: get day failed");
|
||||
return;
|
||||
}
|
||||
year = tempYear;
|
||||
month = tempMonth;
|
||||
day = tempDay;
|
||||
}
|
||||
|
||||
void LunarCalendar::CalcDaysFromBaseDate()
|
||||
{
|
||||
daysCounts = DAYS_OF_YEAR * (solorYear - START_YEAR);
|
||||
@ -177,7 +219,7 @@ int32_t LunarCalendar::GetDaysPerLunarYear(int32_t lunarYear)
|
||||
return 0;
|
||||
}
|
||||
daysPerLunarYear += BASE_DAYS_PER_LUNAR_YEAR;
|
||||
for (int32_t i = 0x8000; i > 0x8; i = i >> 1) {
|
||||
for (uint32_t i = 0x8000; i > 0x8; i = i >> 1) {
|
||||
daysPerLunarYear += ((lunarDateInfo[lunarYear - START_YEAR] & i) == i) ? 1 : 0;
|
||||
}
|
||||
if (((lunarDateInfo[lunarYear - START_YEAR] & 0xf) != 0) &&
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <cmath>
|
||||
#include "i18n_hilog.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -33,6 +34,7 @@ const int BASE_VALUE_SIZE = 2;
|
||||
const int FACTOR_SIZE = 2;
|
||||
const int CHAR_OFFSET = 48;
|
||||
const int MAX_UNIT_NUM = 500;
|
||||
const size_t REGION_SIZE = 2;
|
||||
|
||||
const std::unordered_map<std::string, std::vector<std::string>> USAGE_001 {
|
||||
{ "area-land-agricult", { "hectare" } },
|
||||
@ -308,6 +310,10 @@ const std::unordered_map<std::string, double> POWER_VALUE {
|
||||
|
||||
uint32_t GetMask(const string ®ion)
|
||||
{
|
||||
if (region.length() < REGION_SIZE) {
|
||||
HILOG_ERROR_I18N("GetMask: region is invalid.");
|
||||
return 0;
|
||||
}
|
||||
uint32_t firstChar = (region.c_str()[0] - CHAR_OFFSET);
|
||||
uint32_t secondChar = (region.c_str()[1] - CHAR_OFFSET);
|
||||
return (firstChar << REGION_OFFSET) | secondChar;
|
||||
|
@ -95,7 +95,7 @@ NumberFormat::NumberFormat(const std::vector<std::string> &localeTags, std::map<
|
||||
for (size_t i = 0; i < localeTags.size(); i++) {
|
||||
std::string curLocale = localeTags[i];
|
||||
locale = icu::Locale::forLanguageTag(icu::StringPiece(curLocale), status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
@ -302,9 +302,6 @@ std::string PhoneNumberFormat::getPhoneLocationName(
|
||||
locName = recvArr;
|
||||
}
|
||||
}
|
||||
if (locName.empty()) {
|
||||
locName = LocaleConfig::GetDisplayRegion(regionCode, displayLocale, false);
|
||||
}
|
||||
return locName;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ void PluralRules::InitPluralRules(std::vector<std::string> &localeTags,
|
||||
for (size_t i = 0; i < localeTags.size(); i++) {
|
||||
std::string curLocale = localeTags[i];
|
||||
locale = icu::Locale::forLanguageTag(icu::StringPiece(curLocale), status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ RelativeTimeFormat::RelativeTimeFormat(const std::vector<std::string> &localeTag
|
||||
for (size_t i = 0; i < localeTags.size(); i++) {
|
||||
std::string curLocale = localeTags[i];
|
||||
locale = icu::Locale::forLanguageTag(icu::StringPiece(curLocale), status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
@ -223,8 +223,8 @@ void RelativeTimeFormat::GetResolvedOptions(std::map<std::string, std::string> &
|
||||
|
||||
void RelativeTimeFormat::SetDefaultStyle()
|
||||
{
|
||||
char value[BUFFER_LEN];
|
||||
int code = GetParameter(DEVICE_TYPE_NAME, "", value, BUFFER_LEN);
|
||||
char value[CONFIG_LEN];
|
||||
int code = GetParameter(DEVICE_TYPE_NAME, "", value, CONFIG_LEN);
|
||||
if (code > 0) {
|
||||
std::string deviceType = value;
|
||||
if (defaultFormatStyle.find(deviceType) != defaultFormatStyle.end()) {
|
||||
|
@ -13,13 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cerrno>
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <dirent.h>
|
||||
#include <iomanip>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
@ -40,6 +41,8 @@ using namespace std;
|
||||
static const std::string PSEUDO_LOCALE_TAG = "en-XA";
|
||||
static const std::string PSEUDO_START_TAG = "{";
|
||||
static const std::string PSEUDO_END_TAG = "}";
|
||||
static const char CHAR_A = 'A';
|
||||
static const int32_t CHAR2INT_SIZE = 2;
|
||||
constexpr const char *TIMEZONE_LIST_CONFIG_PATH = "/system/etc/zoneinfo/timezone_list.cfg";
|
||||
constexpr const char *DISTRO_TIMEZONE_LIST_CONFIG = "/system/etc/tzdata_distro/timezone_list.cfg";
|
||||
static std::mutex validLocaleMutex;
|
||||
@ -320,6 +323,10 @@ std::set<std::string> GetTimeZoneAvailableIDs(I18nErrorCode &errorCode)
|
||||
struct stat s;
|
||||
const char *tzIdConfigPath = stat(DISTRO_TIMEZONE_LIST_CONFIG, &s) == 0 ?
|
||||
DISTRO_TIMEZONE_LIST_CONFIG : TIMEZONE_LIST_CONFIG_PATH;
|
||||
if (!CheckTzDataFilePath(tzIdConfigPath)) {
|
||||
HILOG_ERROR_I18N("GetTimeZoneAvailableIDs: check file %{public}s failed.", tzIdConfigPath);
|
||||
return availableIDs;
|
||||
}
|
||||
std::unique_ptr<char[]> resolvedPath = std::make_unique<char[]>(PATH_MAX + 1);
|
||||
if (realpath(tzIdConfigPath, resolvedPath.get()) == nullptr) {
|
||||
HILOG_ERROR_I18N("Get realpath failed, errno: %{public}d.", errno);
|
||||
@ -335,7 +342,7 @@ std::set<std::string> GetTimeZoneAvailableIDs(I18nErrorCode &errorCode)
|
||||
if (line.length() == 0) {
|
||||
break;
|
||||
}
|
||||
line = line.substr(0, line.find_last_not_of("\r\n") + 1);
|
||||
line.resize(line.find_last_not_of("\r\n") + 1);
|
||||
availableIDs.insert(line);
|
||||
}
|
||||
file.close();
|
||||
@ -347,9 +354,20 @@ bool RegexSearchNoExcept(const std::string& str, std::smatch& match, const std::
|
||||
try {
|
||||
return std::regex_search(str, match, regex);
|
||||
} catch (const std::regex_error &except) {
|
||||
HILOG_ERROR_I18N("RegexSearchNoExcept: regex_error caught %{public}s.", except.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string LocaleEncode(const std::string& locale)
|
||||
{
|
||||
std::stringstream ss;
|
||||
for (auto& c : locale) {
|
||||
int32_t number = (c == '-') ? 0 : static_cast<int32_t>(c) - static_cast<int32_t>(CHAR_A) + 1;
|
||||
ss << std::setw(CHAR2INT_SIZE) << std::setfill('0') << number;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
@ -23,13 +23,13 @@ ohos_unittest("intl_test") {
|
||||
|
||||
sources = [
|
||||
"unittest/i18n_test.cpp",
|
||||
"unittest/intl_number_format_test.cpp",
|
||||
"unittest/intl_test.cpp",
|
||||
"unittest/intl_test_extent.cpp",
|
||||
"unittest/locale_config_test.cpp",
|
||||
"unittest/mock/src/generate_ics_file.cpp",
|
||||
"unittest/mock/src/i18n_timezone_mock.cpp",
|
||||
"unittest/mock/src/phone_number_format_mock.cpp",
|
||||
"unittest/number_format_test.cpp",
|
||||
]
|
||||
include_dirs = [
|
||||
"//base/global/i18n/frameworks/intl/entity_recognition/include",
|
||||
@ -59,8 +59,9 @@ ohos_unittest("intl_test") {
|
||||
"openssl:libssl_shared",
|
||||
"preferences:native_preferences",
|
||||
]
|
||||
defines = []
|
||||
if (i18n_support_app_preferred_language) {
|
||||
defines = [ "SUPPORT_APP_PREFERRED_LANGUAGE" ]
|
||||
defines += [ "SUPPORT_APP_PREFERRED_LANGUAGE" ]
|
||||
}
|
||||
if (target_platform == "pc") {
|
||||
defines += [ "SUPPORT_MULTI_USER" ]
|
||||
|
@ -1568,6 +1568,35 @@ HWTEST_F(I18nTest, I18nFuncTest064, TestSize.Level1)
|
||||
EXPECT_EQ(day, 25);
|
||||
EXPECT_EQ(isLeap, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: I18nFuncTest065
|
||||
* @tc.desc: Test I18n lunar calendar
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(I18nTest, I18nFuncTest065, TestSize.Level1)
|
||||
{
|
||||
std::unique_ptr<LunarCalendar> ptr = std::make_unique<LunarCalendar>();
|
||||
ptr->SetGregorianDate(2024, 8, 51);
|
||||
int32_t year = ptr->GetLunarYear();
|
||||
int32_t month = ptr->GetLunarMonth();
|
||||
int32_t day = ptr->GetLunarDay();
|
||||
bool isLeap = ptr->IsLeapMonth();
|
||||
EXPECT_EQ(year, 2024);
|
||||
EXPECT_EQ(month, 8);
|
||||
EXPECT_EQ(day, 18);
|
||||
EXPECT_EQ(isLeap, false);
|
||||
|
||||
ptr->SetGregorianDate(2024, 12, 43);
|
||||
year = ptr->GetLunarYear();
|
||||
month = ptr->GetLunarMonth();
|
||||
day = ptr->GetLunarDay();
|
||||
isLeap = ptr->IsLeapMonth();
|
||||
EXPECT_EQ(year, 2024);
|
||||
EXPECT_EQ(month, 12);
|
||||
EXPECT_EQ(day, 13);
|
||||
EXPECT_EQ(isLeap, false);
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
@ -82,6 +82,7 @@ int I18nFuncTest061(void);
|
||||
int I18nFuncTest062(void);
|
||||
int I18nFuncTest063(void);
|
||||
int I18nFuncTest064(void);
|
||||
int I18nFuncTest065(void);
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
@ -1,216 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "number_format.h"
|
||||
#include "intl_test.h"
|
||||
#include "generate_ics_file.h"
|
||||
#include "signature_verifier.h"
|
||||
#include <unistd.h>
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
using namespace OHOS::Global::I18n;
|
||||
using testing::ext::TestSize;
|
||||
using namespace std;
|
||||
using namespace testing;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
/**
|
||||
* @tc.name: IntlFuncTest0099
|
||||
* @tc.desc: Test Intl NumberFormat.format
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest0099, TestSize.Level1)
|
||||
{
|
||||
string locale = "en-IN";
|
||||
string expects = "+1,23,456.79 euros";
|
||||
vector<string> locales{locale};
|
||||
string useGrouping = "true";
|
||||
string minimumIntegerDigits = "7";
|
||||
string maximumFractionDigits = "2";
|
||||
string style = "currency";
|
||||
string currency = "978";
|
||||
map<string, string> options = { { "useGrouping", useGrouping },
|
||||
{ "style", style },
|
||||
{ "currency", currency },
|
||||
{ "currencyDisplay", "name" },
|
||||
{ "currencySign", "accounting" },
|
||||
{ "signDisplay", "always" } };
|
||||
std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
|
||||
ASSERT_TRUE(numFmt != nullptr);
|
||||
string out = numFmt->Format(123456.789);
|
||||
EXPECT_EQ(out, expects);
|
||||
EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
|
||||
EXPECT_EQ(numFmt->GetStyle(), style);
|
||||
EXPECT_EQ(numFmt->GetCurrency(), "EUR");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00100
|
||||
* @tc.desc: Test Intl NumberFormat.format
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00100, TestSize.Level1)
|
||||
{
|
||||
string locale = "en-IN";
|
||||
string expects = "+1,23,456.789";
|
||||
vector<string> locales{locale};
|
||||
string useGrouping = "true";
|
||||
string minimumIntegerDigits = "7";
|
||||
string maximumFractionDigits = "2";
|
||||
string style = "currency";
|
||||
string currency = "111";
|
||||
map<string, string> options = { { "useGrouping", useGrouping },
|
||||
{ "style", style },
|
||||
{ "currency", currency },
|
||||
{ "currencyDisplay", "name" },
|
||||
{ "currencySign", "accounting" },
|
||||
{ "signDisplay", "always" } };
|
||||
std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
|
||||
ASSERT_TRUE(numFmt != nullptr);
|
||||
string out = numFmt->Format(123456.789);
|
||||
EXPECT_EQ(out, expects);
|
||||
EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
|
||||
EXPECT_EQ(numFmt->GetStyle(), style);
|
||||
EXPECT_EQ(numFmt->GetCurrency(), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00101
|
||||
* @tc.desc: Test Intl NumberFormat.format
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00101, TestSize.Level1)
|
||||
{
|
||||
string locale = "en-IN";
|
||||
string expects = "+1,23,456.789";
|
||||
vector<string> locales{locale};
|
||||
string useGrouping = "true";
|
||||
string minimumIntegerDigits = "7";
|
||||
string maximumFractionDigits = "2";
|
||||
string style = "currency";
|
||||
string currency = "a1b";
|
||||
map<string, string> options = { { "useGrouping", useGrouping },
|
||||
{ "style", style },
|
||||
{ "currency", currency },
|
||||
{ "currencyDisplay", "name" },
|
||||
{ "currencySign", "accounting" },
|
||||
{ "signDisplay", "always" } };
|
||||
std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
|
||||
ASSERT_TRUE(numFmt != nullptr);
|
||||
string out = numFmt->Format(123456.789);
|
||||
EXPECT_EQ(out, expects);
|
||||
EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
|
||||
EXPECT_EQ(numFmt->GetStyle(), style);
|
||||
EXPECT_EQ(numFmt->GetCurrency(), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00102
|
||||
* @tc.desc: Test Intl NumberFormat.format
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00102, TestSize.Level1)
|
||||
{
|
||||
string locale = "en-IN";
|
||||
string expects = "+1,23,456.789";
|
||||
vector<string> locales{locale};
|
||||
string useGrouping = "true";
|
||||
string minimumIntegerDigits = "7";
|
||||
string maximumFractionDigits = "2";
|
||||
string style = "currency";
|
||||
string currency = "a#b";
|
||||
map<string, string> options = { { "useGrouping", useGrouping },
|
||||
{ "style", style },
|
||||
{ "currency", currency },
|
||||
{ "currencyDisplay", "name" },
|
||||
{ "currencySign", "accounting" },
|
||||
{ "signDisplay", "always" } };
|
||||
std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
|
||||
ASSERT_TRUE(numFmt != nullptr);
|
||||
string out = numFmt->Format(123456.789);
|
||||
EXPECT_EQ(out, expects);
|
||||
EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
|
||||
EXPECT_EQ(numFmt->GetStyle(), style);
|
||||
EXPECT_EQ(numFmt->GetCurrency(), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00108
|
||||
* @tc.desc: Test Intl NumberFormat.format
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00108, TestSize.Level1)
|
||||
{
|
||||
string locale = "en-IN";
|
||||
string expects = "+1,23,456.789";
|
||||
vector<string> locales{locale};
|
||||
string useGrouping = "true";
|
||||
string minimumIntegerDigits = "7";
|
||||
string maximumFractionDigits = "2";
|
||||
string style = "currency";
|
||||
string currency = "ab";
|
||||
map<string, string> options = { { "useGrouping", useGrouping },
|
||||
{ "style", style },
|
||||
{ "currency", currency },
|
||||
{ "currencyDisplay", "name" },
|
||||
{ "currencySign", "accounting" },
|
||||
{ "signDisplay", "always" } };
|
||||
std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
|
||||
ASSERT_TRUE(numFmt != nullptr);
|
||||
string out = numFmt->Format(123456.789);
|
||||
EXPECT_EQ(out, expects);
|
||||
EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
|
||||
EXPECT_EQ(numFmt->GetStyle(), style);
|
||||
EXPECT_EQ(numFmt->GetCurrency(), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00109
|
||||
* @tc.desc: Test Intl NumberFormat.format
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00109, TestSize.Level1)
|
||||
{
|
||||
string locale = "en-IN";
|
||||
string expects = "+1,23,456.789";
|
||||
vector<string> locales{locale};
|
||||
string useGrouping = "true";
|
||||
string minimumIntegerDigits = "7";
|
||||
string maximumFractionDigits = "2";
|
||||
string style = "currency";
|
||||
string currency = "abcd";
|
||||
map<string, string> options = { { "useGrouping", useGrouping },
|
||||
{ "style", style },
|
||||
{ "currency", currency },
|
||||
{ "currencyDisplay", "name" },
|
||||
{ "currencySign", "accounting" },
|
||||
{ "signDisplay", "always" } };
|
||||
std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
|
||||
ASSERT_TRUE(numFmt != nullptr);
|
||||
string out = numFmt->Format(123456.789);
|
||||
EXPECT_EQ(out, expects);
|
||||
EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
|
||||
EXPECT_EQ(numFmt->GetStyle(), style);
|
||||
EXPECT_EQ(numFmt->GetCurrency(), "");
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
@ -132,13 +132,6 @@ int IntlFuncTest0099(void);
|
||||
int IntlFuncTest00100(void);
|
||||
int IntlFuncTest00101(void);
|
||||
int IntlFuncTest00102(void);
|
||||
int IntlFuncTest00103(void);
|
||||
int IntlFuncTest00104(void);
|
||||
int IntlFuncTest00105(void);
|
||||
int IntlFuncTest00106(void);
|
||||
int IntlFuncTest00107(void);
|
||||
int IntlFuncTest00108(void);
|
||||
int IntlFuncTest00109(void);
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
@ -537,6 +537,11 @@ HWTEST_F(IntlTest, IntlFuncTest0062, TestSize.Level1)
|
||||
const std::string replace = "";
|
||||
StrReplaceAll(str, target, replace);
|
||||
|
||||
std::string localeTag = "zh-Hans-CN";
|
||||
std::string localeCode = LocaleEncode(localeTag);
|
||||
std::string targetCode = "58400008334651000314";
|
||||
EXPECT_EQ(localeCode, targetCode);
|
||||
|
||||
std::string localeRule = "zh-Hans";
|
||||
DateTimeRule* dateTimeRule = new DateTimeRule(localeRule);
|
||||
DateTimeFilter* dateTimeFilter = new DateTimeFilter(localeRule, dateTimeRule);
|
||||
@ -1834,11 +1839,11 @@ HWTEST_F(IntlTest, IntlFuncTest0097, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00103
|
||||
* @tc.name: IntlFuncTest0098
|
||||
* @tc.desc: Test Intl multi users
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00103, TestSize.Level1)
|
||||
HWTEST_F(IntlTest, IntlFuncTest0098, TestSize.Level1)
|
||||
{
|
||||
#ifdef SUPPORT_MULTI_USER
|
||||
std::string path = "/data/service/el1/public/i18n/global/GlobalParamData";
|
||||
@ -1870,11 +1875,11 @@ HWTEST_F(IntlTest, IntlFuncTest00103, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00104
|
||||
* @tc.name: IntlFuncTest0099
|
||||
* @tc.desc: Test CodeRule
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00104, TestSize.Level1)
|
||||
HWTEST_F(IntlTest, IntlFuncTest0099, TestSize.Level1)
|
||||
{
|
||||
std::string isValidType = "PreSuf";
|
||||
std::string msg = "1 800 234 45";
|
||||
@ -1892,11 +1897,11 @@ HWTEST_F(IntlTest, IntlFuncTest00104, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00105
|
||||
* @tc.name: IntlFuncTest00100
|
||||
* @tc.desc: Test CodeRule
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00105, TestSize.Level1)
|
||||
HWTEST_F(IntlTest, IntlFuncTest00100, TestSize.Level1)
|
||||
{
|
||||
std::string isValidType = "PreSuf";
|
||||
std::string msg = "A-1 800 234 45 67";
|
||||
@ -1926,11 +1931,11 @@ HWTEST_F(IntlTest, IntlFuncTest00105, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00106
|
||||
* @tc.name: IntlFuncTest00101
|
||||
* @tc.desc: Test CodeRule
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00106, TestSize.Level1)
|
||||
HWTEST_F(IntlTest, IntlFuncTest00101, TestSize.Level1)
|
||||
{
|
||||
std::string isValidType = "Rawstr";
|
||||
std::string msg = "13649372A-";
|
||||
@ -1950,11 +1955,11 @@ HWTEST_F(IntlTest, IntlFuncTest00106, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IntlFuncTest00107
|
||||
* @tc.name: IntlFuncTest00102
|
||||
* @tc.desc: Test CodeRule
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IntlTest, IntlFuncTest00107, TestSize.Level1)
|
||||
HWTEST_F(IntlTest, IntlFuncTest00102, TestSize.Level1)
|
||||
{
|
||||
std::string isValidType = "Rawstr";
|
||||
std::string msg = "400A-";
|
||||
|
@ -264,17 +264,17 @@ HWTEST_F(LocaleConfigTest, LocaleConfigFuncTest010, TestSize.Level1)
|
||||
std::string languageTag = "zh-Hant-HK";
|
||||
std::string localeTag = "zh-Hant";
|
||||
std::string displayName = LocaleConfig::GetDisplayLanguage(languageTag, localeTag, true);
|
||||
EXPECT_EQ(displayName, "繁體中文");
|
||||
EXPECT_EQ(displayName, "繁體中文(中國香港)");
|
||||
|
||||
languageTag = "zh-Hant-HK";
|
||||
localeTag = "zh-Hans";
|
||||
displayName = LocaleConfig::GetDisplayLanguage(languageTag, localeTag, true);
|
||||
EXPECT_EQ(displayName, "繁体中文");
|
||||
EXPECT_EQ(displayName, "繁体中文(中国香港)");
|
||||
|
||||
languageTag = "zh-Hant-HK";
|
||||
localeTag = "en-US";
|
||||
displayName = LocaleConfig::GetDisplayLanguage(languageTag, localeTag, true);
|
||||
EXPECT_EQ(displayName, "Traditional Chinese");
|
||||
EXPECT_EQ(displayName, "Traditional Chinese(Hong Kong, China)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
1839
frameworks/intl/test/unittest/number_format_test.cpp
Normal file
1839
frameworks/intl/test/unittest/number_format_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
61
frameworks/intl/test/unittest/number_format_test.h
Normal file
61
frameworks/intl/test/unittest/number_format_test.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_GLOBAL_I18N_NUMBER_FORMAT_TEST
|
||||
#define OHOS_GLOBAL_I18N_NUMBER_FORMAT_TEST
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
int NumberFormatFuncTest001(void);
|
||||
int NumberFormatFuncTest002(void);
|
||||
int NumberFormatFuncTest003(void);
|
||||
int NumberFormatFuncTest004(void);
|
||||
int NumberFormatFuncTest005(void);
|
||||
int NumberFormatFuncTest006(void);
|
||||
int NumberFormatFuncTest007(void);
|
||||
int NumberFormatFuncTest008(void);
|
||||
int NumberFormatFuncTest009(void);
|
||||
int NumberFormatFuncTest0010(void);
|
||||
int NumberFormatFuncTest0011(void);
|
||||
int NumberFormatFuncTest0012(void);
|
||||
int NumberFormatFuncTest0013(void);
|
||||
int NumberFormatFuncTest0014(void);
|
||||
int NumberFormatFuncTest0015(void);
|
||||
int NumberFormatFuncTest0016(void);
|
||||
int NumberFormatFuncTest0017(void);
|
||||
int NumberFormatFuncTest0018(void);
|
||||
int NumberFormatFuncTest0019(void);
|
||||
int NumberFormatFuncTest0020(void);
|
||||
int NumberFormatFuncTest0021(void);
|
||||
int NumberFormatFuncTest0022(void);
|
||||
int NumberFormatFuncTest0023(void);
|
||||
int NumberFormatFuncTest0024(void);
|
||||
int NumberFormatFuncTest0025(void);
|
||||
int NumberFormatFuncTest0026(void);
|
||||
int NumberFormatFuncTest0027(void);
|
||||
int NumberFormatFuncTest0028(void);
|
||||
int NumberFormatFuncTest0029(void);
|
||||
int NumberFormatFuncTest0030(void);
|
||||
int NumberFormatFuncTest0031(void);
|
||||
int NumberFormatFuncTest0032(void);
|
||||
int NumberFormatFuncTest0033(void);
|
||||
int NumberFormatFuncTest0034(void);
|
||||
int NumberFormatFuncTest0035(void);
|
||||
int NumberFormatFuncTest0036(void);
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -116,7 +116,7 @@ string ZoneUtil::GetDefaultZone(const string country, const int32_t offset)
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
StringEnumeration *strEnum =
|
||||
TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, country.c_str(), &offset, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return "";
|
||||
}
|
||||
string ret;
|
||||
@ -160,7 +160,7 @@ void ZoneUtil::GetZoneList(const string country, const int32_t offset, vector<st
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
StringEnumeration *strEnum =
|
||||
TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, country.c_str(), &offset, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
delete strEnum;
|
||||
strEnum = nullptr;
|
||||
return;
|
||||
@ -180,16 +180,16 @@ void ZoneUtil::GetString(StringEnumeration *strEnum, string& ret)
|
||||
return;
|
||||
}
|
||||
int32_t count = strEnum->count(status);
|
||||
if ((status != U_ZERO_ERROR) || count <= 0) {
|
||||
if (U_FAILURE(status) || count <= 0) {
|
||||
return;
|
||||
}
|
||||
const UnicodeString *uniStr = strEnum->snext(status);
|
||||
if ((status != U_ZERO_ERROR) || (!uniStr)) {
|
||||
if (U_FAILURE(status) || (!uniStr)) {
|
||||
return;
|
||||
}
|
||||
UnicodeString canonicalUnistring;
|
||||
TimeZone::getCanonicalID(*uniStr, canonicalUnistring, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
canonicalUnistring.toUTF8String(ret);
|
||||
@ -203,18 +203,18 @@ void ZoneUtil::GetList(StringEnumeration *strEnum, vector<string> &retVec)
|
||||
}
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int32_t count = strEnum->count(status);
|
||||
if (count <= 0 || status != U_ZERO_ERROR) {
|
||||
if (count <= 0 || U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
while (count > 0) {
|
||||
const UnicodeString *uniStr = strEnum->snext(status);
|
||||
if ((!uniStr) || (status != U_ZERO_ERROR)) {
|
||||
if ((!uniStr) || U_FAILURE(status)) {
|
||||
retVec.clear();
|
||||
break;
|
||||
}
|
||||
UnicodeString canonicalUnistring;
|
||||
TimeZone::getCanonicalID(*uniStr, canonicalUnistring, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(status)) {
|
||||
retVec.clear();
|
||||
break;
|
||||
}
|
||||
|
@ -24,12 +24,9 @@ group("build_module") {
|
||||
ohos_shared_library("cj_i18n_ffi") {
|
||||
include_dirs = [
|
||||
"../../frameworks/intl/include",
|
||||
"../js/kits/include",
|
||||
"include",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-frtti" ]
|
||||
remove_configs = [ "//build/config/compiler:no_rtti" ]
|
||||
|
||||
if (!defined(defines)) {
|
||||
defines = []
|
||||
}
|
||||
@ -41,14 +38,44 @@ ohos_shared_library("cj_i18n_ffi") {
|
||||
]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hilog:libhilog",
|
||||
"icu:shared_icui18n",
|
||||
"icu:shared_icuuc",
|
||||
"ipc:ipc_core",
|
||||
"libphonenumber:phonenumber_standard",
|
||||
"libpng:libpng",
|
||||
"libxml2:libxml2",
|
||||
"napi:ace_napi",
|
||||
"napi:cj_bind_ffi",
|
||||
"napi:cj_bind_native",
|
||||
"preferences:native_preferences",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
sources = [
|
||||
"src/i18n_breakIterator_ffi.cpp",
|
||||
"src/i18n_breakIterator_impl.cpp",
|
||||
"src/i18n_calendar_ffi.cpp",
|
||||
"src/i18n_calendar_impl.cpp",
|
||||
"src/i18n_entity_ffi.cpp",
|
||||
"src/i18n_entity_impl.cpp",
|
||||
"src/i18n_ffi.cpp",
|
||||
"src/i18n_holiday_ffi.cpp",
|
||||
"src/i18n_holiday_impl.cpp",
|
||||
"src/i18n_index_util_ffi.cpp",
|
||||
"src/i18n_index_util_impl.cpp",
|
||||
"src/i18n_normalizer_ffi.cpp",
|
||||
"src/i18n_normalizer_impl.cpp",
|
||||
"src/i18n_phone_number_format_ffi.cpp",
|
||||
"src/i18n_phone_number_format_impl.cpp",
|
||||
"src/i18n_system_ffi.cpp",
|
||||
"src/i18n_timezone_ffi.cpp",
|
||||
"src/i18n_timezone_impl.cpp",
|
||||
"src/i18n_transliterator_ffi.cpp",
|
||||
"src/i18n_transliterator_impl.cpp",
|
||||
"src/i18n_unicode_ffi.cpp",
|
||||
"src/i18n_util_ffi.cpp",
|
||||
]
|
||||
sources = [ "i18n_ffi.cpp" ]
|
||||
} else {
|
||||
defines += [ "PREVIEWER" ]
|
||||
sources = [ "cj_i18n_mock.cpp" ]
|
||||
@ -63,6 +90,10 @@ ohos_shared_library("cj_i18n_ffi") {
|
||||
defines += [ "WINDOWS_PLATFORM" ]
|
||||
}
|
||||
|
||||
if (i18n_support_app_preferred_language) {
|
||||
defines += [ "SUPPORT_APP_PREFERRED_LANGUAGE" ]
|
||||
}
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "global"
|
||||
part_name = "i18n"
|
||||
|
35
interfaces/cj/include/i18n_breakIterator_ffi.h
Normal file
35
interfaces/cj/include/i18n_breakIterator_ffi.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_BREAKITERATOR_FFI_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_BREAKITERATOR_FFI_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT void FfiOHOSBreakIteratorSetLineBreakText(int64_t id, const char* text);
|
||||
FFI_EXPORT char* FfiOHOSBreakIteratorGetLineBreakText(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarBreakIteratorCurrent(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarBreakIteratorFirst(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarBreakIteratorLast(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarBreakIteratorNext(int64_t id, int32_t index);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarBreakIteratorPrevious(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarBreakIteratorFollowing(int64_t id, int32_t offset);
|
||||
FFI_EXPORT bool FfiOHOSCalendarBreakIteratorIsBoundary(int64_t id);
|
||||
FFI_EXPORT int64_t FfiOHOSGetLineInstance(const char* locale);
|
||||
}
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_BREAKITERATOR_FFI_H_
|
49
interfaces/cj/include/i18n_breakIterator_impl.h
Normal file
49
interfaces/cj/include/i18n_breakIterator_impl.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_BREAKITERATOR_IMPL_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_BREAKITERATOR_IMPL_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "i18n_break_iterator.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class CBreakIterator : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(CBreakIterator, FFIData)
|
||||
public:
|
||||
explicit CBreakIterator(std::string localeTag);
|
||||
~CBreakIterator() = default;
|
||||
void SetLineBreakText(const char* text);
|
||||
std::string GetLineBreakText();
|
||||
int32_t current();
|
||||
int32_t first();
|
||||
int32_t last();
|
||||
int32_t next(int32_t number);
|
||||
int32_t previous();
|
||||
int32_t following(int32_t offset);
|
||||
bool IsBoundary(int32_t offset);
|
||||
private:
|
||||
std::unique_ptr<I18nBreakIterator> brkiter_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_BREAKITERATOR_IMPL_H_
|
42
interfaces/cj/include/i18n_calendar_ffi.h
Normal file
42
interfaces/cj/include/i18n_calendar_ffi.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_CALENDAR_FFI_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_CALENDAR_FFI_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include "i18n_struct.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT void FfiOHOSCalendarSetTime(int64_t id, double milliseconds);
|
||||
FFI_EXPORT void FfiOHOSCalendarSetOfDay(int64_t id, int32_t hour, int32_t minute, int32_t second);
|
||||
FFI_EXPORT void FfiOHOSCalendarSetDate(int64_t id, int32_t year, int32_t month, int32_t day);
|
||||
FFI_EXPORT void FfiOHOSCalendarSetTimeZone(int64_t id, const char* timeZone);
|
||||
FFI_EXPORT char* FfiOHOSCalendarGetTimeZone(int64_t id);
|
||||
FFI_EXPORT void FfiOHOSCalendarSetFirstDayOfWeek(int64_t id, int32_t firstDayOfWeek);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarGetFirstDayOfWeek(int64_t id);
|
||||
FFI_EXPORT void FfiOHOSCalendarSetMinimalDaysInFirstWeek(int64_t id, int32_t minimalDaysInFirstWeek);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarGetMinimalDaysInFirstWeek(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarGet(int64_t id, char* field);
|
||||
FFI_EXPORT char* FfiOHOSCalendarGetDisplayName(int64_t id, char* locale);
|
||||
FFI_EXPORT bool FfiOHOSCalendarIsWeekend(int64_t id, CDate date);
|
||||
FFI_EXPORT void FfiOHOSCalendarAdd(int64_t id, char* field, int32_t amount, int32_t* errcode);
|
||||
FFI_EXPORT double FfiOHOSCalendarGetTimeInMillis(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSCalendarCompareDays(int64_t id, CDate date);
|
||||
FFI_EXPORT int64_t FfiOHOSGetCalendar(const char* locale, const char* type);
|
||||
}
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_CALENDAR_FFI_H_
|
58
interfaces/cj/include/i18n_calendar_impl.h
Normal file
58
interfaces/cj/include/i18n_calendar_impl.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "i18n_struct.h"
|
||||
#include "i18n_calendar.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class CCalendar : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(CCalendar, FFIData)
|
||||
public:
|
||||
explicit CCalendar(std::string localeTag, CalendarType type);
|
||||
~CCalendar() = default;
|
||||
void SetTime(double time);
|
||||
void Set(int32_t year, int32_t month, int32_t date);
|
||||
void Set(UCalendarDateFields field, int32_t value);
|
||||
std::string GetTimeZone();
|
||||
void SetTimeZone(std::string timezoneId);
|
||||
int32_t Get(UCalendarDateFields field) const;
|
||||
void Add(UCalendarDateFields field, int32_t amount);
|
||||
void SetMinimalDaysInFirstWeek(int32_t value);
|
||||
void SetFirstDayOfWeek(int32_t value);
|
||||
UDate GetTimeInMillis(void);
|
||||
int32_t GetMinimalDaysInFirstWeek(void);
|
||||
int32_t GetFirstDayOfWeek(void);
|
||||
bool IsWeekend(int64_t date, UErrorCode &status);
|
||||
bool IsWeekend(void);
|
||||
std::string GetDisplayName(std::string &displayLocaleTag);
|
||||
int32_t CompareDays(UDate date);
|
||||
|
||||
private:
|
||||
std::unique_ptr<I18nCalendar> calendar_;
|
||||
};
|
||||
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_
|
25
interfaces/cj/include/i18n_entity_ffi.h
Normal file
25
interfaces/cj/include/i18n_entity_ffi.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_ENTITY_FFI_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_ENTITY_FFI_H_
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT int64_t FfiOHOSEntityImplConstructor(char* locale, int32_t* errcode);
|
||||
FFI_EXPORT CEntityInfoItemArr FfiOHOSEntityFindEntityInfo(int64_t id, char* text);
|
||||
}
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_ENTITY_FFI_H_
|
43
interfaces/cj/include/i18n_entity_impl.h
Normal file
43
interfaces/cj/include/i18n_entity_impl.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_ENTITY_IMPL_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_ENTITY_IMPL_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "i18n_struct.h"
|
||||
#include "entity_recognizer.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class CEntity : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(CEntity, FFIData)
|
||||
public:
|
||||
explicit CEntity(std::string locale);
|
||||
~CEntity() = default;
|
||||
CEntityInfoItemArr FindEntityInfo(std::string text);
|
||||
bool InitSuccess();
|
||||
private:
|
||||
std::unique_ptr<EntityRecognizer> entityRecognizer_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_ENTITY_IMPL_H_
|
32
interfaces/cj/include/i18n_ffi.h
Normal file
32
interfaces/cj/include/i18n_ffi.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_FFI_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_FFI_H_
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include "i18n_struct.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
char* MallocCString(const std::string& origin);
|
||||
FFI_EXPORT bool FfiOHOSIsRTL(char* locale);
|
||||
CArrStr VectorStringToCArr(const std::vector<std::string>& vectorString);
|
||||
}
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_FFI_H_
|
30
interfaces/cj/include/i18n_holiday_ffi.h
Normal file
30
interfaces/cj/include/i18n_holiday_ffi.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_HOLIDAY_FFI_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_HOLIDAY_FFI_H_
|
||||
|
||||
#include <string>
|
||||
#include "i18n_calendar_ffi.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT int64_t FfiOHOSHolidayManagerImplConstructor(char* icsPath);
|
||||
FFI_EXPORT bool FfiOHOSHolidayManagerIsHoliday(int64_t id, CDate date);
|
||||
FFI_EXPORT HolidayInfoItemArr FfiOHOSHolidayManagerGetHolidayInfoItemArray(
|
||||
int64_t id, int32_t year);
|
||||
}
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_HOLIDAY_FFI_H_
|
45
interfaces/cj/include/i18n_holiday_impl.h
Normal file
45
interfaces/cj/include/i18n_holiday_impl.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_HOLIDAY_IMPL_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_HOLIDAY_IMPL_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "holiday_manager.h"
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_struct.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class CHolidayManager : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(CHolidayManager, FFIData)
|
||||
public:
|
||||
explicit CHolidayManager(char* icsPath);
|
||||
~CHolidayManager() = default;
|
||||
std::vector<HolidayInfoItem> getHolidayInfoItemArray(int32_t year);
|
||||
std::vector<HolidayInfoItem> getHolidayInfoItemArray();
|
||||
bool isHoliday();
|
||||
bool isHoliday(int32_t year, int32_t month, int32_t day);
|
||||
private:
|
||||
std::unique_ptr<HolidayManager> holidayManager_;
|
||||
};
|
||||
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_HOLIDAY_IMPL_H_
|
30
interfaces/cj/include/i18n_index_util_ffi.h
Normal file
30
interfaces/cj/include/i18n_index_util_ffi.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I18N_INDEX_UTIL_FFI_H
|
||||
#define I18N_INDEX_UTIL_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT int64_t FfiI18nIndexUtilConstructor(char* locale);
|
||||
FFI_EXPORT void FfiI18nIndexUtilAddLocale(int64_t remoteDataID, char* locale);
|
||||
FFI_EXPORT char* FfiI18nIndexUtilGetIndex(int64_t remoteDataID, char* text);
|
||||
FFI_EXPORT CArrStr FfiI18nIndexUtilGetIndexList(int64_t remoteDataID);
|
||||
}
|
||||
|
||||
#endif
|
43
interfaces/cj/include/i18n_index_util_impl.h
Normal file
43
interfaces/cj/include/i18n_index_util_impl.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_NORMALIZER_IMPL_H
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_NORMALIZER_IMPL_H
|
||||
|
||||
#include <string>
|
||||
#include "ffi_remote_data.h"
|
||||
#include "index_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class FfiI18nIndexUtil : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(FfiI18nIndexUtil, FFIData)
|
||||
public:
|
||||
explicit FfiI18nIndexUtil(std::unique_ptr<OHOS::Global::I18n::IndexUtil> indexUtil);
|
||||
~FfiI18nIndexUtil() = default;
|
||||
void addLocale(std::string locale);
|
||||
char* getIndex(std::string text);
|
||||
CArrStr getIndexList();
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::IndexUtil> indexUtil_ = nullptr;
|
||||
friend class OHOS::FFI::RuntimeType;
|
||||
friend class OHOS::FFI::TypeBase;
|
||||
};
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_
|
@ -12,17 +12,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I18N_FFI_H
|
||||
#define I18N_FFI_H
|
||||
#ifndef I18N_NORMALIZER_FFI_H
|
||||
#define I18N_NORMALIZER_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT char* FfiOHOSGetAppPreferredLanguage();
|
||||
FFI_EXPORT char* FfiI18nSystemGetSystemLanguage();
|
||||
FFI_EXPORT char* FfiI18nSystemGetSystemRegion();
|
||||
FFI_EXPORT int64_t FfiI18nNormalizerConstructor(int32_t mode);
|
||||
FFI_EXPORT char* FfiI18nNormalizerNormalize(int64_t remoteDataID, char* text);
|
||||
}
|
||||
|
||||
#endif
|
41
interfaces/cj/include/i18n_normalizer_impl.h
Normal file
41
interfaces/cj/include/i18n_normalizer_impl.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_NORMALIZER_IMPL_H
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_NORMALIZER_IMPL_H
|
||||
|
||||
#include <string>
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_normalizer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class FfiI18nNormalizer : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(FfiI18nNormalizer, FFIData)
|
||||
public:
|
||||
explicit FfiI18nNormalizer(std::unique_ptr<OHOS::Global::I18n::I18nNormalizer> normalizer);
|
||||
~FfiI18nNormalizer() = default;
|
||||
char* normalize(char* text);
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::I18nNormalizer> normalizer_ = nullptr;
|
||||
friend class OHOS::FFI::RuntimeType;
|
||||
friend class OHOS::FFI::TypeBase;
|
||||
};
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_
|
30
interfaces/cj/include/i18n_phone_number_format_ffi.h
Normal file
30
interfaces/cj/include/i18n_phone_number_format_ffi.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I18N_PHONE_NUMBER_FORMAT_FFI_H
|
||||
#define I18N_PHONE_NUMBER_FORMAT_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT int64_t FfiI18nPhoneNumberFormatConstructor(char* country, char* formatType);
|
||||
FFI_EXPORT char* FfiI18nPhoneNumberFormatFormat(int64_t remoteDataID, char* number);
|
||||
FFI_EXPORT bool FfiI18nPhoneNumberFormatIsValidNumber(int64_t remoteDataID, char* number);
|
||||
FFI_EXPORT char* FfiI18nPhoneNumberFormatGetLocationName(int64_t remoteDataID, char* number, char* locale);
|
||||
}
|
||||
|
||||
#endif
|
44
interfaces/cj/include/i18n_phone_number_format_impl.h
Normal file
44
interfaces/cj/include/i18n_phone_number_format_impl.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_PHONE_NUMBER_FORMAT_IMPL_H
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_PHONE_NUMBER_FORMAT_IMPL_H
|
||||
|
||||
#include <string>
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "phone_number_format.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class FfiI18nPhoneNumberFormat : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(FfiI18nPhoneNumberFormat, FFIData)
|
||||
public:
|
||||
explicit FfiI18nPhoneNumberFormat(std::unique_ptr<OHOS::Global::I18n::PhoneNumberFormat> phoneNumberFormat);
|
||||
~FfiI18nPhoneNumberFormat() = default;
|
||||
char* format(std::string number);
|
||||
bool isValidNumber(std::string number);
|
||||
char* getLocationNmae(std::string number, std::string locale);
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::PhoneNumberFormat> phoneNumberFormat_ = nullptr;
|
||||
friend class OHOS::FFI::RuntimeType;
|
||||
friend class OHOS::FFI::TypeBase;
|
||||
};
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_
|
84
interfaces/cj/include/i18n_struct.h
Normal file
84
interfaces/cj/include/i18n_struct.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_STRUCT_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_STRUCT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
const int32_t I18N_NOT_VALID = 890001;
|
||||
|
||||
extern "C" {
|
||||
struct UnitInfo {
|
||||
char* unit;
|
||||
char* measureSystem;
|
||||
};
|
||||
|
||||
struct CDate {
|
||||
int64_t year;
|
||||
int64_t month;
|
||||
int64_t day;
|
||||
double icuUdate;
|
||||
bool isNull;
|
||||
};
|
||||
|
||||
struct CHolidayLocalName {
|
||||
char* language;
|
||||
char* name;
|
||||
};
|
||||
|
||||
struct HolidayLocalNameArr {
|
||||
int64_t size;
|
||||
CHolidayLocalName *head;
|
||||
};
|
||||
|
||||
struct CHolidayInfoItem {
|
||||
char* baseName;
|
||||
int32_t year;
|
||||
int32_t month;
|
||||
int32_t day;
|
||||
char* language;
|
||||
HolidayLocalNameArr localNames;
|
||||
};
|
||||
|
||||
struct HolidayInfoItemArr {
|
||||
int64_t size;
|
||||
CHolidayInfoItem *head;
|
||||
};
|
||||
|
||||
struct CArrStr {
|
||||
char** data;
|
||||
int32_t length;
|
||||
};
|
||||
|
||||
struct CEntityInfoItem {
|
||||
char* type;
|
||||
int32_t begin;
|
||||
int32_t end;
|
||||
};
|
||||
|
||||
struct CEntityInfoItemArr {
|
||||
int32_t size;
|
||||
CEntityInfoItem* head;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
struct EntityInfoItem {
|
||||
std::string type;
|
||||
int32_t begin;
|
||||
int32_t end;
|
||||
};
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_STRUCT_H_
|
41
interfaces/cj/include/i18n_system_ffi.h
Normal file
41
interfaces/cj/include/i18n_system_ffi.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I18N_SYSTEM_FFI_H
|
||||
#define I18N_SYSTEM_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_struct.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT char* FfiI18nSystemGetAppPreferredLanguage();
|
||||
FFI_EXPORT char* FfiI18nSystemGetSystemLanguage();
|
||||
FFI_EXPORT char* FfiI18nSystemGetSystemRegion();
|
||||
FFI_EXPORT bool FfiI18nSystemIsSuggested(char* language, char* region, int32_t parameterStatus);
|
||||
FFI_EXPORT CArrStr FfiI18nSystemGetSystemCountries(char* language);
|
||||
FFI_EXPORT char* FfiI18nSystemGetDisplayCountry(char* country, char* locale, bool sentenceCase, int32_t* errcode);
|
||||
FFI_EXPORT bool FfiI18nSystemGetUsingLocalDigit();
|
||||
FFI_EXPORT int32_t FfiI18nSystemSetAppPreferredLanguage(char* language);
|
||||
FFI_EXPORT char* FfiI18nSystemGetFirstPreferredLanguage();
|
||||
FFI_EXPORT CArrStr FfiI18nSystemGetPreferredLanguageList();
|
||||
FFI_EXPORT bool FfiI18nSystemIs24HourClock();
|
||||
FFI_EXPORT CArrStr FfiI18nSystemGetSystemLanguages();
|
||||
FFI_EXPORT char* FfiI18nSystemGetDisplayLanguage(char* language, char* locale, bool sentenceCase, int32_t* errCode);
|
||||
FFI_EXPORT char* FfiI18nSystemGetSystemLocale();
|
||||
}
|
||||
|
||||
#endif
|
37
interfaces/cj/include/i18n_timezone_ffi.h
Normal file
37
interfaces/cj/include/i18n_timezone_ffi.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I18N_TIMEZONE_FFI_H
|
||||
#define I18N_TIMEZONE_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_struct.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT int64_t FfiI18nTimezoneConstructor(char* id, bool isZoneId);
|
||||
FFI_EXPORT CArrStr FfiI18nTimezoneGetTimezonesByLocation(double longitude, double latitude);
|
||||
FFI_EXPORT char* FfiI18nTimezoneGetCityDisplayName(char* cityID, char* locale);
|
||||
FFI_EXPORT CArrStr FfiI18nTimezoneGetAvailableZoneCityIDs();
|
||||
FFI_EXPORT CArrStr FfiI18nTimezoneGetAvailableIDs();
|
||||
FFI_EXPORT char* FfiI18nTimezoneGetDisplayName(int64_t remoteDataID,
|
||||
char* locale, bool isDST, int32_t parameterStatus);
|
||||
FFI_EXPORT int32_t FfiI18nTimezoneGetOffset(int64_t remoteDataID, double date, int32_t parameterStatus);
|
||||
FFI_EXPORT int32_t FfiI18nTimezoneGetRawOffset(int64_t remoteDataID);
|
||||
FFI_EXPORT char* FfiI18nTimezoneGetID(int64_t remoteDataID);
|
||||
}
|
||||
|
||||
#endif
|
48
interfaces/cj/include/i18n_timezone_impl.h
Normal file
48
interfaces/cj/include/i18n_timezone_impl.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_TIMEZONE_IMPL_H
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_TIMEZONE_IMPL_H
|
||||
|
||||
#include <string>
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_struct.h"
|
||||
#include "i18n_timezone.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class FfiI18nTimeZone : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(FfiI18nTimeZone, FFIData)
|
||||
public:
|
||||
explicit FfiI18nTimeZone(std::unique_ptr<OHOS::Global::I18n::I18nTimeZone> timezone_);
|
||||
~FfiI18nTimeZone() = default;
|
||||
char* getID();
|
||||
int32_t getRawOffset();
|
||||
int32_t getOffset(double date);
|
||||
char* getDisplayName();
|
||||
char* getDisplayName(std::string locale);
|
||||
char* getDisplayName(std::string locale, bool isDST);
|
||||
char* getDisplayName(bool isDST);
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::I18nTimeZone> timezone_ = nullptr;
|
||||
friend class OHOS::FFI::RuntimeType;
|
||||
friend class OHOS::FFI::TypeBase;
|
||||
};
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_
|
29
interfaces/cj/include/i18n_transliterator_ffi.h
Normal file
29
interfaces/cj/include/i18n_transliterator_ffi.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I18N_TRANSLITERATOR_FFI_H
|
||||
#define I18N_TRANSLITERATOR_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT int64_t FfiI18nTransliteratorConstructor(char* id);
|
||||
FFI_EXPORT CArrStr FfiI18nTransliteratorGetAvailableIDs();
|
||||
FFI_EXPORT char* FfiI18nTransliteratorTransform(int64_t remoteDataID, char* text);
|
||||
}
|
||||
|
||||
#endif
|
41
interfaces/cj/include/i18n_transliterator_impl.h
Normal file
41
interfaces/cj/include/i18n_transliterator_impl.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_TRANSLITERATOR_IMPL_H
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_TRANSLITERATOR_IMPL_H
|
||||
|
||||
#include <string>
|
||||
#include "ffi_remote_data.h"
|
||||
#include "unicode/translit.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
class FfiI18nTransliterator : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(FfiI18nTimeZone, FFIData)
|
||||
public:
|
||||
explicit FfiI18nTransliterator(std::unique_ptr<icu::Transliterator> transliterator_);
|
||||
~FfiI18nTransliterator() = default;
|
||||
char* transform(char* text);
|
||||
private:
|
||||
std::unique_ptr<icu::Transliterator> transliterator_ = nullptr;
|
||||
friend class OHOS::FFI::RuntimeType;
|
||||
friend class OHOS::FFI::TypeBase;
|
||||
};
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_
|
35
interfaces/cj/include/i18n_unicode_ffi.h
Normal file
35
interfaces/cj/include/i18n_unicode_ffi.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I18N_UNICODE_FFI_H
|
||||
#define I18N_UNICODE_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_struct.h"
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT char* FfiI18nUnicodeGetType(char* text);
|
||||
FFI_EXPORT bool FfiI18nUnicodeIsUpperCase(char* text);
|
||||
FFI_EXPORT bool FfiI18nUnicodeIsLowerCase(char* text);
|
||||
FFI_EXPORT bool FfiI18nUnicodeIsLetter(char* text);
|
||||
FFI_EXPORT bool FfiI18nUnicodeIsIdeograph(char* text);
|
||||
FFI_EXPORT bool FfiI18nUnicodeIsRTL(char* text);
|
||||
FFI_EXPORT bool FfiI18nUnicodeIsWhitespace(char* text);
|
||||
FFI_EXPORT bool FfiI18nUnicodeIsSpaceChar(char* text);
|
||||
FFI_EXPORT bool FfiI18nUnicodeIsDigit(char* text);
|
||||
}
|
||||
|
||||
#endif
|
33
interfaces/cj/include/i18n_util_ffi.h
Normal file
33
interfaces/cj/include/i18n_util_ffi.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef INTERFACES_CJ_INCLUDE_I18N_UTIL_FFI_H_
|
||||
#define INTERFACES_CJ_INCLUDE_I18N_UTIL_FFI_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include "i18n_struct.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT char* FfiI18nUtilUnitConvert(UnitInfo fromUnit, UnitInfo toUnit,
|
||||
double value, char* locale, char* style);
|
||||
FFI_EXPORT char* FfiI18nUtilGetDateOrder(char* locale);
|
||||
FFI_EXPORT char* FfiI18nUtilGetTimePeriodName(int32_t hour, char* locale, int32_t* errcode);
|
||||
FFI_EXPORT char* FfiI18nUtilGetThreeLetterLanguage(char* locale, int32_t* errcode);
|
||||
FFI_EXPORT char* FfiI18nUtilGetThreeLetterRegion(char* locale, int32_t* errcode);
|
||||
FFI_EXPORT char* FfiI18nUtilGetBestMatchLocale(char* locale, CArrStr localeList, int32_t* errcode);
|
||||
}
|
||||
|
||||
#endif // INTERFACES_CJ_INCLUDE_I18N_UTIL_FFI_H_
|
@ -21,6 +21,8 @@ ohos_shared_library("cj_intl_ffi") {
|
||||
"include",
|
||||
]
|
||||
|
||||
defines = []
|
||||
|
||||
deps = [ "../../../frameworks/intl:intl_util" ]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
@ -41,8 +43,8 @@ ohos_shared_library("cj_intl_ffi") {
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
sources = [
|
||||
"intl_ffi.cpp",
|
||||
"intl_impl.cpp",
|
||||
"src/intl_ffi.cpp",
|
||||
"src/intl_impl.cpp",
|
||||
]
|
||||
|
||||
if (i18n_support_app_preferred_language) {
|
||||
|
@ -242,18 +242,26 @@ RelativeTimeFormatImpl::RelativeTimeFormatImpl(
|
||||
}
|
||||
}
|
||||
|
||||
CArrArrString RelativeTimeFormatImpl::FormatToParts(double number, char *unit)
|
||||
{
|
||||
std::string unitStr = unit;
|
||||
std::vector<std::vector<std::string>> timeVectorStr;
|
||||
char *RelativeTimeFormatImpl::Format(double number, char *unit)
|
||||
{
|
||||
std::string unitStr = unit;
|
||||
std::string value = relativeTimeFmt_->Format(number, unitStr);
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
|
||||
CArrArrString ret = {.head = nullptr, .size = 0};
|
||||
relativeTimeFmt_->FormatToParts(number, unitStr, timeVectorStr);
|
||||
CArrString *res = static_cast<CArrString *>(malloc(sizeof(char ***) * timeVectorStr.size()));
|
||||
if (res == nullptr) {
|
||||
HILOG_ERROR_I18N("The CArrString is nullptr");
|
||||
return ret;
|
||||
}
|
||||
CArrArrString RelativeTimeFormatImpl::FormatToParts(double number, char *unit)
|
||||
{
|
||||
std::string unitStr = unit;
|
||||
std::vector<std::vector<std::string>> timeVectorStr;
|
||||
|
||||
CArrArrString ret = {.head = nullptr, .size = 0};
|
||||
relativeTimeFmt_->FormatToParts(number, unitStr, timeVectorStr);
|
||||
CArrString *res = static_cast<CArrString *>(malloc(sizeof(char ***) * timeVectorStr.size()));
|
||||
if (res == nullptr) {
|
||||
HILOG_ERROR_I18N("The CArrString is nullptr");
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < timeVectorStr.size(); i++) {
|
||||
std::vector<std::string> timeVector = timeVectorStr[i];
|
||||
|
93
interfaces/cj/src/i18n_breakIterator_ffi.cpp
Normal file
93
interfaces/cj/src/i18n_breakIterator_ffi.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_breakIterator_ffi.h"
|
||||
#include "i18n_breakIterator_impl.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
extern "C" {
|
||||
void FfiOHOSBreakIteratorSetLineBreakText(int64_t id, const char* text)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
instance->SetLineBreakText(text);
|
||||
}
|
||||
|
||||
char* FfiOHOSBreakIteratorGetLineBreakText(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
return MallocCString(instance->GetLineBreakText());
|
||||
}
|
||||
|
||||
int32_t FfiOHOSBreakIteratorCurrent(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
return instance->current();
|
||||
}
|
||||
|
||||
int32_t FfiOHOSBreakIteratorFirst(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
return instance->first();
|
||||
}
|
||||
|
||||
int32_t FfiOHOSBreakIteratorFollowing(int64_t id, int32_t offset)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
return instance->following(offset);
|
||||
}
|
||||
|
||||
int32_t FfiOHOSBreakIteratorLast(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
return instance->last();
|
||||
}
|
||||
|
||||
int32_t FfiOHOSBreakIteratorNext(int64_t id, int32_t number)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
return instance->next(number);
|
||||
}
|
||||
|
||||
int32_t FfiOHOSBreakIteratorPrevious(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
return instance->previous();
|
||||
}
|
||||
|
||||
bool FfiOHOSBreakIteratorIsBoundary(int64_t id, int32_t offset)
|
||||
{
|
||||
auto instance = FFIData::GetData<CBreakIterator>(id);
|
||||
return instance->IsBoundary(offset);
|
||||
}
|
||||
|
||||
int64_t FfiOHOSGetLineInstance(const char* locale)
|
||||
{
|
||||
std::string localeStr(locale);
|
||||
auto instance = FFIData::Create<CBreakIterator>(localeStr);
|
||||
if (instance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create CBreakIterator fail");
|
||||
return -1;
|
||||
}
|
||||
return instance->GetID();
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
79
interfaces/cj/src/i18n_breakIterator_impl.cpp
Normal file
79
interfaces/cj/src/i18n_breakIterator_impl.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_breakIterator_impl.h"
|
||||
#include <memory>
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
CBreakIterator::CBreakIterator(std::string localeTag)
|
||||
{
|
||||
brkiter_ = std::make_unique<I18nBreakIterator>(localeTag);
|
||||
if (brkiter_ == nullptr) {
|
||||
HILOG_ERROR_I18N("Create I18nBreakIterator fail");
|
||||
}
|
||||
}
|
||||
|
||||
void CBreakIterator::SetLineBreakText(const char* text)
|
||||
{
|
||||
brkiter_->SetText(text);
|
||||
}
|
||||
|
||||
std::string CBreakIterator::GetLineBreakText()
|
||||
{
|
||||
std::string res;
|
||||
brkiter_->GetText(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t CBreakIterator::current()
|
||||
{
|
||||
return brkiter_->Current();
|
||||
}
|
||||
|
||||
int32_t CBreakIterator::first()
|
||||
{
|
||||
return brkiter_->First();
|
||||
}
|
||||
|
||||
int32_t CBreakIterator::last()
|
||||
{
|
||||
return brkiter_->Last();
|
||||
}
|
||||
|
||||
int32_t CBreakIterator::next(int32_t number)
|
||||
{
|
||||
return brkiter_->Next(number);
|
||||
}
|
||||
|
||||
int32_t CBreakIterator::previous()
|
||||
{
|
||||
return brkiter_->Previous();
|
||||
}
|
||||
|
||||
int32_t CBreakIterator::following(int32_t offset)
|
||||
{
|
||||
return brkiter_->Following(offset);
|
||||
}
|
||||
|
||||
bool CBreakIterator::IsBoundary(int32_t offset)
|
||||
{
|
||||
return brkiter_->IsBoundary(offset);
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
226
interfaces/cj/src/i18n_calendar_ffi.cpp
Normal file
226
interfaces/cj/src/i18n_calendar_ffi.cpp
Normal file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <ctime>
|
||||
#include "i18n_calendar_ffi.h"
|
||||
#include "i18n_calendar_impl.h"
|
||||
#include "unicode/ucal.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace {
|
||||
using namespace OHOS::Global::I18n;
|
||||
std::unordered_map<std::string, UCalendarDateFields> g_fieldsMap {
|
||||
{ "era", UCAL_ERA },
|
||||
{ "year", UCAL_YEAR },
|
||||
{ "month", UCAL_MONTH },
|
||||
{ "week_of_year", UCAL_WEEK_OF_YEAR },
|
||||
{ "week_of_month", UCAL_WEEK_OF_MONTH },
|
||||
{ "date", UCAL_DATE },
|
||||
{ "day_of_year", UCAL_DAY_OF_YEAR },
|
||||
{ "day_of_week", UCAL_DAY_OF_WEEK },
|
||||
{ "day_of_week_in_month", UCAL_DAY_OF_WEEK_IN_MONTH },
|
||||
{ "ap_pm", UCAL_AM_PM },
|
||||
{ "hour", UCAL_HOUR },
|
||||
{ "hour_of_day", UCAL_HOUR_OF_DAY },
|
||||
{ "minute", UCAL_MINUTE },
|
||||
{ "second", UCAL_SECOND },
|
||||
{ "millisecond", UCAL_MILLISECOND },
|
||||
{ "zone_offset", UCAL_ZONE_OFFSET },
|
||||
{ "dst_offset", UCAL_DST_OFFSET },
|
||||
{ "year_woy", UCAL_YEAR_WOY },
|
||||
{ "dow_local", UCAL_DOW_LOCAL },
|
||||
{ "extended_year", UCAL_EXTENDED_YEAR },
|
||||
{ "julian_day", UCAL_JULIAN_DAY },
|
||||
{ "milliseconds_in_day", UCAL_MILLISECONDS_IN_DAY },
|
||||
{ "is_leap_month", UCAL_IS_LEAP_MONTH },
|
||||
};
|
||||
|
||||
std::unordered_set<std::string> g_fieldsInFunctionAdd {
|
||||
"year", "month", "date", "hour", "minute", "second", "millisecond",
|
||||
"week_of_year", "week_of_month", "day_of_year", "day_of_week",
|
||||
"day_of_week_in_month", "hour_of_day", "milliseconds_in_day",
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, CalendarType> g_typeMap {
|
||||
{ "buddhist", CalendarType::BUDDHIST },
|
||||
{ "chinese", CalendarType::CHINESE },
|
||||
{ "coptic", CalendarType::COPTIC },
|
||||
{ "ethiopic", CalendarType::ETHIOPIC },
|
||||
{ "hebrew", CalendarType::HEBREW },
|
||||
{ "gregory", CalendarType::GREGORY },
|
||||
{ "indian", CalendarType::INDIAN },
|
||||
{ "islamic_civil", CalendarType::ISLAMIC_CIVIL },
|
||||
{ "islamic_tbla", CalendarType::ISLAMIC_TBLA },
|
||||
{ "islamic_umalqura", CalendarType::ISLAMIC_UMALQURA },
|
||||
{ "japanese", CalendarType::JAPANESE },
|
||||
{ "persion", CalendarType::PERSIAN },
|
||||
};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
|
||||
extern "C" {
|
||||
CalendarType GetCalendarType(const std::string& calendarType)
|
||||
{
|
||||
CalendarType type = CalendarType::UNDEFINED;
|
||||
if (g_typeMap.find(calendarType) != g_typeMap.end()) {
|
||||
type = g_typeMap[calendarType];
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
int64_t FfiOHOSGetCalendar(const char* locale, const char* type)
|
||||
{
|
||||
CalendarType calendarType = CalendarType::UNDEFINED;
|
||||
if (type != nullptr) {
|
||||
calendarType = GetCalendarType(std::string(type));
|
||||
}
|
||||
std::string localStr(locale);
|
||||
auto nativeCalendar = FFIData::Create<CCalendar>(localStr, calendarType);
|
||||
if (nativeCalendar == nullptr) {
|
||||
HILOG_ERROR_I18N("Create CCalendar fail");
|
||||
return -1;
|
||||
}
|
||||
return nativeCalendar->GetID();
|
||||
}
|
||||
|
||||
void FfiOHOSCalendarSetTime(int64_t id, double time)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
instance->SetTime(time);
|
||||
}
|
||||
|
||||
void FfiOHOSCalendarSetDate(int64_t id, int32_t year, int32_t month, int32_t day)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
instance->Set(year, month, day);
|
||||
}
|
||||
|
||||
void FfiOHOSCalendarSetOfDay(int64_t id, int32_t hour, int32_t minute, int32_t second)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::tm* now = std::localtime(&t);
|
||||
if (hour == -1) {
|
||||
hour = now->tm_hour;
|
||||
}
|
||||
if (minute == -1) {
|
||||
minute = now->tm_min;
|
||||
}
|
||||
if (second == -1) {
|
||||
second = now->tm_sec;
|
||||
}
|
||||
instance->Set(UCalendarDateFields::UCAL_HOUR_OF_DAY, hour);
|
||||
instance->Set(UCalendarDateFields::UCAL_MINUTE, minute);
|
||||
instance->Set(UCalendarDateFields::UCAL_SECOND, second);
|
||||
}
|
||||
|
||||
void FfiOHOSCalendarSetTimeZone(int64_t id, const char* timeZone)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
instance->SetTimeZone(std::string(timeZone));
|
||||
}
|
||||
|
||||
char* FfiOHOSCalendarGetTimeZone(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
std::string res = instance->GetTimeZone();
|
||||
return MallocCString(res);
|
||||
}
|
||||
|
||||
void FfiOHOSCalendarSetFirstDayOfWeek(int64_t id, int32_t firstDayOfWeek)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
instance->SetFirstDayOfWeek(firstDayOfWeek);
|
||||
}
|
||||
|
||||
int32_t FfiOHOSCalendarGetFirstDayOfWeek(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
return instance->GetFirstDayOfWeek();
|
||||
}
|
||||
|
||||
void FfiOHOSCalendarSetMinimalDaysInFirstWeek(int64_t id, int32_t minimalDays)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
instance->SetMinimalDaysInFirstWeek(minimalDays);
|
||||
}
|
||||
|
||||
int32_t FfiOHOSCalendarGetMinimalDaysInFirstWeek(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
return instance->GetMinimalDaysInFirstWeek();
|
||||
}
|
||||
|
||||
int32_t FfiOHOSCalendarGet(int64_t id, char* field)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
std::string fieldName(field);
|
||||
return instance->Get(g_fieldsMap[fieldName]);
|
||||
}
|
||||
|
||||
char* FfiOHOSCalendarGetDisplayName(int64_t id, char* locale)
|
||||
{
|
||||
std::string localeStr(locale);
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
std::string res = instance->GetDisplayName(localeStr);
|
||||
return MallocCString(res);
|
||||
}
|
||||
|
||||
bool FfiOHOSCalendarIsWeekend(int64_t id, CDate date)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
// -1 indicates that the date is not provided
|
||||
if (date.isNull) {
|
||||
return instance->IsWeekend();
|
||||
} else {
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
return instance->IsWeekend(date.icuUdate, error);
|
||||
}
|
||||
}
|
||||
|
||||
void FfiOHOSCalendarAdd(int64_t id, char* field, int32_t amount, int32_t* errcode)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
std::string fieldStr(field);
|
||||
if (g_fieldsInFunctionAdd.find(fieldStr) == g_fieldsInFunctionAdd.end()) {
|
||||
*errcode = I18N_NOT_VALID;
|
||||
}
|
||||
instance -> Add(g_fieldsMap[fieldStr], amount);
|
||||
}
|
||||
|
||||
double FfiOHOSCalendarGetTimeInMillis(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
return instance->GetTimeInMillis();
|
||||
}
|
||||
|
||||
int32_t FfiOHOSCalendarCompareDays(int64_t id, CDate date)
|
||||
{
|
||||
auto instance = FFIData::GetData<CCalendar>(id);
|
||||
return instance->CompareDays(date.icuUdate);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
113
interfaces/cj/src/i18n_calendar_impl.cpp
Normal file
113
interfaces/cj/src/i18n_calendar_impl.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_calendar_impl.h"
|
||||
#include "i18n_calendar.h"
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
CCalendar::CCalendar(std::string localeTag, CalendarType type)
|
||||
{
|
||||
calendar_ = std::make_unique<I18nCalendar>(localeTag, type);
|
||||
if (calendar_ == nullptr) {
|
||||
HILOG_ERROR_I18N("Create I18nCalendar fail");
|
||||
}
|
||||
}
|
||||
|
||||
void CCalendar::SetTime(double time)
|
||||
{
|
||||
calendar_->SetTime(time);
|
||||
}
|
||||
|
||||
void CCalendar::Set(UCalendarDateFields field, int32_t value)
|
||||
{
|
||||
calendar_->Set(field, value);
|
||||
}
|
||||
|
||||
void CCalendar::Set(int32_t year, int32_t month, int32_t date)
|
||||
{
|
||||
calendar_->Set(year, month, date);
|
||||
}
|
||||
|
||||
std::string CCalendar::GetTimeZone(void)
|
||||
{
|
||||
return calendar_->GetTimeZone();
|
||||
}
|
||||
|
||||
void CCalendar::SetTimeZone(std::string timezoneId)
|
||||
{
|
||||
calendar_->SetTimeZone(timezoneId);
|
||||
}
|
||||
|
||||
int32_t CCalendar::Get(UCalendarDateFields field) const
|
||||
{
|
||||
return calendar_->Get(field);
|
||||
}
|
||||
|
||||
void CCalendar::Add(UCalendarDateFields field, int32_t amount)
|
||||
{
|
||||
return calendar_->Add(field, amount);
|
||||
}
|
||||
|
||||
void CCalendar::SetMinimalDaysInFirstWeek(int32_t value)
|
||||
{
|
||||
calendar_->SetMinimalDaysInFirstWeek(value);
|
||||
}
|
||||
|
||||
void CCalendar::SetFirstDayOfWeek(int32_t value)
|
||||
{
|
||||
calendar_->SetFirstDayOfWeek(value);
|
||||
}
|
||||
|
||||
UDate CCalendar::GetTimeInMillis(void)
|
||||
{
|
||||
return calendar_->GetTimeInMillis();
|
||||
}
|
||||
|
||||
int32_t CCalendar::CompareDays(UDate date)
|
||||
{
|
||||
return calendar_->CompareDays(date);
|
||||
}
|
||||
|
||||
bool CCalendar::IsWeekend(void)
|
||||
{
|
||||
return calendar_->IsWeekend();
|
||||
}
|
||||
|
||||
bool CCalendar::IsWeekend(int64_t date, UErrorCode &status)
|
||||
{
|
||||
return calendar_->IsWeekend(date, status);
|
||||
}
|
||||
|
||||
std::string CCalendar::GetDisplayName(std::string &displayLocaleTag)
|
||||
{
|
||||
return calendar_->GetDisplayName(displayLocaleTag);
|
||||
}
|
||||
|
||||
int32_t CCalendar::GetMinimalDaysInFirstWeek(void)
|
||||
{
|
||||
return calendar_->GetMinimalDaysInFirstWeek();
|
||||
}
|
||||
|
||||
int32_t CCalendar::GetFirstDayOfWeek(void)
|
||||
{
|
||||
return calendar_->GetFirstDayOfWeek();
|
||||
}
|
||||
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
47
interfaces/cj/src/i18n_entity_ffi.cpp
Normal file
47
interfaces/cj/src/i18n_entity_ffi.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_struct.h"
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_entity_ffi.h"
|
||||
#include "i18n_entity_impl.h"
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
extern "C" {
|
||||
int64_t FfiOHOSEntityImplConstructor(char* locale, int32_t* errcode)
|
||||
{
|
||||
std::string localeStr(locale);
|
||||
auto instance = FFIData::Create<CEntity>(localeStr);
|
||||
if (!instance->InitSuccess()) {
|
||||
*errcode = I18N_NOT_VALID;
|
||||
HILOG_ERROR_I18N("Create CEntity fail");
|
||||
return -1;
|
||||
}
|
||||
return instance->GetID();
|
||||
}
|
||||
|
||||
CEntityInfoItemArr FfiOHOSEntityFindEntityInfo(int64_t id, char* text)
|
||||
{
|
||||
auto instance = FFIData::GetData<CEntity>(id);
|
||||
return instance->FindEntityInfo(std::string(text));
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
101
interfaces/cj/src/i18n_entity_impl.cpp
Normal file
101
interfaces/cj/src/i18n_entity_impl.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include "i18n_entity_impl.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "utils.h"
|
||||
#include "entity_recognizer.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
|
||||
CEntity::CEntity(std::string locale)
|
||||
{
|
||||
UErrorCode localeStatus = U_ZERO_ERROR;
|
||||
icu::Locale localeTag = icu::Locale::forLanguageTag(locale, localeStatus);
|
||||
if (!IsValidLocaleTag(localeTag)) {
|
||||
entityRecognizer_ = nullptr;
|
||||
return;
|
||||
}
|
||||
entityRecognizer_ = std::make_unique<EntityRecognizer>(localeTag);
|
||||
if (entityRecognizer_ == nullptr) {
|
||||
HILOG_ERROR_I18N("Create EntityRecognizer fail");
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t EntityInfoItems2C(const std::vector<EntityInfoItem>& items, CEntityInfoItemArr &arr)
|
||||
{
|
||||
int32_t size = static_cast<int32_t>(items.size());
|
||||
if (size > 0) {
|
||||
arr.head = static_cast<CEntityInfoItem*>(malloc(sizeof(CEntityInfoItem) * size));
|
||||
if (arr.head == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
arr.size = size;
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
const EntityInfoItem& item = items[i];
|
||||
CEntityInfoItem cItem;
|
||||
cItem.type = MallocCString(item.type);
|
||||
cItem.begin = item.begin;
|
||||
cItem.end = item.end;
|
||||
|
||||
if (cItem.type == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
arr.head[i] = cItem;
|
||||
}
|
||||
} else {
|
||||
arr.head = nullptr;
|
||||
arr.size = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
CEntityInfoItemArr CEntity::FindEntityInfo(std::string text)
|
||||
{
|
||||
std::vector<std::vector<int>> entityInfo = entityRecognizer_->FindEntityInfo(text);
|
||||
std::vector<std::string> types = {"phone_number", "date"};
|
||||
std::vector<EntityInfoItem> items;
|
||||
CEntityInfoItemArr arr = { 0, nullptr };
|
||||
int index = 0;
|
||||
for (std::string::size_type t = 0; t < types.size(); t++) {
|
||||
for (int i = 0; i < entityInfo[t][0]; i++) {
|
||||
int begin = entityInfo[t][2 * i + 1];
|
||||
int end = entityInfo[t][2 * i + 2];
|
||||
std::string type = types[t];
|
||||
EntityInfoItem item = { type, begin, end };
|
||||
items.push_back(item);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
EntityInfoItems2C(items, arr);
|
||||
return arr;
|
||||
}
|
||||
|
||||
bool CEntity::InitSuccess()
|
||||
{
|
||||
return entityRecognizer_ != nullptr;
|
||||
}
|
||||
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
@ -12,16 +12,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "preferred_language.h"
|
||||
#include "locale_config.h"
|
||||
#include <cstdint>
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_struct.h"
|
||||
#include "locale_config.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
extern "C"
|
||||
{
|
||||
char* MallocCString(const std::string& origin)
|
||||
@ -37,24 +35,26 @@ char* MallocCString(const std::string& origin)
|
||||
return std::char_traits<char>::copy(res, origin.c_str(), length);
|
||||
}
|
||||
|
||||
char* FfiOHOSGetAppPreferredLanguage()
|
||||
CArrStr VectorStringToCArr(const std::vector<std::string>& vectorString)
|
||||
{
|
||||
std::string language = PreferredLanguage::GetFirstPreferredLanguage();
|
||||
char* res = MallocCString(language);
|
||||
return res;
|
||||
CArrStr strArray;
|
||||
strArray.length = static_cast<int64_t>(vectorString.size());
|
||||
strArray.data = static_cast<char**>(malloc(strArray.length * sizeof(char*)));
|
||||
if (strArray.data == nullptr) {
|
||||
return CArrStr{0};
|
||||
}
|
||||
for (int64_t i = 0; i < strArray.length; i++) {
|
||||
strArray.data[i] = MallocCString(vectorString[i]);
|
||||
}
|
||||
return strArray;
|
||||
}
|
||||
|
||||
char* FfiI18nSystemGetSystemLanguage()
|
||||
bool FfiOHOSIsRTL(char* locale)
|
||||
{
|
||||
std::string language = OHOS::Global::I18n::LocaleConfig::GetSystemLanguage();
|
||||
return MallocCString(language);
|
||||
}
|
||||
char* FfiI18nSystemGetSystemRegion()
|
||||
{
|
||||
std::string region = OHOS::Global::I18n::LocaleConfig::GetSystemRegion();
|
||||
return MallocCString(region);
|
||||
bool isRTL = LocaleConfig::IsRTL(std::string(locale));
|
||||
return isRTL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
129
interfaces/cj/src/i18n_holiday_ffi.cpp
Normal file
129
interfaces/cj/src/i18n_holiday_ffi.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_holiday_ffi.h"
|
||||
#include "i18n_struct.h"
|
||||
#include "ffi_remote_data.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_holiday_impl.h"
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
#define HOLIDAY_OPT_SUCCESS 0
|
||||
#define HOLIDAY_OPT_FAILED (-1)
|
||||
extern "C" {
|
||||
int64_t FfiOHOSHolidayManagerImplConstructor(char* icsPath)
|
||||
{
|
||||
auto instance = FFIData::Create<CHolidayManager>(icsPath);
|
||||
if (instance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create CHolidayManager fail");
|
||||
return -1;
|
||||
}
|
||||
return instance->GetID();
|
||||
}
|
||||
|
||||
bool FfiOHOSHolidayManagerIsHoliday(int64_t id, CDate date)
|
||||
{
|
||||
auto instance = FFIData::GetData<CHolidayManager>(id);
|
||||
if (date.isNull) {
|
||||
return instance->isHoliday();
|
||||
} else {
|
||||
return instance->isHoliday(date.year, date.month, date.day);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t HolidayLocalNames2Cj(const std::vector<HolidayLocalName>& localNames, HolidayLocalNameArr &arr)
|
||||
{
|
||||
int64_t size = static_cast<int64_t>(localNames.size());
|
||||
if (size > 0) {
|
||||
arr.head = static_cast<CHolidayLocalName *>(malloc(sizeof(CHolidayLocalName) * size));
|
||||
if (arr.head == nullptr) {
|
||||
return HOLIDAY_OPT_FAILED;
|
||||
}
|
||||
arr.size = size;
|
||||
|
||||
uint32_t idx = 0;
|
||||
for (const auto& each : localNames) {
|
||||
CHolidayLocalName info;
|
||||
info.language = MallocCString(each.language);
|
||||
info.name = MallocCString(each.name);
|
||||
arr.head[idx] = info;
|
||||
idx++;
|
||||
}
|
||||
} else {
|
||||
arr.head = nullptr;
|
||||
arr.size = 0;
|
||||
}
|
||||
|
||||
return HOLIDAY_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t HolidayInfo2Cj(const std::vector<HolidayInfoItem>& items, HolidayInfoItemArr &arr)
|
||||
{
|
||||
int64_t size = static_cast<int64_t>(items.size());
|
||||
if (size <= 0) {
|
||||
arr.head = nullptr;
|
||||
arr.size = 0;
|
||||
return HOLIDAY_OPT_SUCCESS;
|
||||
}
|
||||
arr.head = static_cast<CHolidayInfoItem*>(malloc(sizeof(CHolidayInfoItem) * size));
|
||||
if (arr.head == nullptr) {
|
||||
return HOLIDAY_OPT_FAILED;
|
||||
}
|
||||
uint32_t idx = 0;
|
||||
for (const auto& each : items) {
|
||||
CHolidayInfoItem info;
|
||||
info.baseName = MallocCString(each.baseName);
|
||||
info.day = each.day;
|
||||
info.month = each.month;
|
||||
info.year = each.year;
|
||||
|
||||
if (HolidayLocalNames2Cj(each.localNames, info.localNames) != HOLIDAY_OPT_SUCCESS) {
|
||||
for (uint32_t index = 0; index < idx; index++) {
|
||||
free(arr.head[idx].baseName);
|
||||
}
|
||||
free(info.baseName);
|
||||
free(arr.head);
|
||||
return HOLIDAY_OPT_FAILED;
|
||||
}
|
||||
|
||||
arr.head[idx] = info;
|
||||
idx++;
|
||||
}
|
||||
arr.size = idx;
|
||||
return HOLIDAY_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
HolidayInfoItemArr FfiOHOSHolidayManagerGetHolidayInfoItemArray(int64_t id, int32_t year)
|
||||
{
|
||||
auto instance = FFIData::GetData<CHolidayManager>(id);
|
||||
std::vector<HolidayInfoItem> result;
|
||||
HolidayInfoItemArr infos = { 0, nullptr };
|
||||
if (year == -1) {
|
||||
result = instance->getHolidayInfoItemArray();
|
||||
} else {
|
||||
result = instance->getHolidayInfoItemArray(year);
|
||||
}
|
||||
|
||||
HolidayInfo2Cj(result, infos);
|
||||
return infos;
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
55
interfaces/cj/src/i18n_holiday_impl.cpp
Normal file
55
interfaces/cj/src/i18n_holiday_impl.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_holiday_impl.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
CHolidayManager::CHolidayManager(char* icsPath)
|
||||
{
|
||||
holidayManager_ = std::make_unique<HolidayManager>(icsPath);
|
||||
if (holidayManager_ == nullptr) {
|
||||
HILOG_ERROR_I18N("Create HolidayManager fail");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<HolidayInfoItem> CHolidayManager::getHolidayInfoItemArray(int32_t year)
|
||||
{
|
||||
std::vector<HolidayInfoItem> itemList = holidayManager_->GetHolidayInfoItemArray(year);
|
||||
return itemList;
|
||||
}
|
||||
|
||||
std::vector<HolidayInfoItem> CHolidayManager::getHolidayInfoItemArray()
|
||||
{
|
||||
std::vector<HolidayInfoItem> itemList = holidayManager_->GetHolidayInfoItemArray();
|
||||
return itemList;
|
||||
}
|
||||
|
||||
bool CHolidayManager::isHoliday()
|
||||
{
|
||||
return holidayManager_->IsHoliday();
|
||||
}
|
||||
|
||||
bool CHolidayManager::isHoliday(int32_t year, int32_t month, int32_t day)
|
||||
{
|
||||
return holidayManager_->IsHoliday(year, month, day);
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
69
interfaces/cj/src/i18n_index_util_ffi.cpp
Normal file
69
interfaces/cj/src/i18n_index_util_ffi.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "i18n_struct.h"
|
||||
#include "i18n_hilog.h"
|
||||
#include "i18n_index_util_ffi.h"
|
||||
#include "i18n_index_util_impl.h"
|
||||
#include "index_util.h"
|
||||
#include <utility>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
extern "C"
|
||||
{
|
||||
int64_t FfiI18nIndexUtilConstructor(char* locale)
|
||||
{
|
||||
std::unique_ptr<IndexUtil> indexUtil_ = std::make_unique<IndexUtil>(std::string(locale));
|
||||
if (indexUtil_ == nullptr) {
|
||||
HILOG_ERROR_I18N("Create IndexUtil fail");
|
||||
return -1;
|
||||
}
|
||||
auto ffiIndexUtilInstance = FFIData::Create<FfiI18nIndexUtil>(std::move(indexUtil_));
|
||||
if (ffiIndexUtilInstance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create FfiI18nIndexUtil fail");
|
||||
return -1;
|
||||
}
|
||||
return ffiIndexUtilInstance -> GetID();
|
||||
}
|
||||
|
||||
void FfiI18nIndexUtilAddLocale(int64_t remoteDataID, char* locale)
|
||||
{
|
||||
auto ffiIndexUtilInstance = FFIData::GetData<FfiI18nIndexUtil>(remoteDataID);
|
||||
ffiIndexUtilInstance->addLocale(std::string(locale));
|
||||
}
|
||||
|
||||
char* FfiI18nIndexUtilGetIndex(int64_t remoteDataID, char* text)
|
||||
{
|
||||
auto ffiIndexUtilInstance = FFIData::GetData<FfiI18nIndexUtil>(remoteDataID);
|
||||
return ffiIndexUtilInstance->getIndex(std::string(text));
|
||||
}
|
||||
|
||||
CArrStr FfiI18nIndexUtilGetIndexList(int64_t remoteDataID)
|
||||
{
|
||||
auto ffiIndexUtilInstance = FFIData::GetData<FfiI18nIndexUtil>(remoteDataID);
|
||||
return ffiIndexUtilInstance->getIndexList();
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
46
interfaces/cj/src/i18n_index_util_impl.cpp
Normal file
46
interfaces/cj/src/i18n_index_util_impl.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_index_util_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
extern "C"
|
||||
{
|
||||
FfiI18nIndexUtil::FfiI18nIndexUtil(std::unique_ptr<IndexUtil> indexUtil)
|
||||
{
|
||||
indexUtil_ = std::move(indexUtil);
|
||||
}
|
||||
|
||||
void FfiI18nIndexUtil::addLocale(std::string locale)
|
||||
{
|
||||
indexUtil_->AddLocale(locale);
|
||||
}
|
||||
|
||||
char* FfiI18nIndexUtil::getIndex(std::string text)
|
||||
{
|
||||
return MallocCString(indexUtil_->GetIndex(text));
|
||||
}
|
||||
|
||||
CArrStr FfiI18nIndexUtil::getIndexList()
|
||||
{
|
||||
return VectorStringToCArr(indexUtil_->GetIndexList());
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
55
interfaces/cj/src/i18n_normalizer_ffi.cpp
Normal file
55
interfaces/cj/src/i18n_normalizer_ffi.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include "i18n_hilog.h"
|
||||
#include "i18n_normalizer_ffi.h"
|
||||
#include "i18n_normalizer_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
extern "C"
|
||||
{
|
||||
int64_t FfiI18nNormalizerConstructor(int32_t mode)
|
||||
{
|
||||
I18nNormalizerMode normalizerMode = I18nNormalizerMode(mode);
|
||||
I18nErrorCode errorCode = SUCCESS;
|
||||
std::unique_ptr<I18nNormalizer> normalizer_ = std::make_unique<I18nNormalizer>(normalizerMode, errorCode);
|
||||
if (errorCode != I18nErrorCode::SUCCESS || !normalizer_) {
|
||||
HILOG_ERROR_I18N("Create I18nNormalizer fail, error code: %d", errorCode);
|
||||
return -1;
|
||||
}
|
||||
auto ffiNormalizerInstance = FFIData::Create<FfiI18nNormalizer>(std::move(normalizer_));
|
||||
if (ffiNormalizerInstance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create FfiI18nNormalizer fail");
|
||||
return -1;
|
||||
}
|
||||
return ffiNormalizerInstance->GetID();
|
||||
}
|
||||
|
||||
char* FfiI18nNormalizerNormalize(int64_t remoteDataID, char* text)
|
||||
{
|
||||
auto normalizer = FFIData::GetData<FfiI18nNormalizer>(remoteDataID);
|
||||
return normalizer->normalize(text);
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
43
interfaces/cj/src/i18n_normalizer_impl.cpp
Normal file
43
interfaces/cj/src/i18n_normalizer_impl.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_hilog.h"
|
||||
#include "i18n_normalizer_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
extern "C"
|
||||
{
|
||||
FfiI18nNormalizer::FfiI18nNormalizer(std::unique_ptr<I18nNormalizer> normalizer)
|
||||
{
|
||||
normalizer_ = std::move(normalizer);
|
||||
}
|
||||
|
||||
char* FfiI18nNormalizer::normalize(char* text)
|
||||
{
|
||||
I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
|
||||
std::string normalizedText = normalizer_->Normalize(text, std::strlen(text), errorCode);
|
||||
if (errorCode != I18nErrorCode::SUCCESS) {
|
||||
HILOG_ERROR_I18N("FfiI18nNormalizer normalize fail, error code: %d", errorCode);
|
||||
return MallocCString("");
|
||||
}
|
||||
return MallocCString(normalizedText);
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
74
interfaces/cj/src/i18n_phone_number_format_ffi.cpp
Normal file
74
interfaces/cj/src/i18n_phone_number_format_ffi.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "i18n_hilog.h"
|
||||
#include "i18n_struct.h"
|
||||
#include "i18n_phone_number_format_ffi.h"
|
||||
#include "i18n_phone_number_format_impl.h"
|
||||
#include <utility>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
extern "C"
|
||||
{
|
||||
int64_t FfiI18nPhoneNumberFormatConstructor(char* country, char* formatType)
|
||||
{
|
||||
std::map<std::string, std::string> options;
|
||||
if (formatType != nullptr) {
|
||||
options.insert(std::make_pair("type", std::string(formatType)));
|
||||
}
|
||||
std::unique_ptr<PhoneNumberFormat> phoneNumberFormatInstance
|
||||
= PhoneNumberFormat::CreateInstance(country, options);
|
||||
if (phoneNumberFormatInstance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create PhoneNumberFormat fail");
|
||||
return -1;
|
||||
}
|
||||
auto ffiI18nPhoneNumberFormatInstance
|
||||
= FFIData::Create<FfiI18nPhoneNumberFormat>(std::move(phoneNumberFormatInstance));
|
||||
if (ffiI18nPhoneNumberFormatInstance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create FfiI18nPhoneNumberFormat fail");
|
||||
return -1;
|
||||
}
|
||||
return ffiI18nPhoneNumberFormatInstance->GetID();
|
||||
}
|
||||
|
||||
char* FfiI18nPhoneNumberFormatFormat(int64_t remoteDataID, char* number)
|
||||
{
|
||||
auto format = FFIData::GetData<FfiI18nPhoneNumberFormat>(remoteDataID);
|
||||
return format->format(std::string(number));
|
||||
}
|
||||
bool FfiI18nPhoneNumberFormatIsValidNumber(int64_t remoteDataID, char* number)
|
||||
{
|
||||
auto format = FFIData::GetData<FfiI18nPhoneNumberFormat>(remoteDataID);
|
||||
return format->isValidNumber(std::string(number));
|
||||
}
|
||||
char* FfiI18nPhoneNumberFormatGetLocationName(int64_t remoteDataID, char* number, char* locale)
|
||||
{
|
||||
auto format = FFIData::GetData<FfiI18nPhoneNumberFormat>(remoteDataID);
|
||||
return format->getLocationNmae(std::string(number), std::string(locale));
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
46
interfaces/cj/src/i18n_phone_number_format_impl.cpp
Normal file
46
interfaces/cj/src/i18n_phone_number_format_impl.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_phone_number_format_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
extern "C"
|
||||
{
|
||||
FfiI18nPhoneNumberFormat::FfiI18nPhoneNumberFormat
|
||||
(std::unique_ptr<PhoneNumberFormat> phoneNumberFormat)
|
||||
{
|
||||
phoneNumberFormat_ = std::move(phoneNumberFormat);
|
||||
}
|
||||
|
||||
char* FfiI18nPhoneNumberFormat::format(std::string number)
|
||||
{
|
||||
return MallocCString(phoneNumberFormat_->format(number));
|
||||
}
|
||||
|
||||
bool FfiI18nPhoneNumberFormat::isValidNumber(std::string number)
|
||||
{
|
||||
return phoneNumberFormat_->isValidPhoneNumber(number);
|
||||
}
|
||||
|
||||
char* FfiI18nPhoneNumberFormat::getLocationNmae(std::string number, std::string locale)
|
||||
{
|
||||
return MallocCString(phoneNumberFormat_->getLocationName(number, locale));
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
161
interfaces/cj/src/i18n_system_ffi.cpp
Normal file
161
interfaces/cj/src/i18n_system_ffi.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "locale_config.h"
|
||||
#include "locale_info.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_hilog.h"
|
||||
#include "i18n_struct.h"
|
||||
#include "i18n_system_ffi.h"
|
||||
#include "preferred_language.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
extern "C"
|
||||
{
|
||||
char* FfiI18nSystemGetAppPreferredLanguage()
|
||||
{
|
||||
#ifdef SUPPORT_APP_PREFERRED_LANGUAGE
|
||||
std::string language = PreferredLanguage::GetAppPreferredLanguage();
|
||||
#else
|
||||
std::string language = PreferredLanguage::GetFirstPreferredLanguage();
|
||||
#endif
|
||||
return MallocCString(language);
|
||||
}
|
||||
|
||||
char* FfiI18nSystemGetSystemLanguage()
|
||||
{
|
||||
return MallocCString(LocaleConfig::GetSystemLanguage());
|
||||
}
|
||||
|
||||
char* FfiI18nSystemGetSystemRegion()
|
||||
{
|
||||
return MallocCString(LocaleConfig::GetSystemRegion());
|
||||
}
|
||||
|
||||
bool FfiI18nSystemIsSuggested(char* language, char* region, int32_t parameterStatus)
|
||||
{
|
||||
bool isSuggested = false;
|
||||
if (parameterStatus == 1) {
|
||||
isSuggested = LocaleConfig::IsSuggested(std::string(language), std::string(region));
|
||||
} else {
|
||||
isSuggested = LocaleConfig::IsSuggested(std::string(language));
|
||||
}
|
||||
return isSuggested;
|
||||
}
|
||||
|
||||
CArrStr FfiI18nSystemGetSystemCountries(char* language)
|
||||
{
|
||||
std::vector<std::string> systemCountries;
|
||||
LocaleConfig::GetSystemCountries(systemCountries);
|
||||
return VectorStringToCArr(systemCountries);
|
||||
}
|
||||
|
||||
char* FfiI18nSystemGetDisplayCountry(char* country, char* locale, bool sentenceCase, int32_t* errcode)
|
||||
{
|
||||
std::string countryStr(country);
|
||||
std::string localeStr(locale);
|
||||
LocaleInfo localeInfo(countryStr);
|
||||
if (!LocaleConfig::IsValidRegion(countryStr) && localeInfo.GetRegion() == "") {
|
||||
HILOG_ERROR_I18N("GetDisplayCountry: Failed to get display country, because param country is invalid!");
|
||||
*errcode = I18N_NOT_VALID;
|
||||
return MallocCString("");
|
||||
} else if (!LocaleConfig::IsValidTag(locale)) {
|
||||
HILOG_ERROR_I18N("GetDisplayCountry: Failed to get display country, because param locale is invalid!");
|
||||
*errcode = I18N_NOT_VALID;
|
||||
return MallocCString("");
|
||||
}
|
||||
std::string region = LocaleConfig::GetDisplayRegion(countryStr, localeStr, sentenceCase);
|
||||
return MallocCString(region);
|
||||
}
|
||||
|
||||
bool FfiI18nSystemGetUsingLocalDigit()
|
||||
{
|
||||
return LocaleConfig::GetUsingLocalDigit();
|
||||
}
|
||||
|
||||
int32_t FfiI18nSystemSetAppPreferredLanguage(char* language)
|
||||
{
|
||||
UErrorCode icuStatus = U_ZERO_ERROR;
|
||||
std::string localeTag(language);
|
||||
icu::Locale locale = icu::Locale::forLanguageTag(localeTag, icuStatus);
|
||||
if (U_FAILURE(icuStatus) || !(IsValidLocaleTag(locale) || localeTag.compare("default") == 0)) {
|
||||
HILOG_ERROR_I18N("SetAppPreferredLanguage does not support this locale");
|
||||
return I18N_NOT_VALID;
|
||||
}
|
||||
#ifdef SUPPORT_APP_PREFERRED_LANGUAGE
|
||||
I18nErrorCode errCode = I18nErrorCode::SUCCESS;
|
||||
PreferredLanguage::SetAppPreferredLanguage(localeTag, errCode);
|
||||
if (errCode != I18nErrorCode::SUCCESS) {
|
||||
HILOG_ERROR_I18N("Set app language to i18n app preferences failed, error code: %d", errCode);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* FfiI18nSystemGetFirstPreferredLanguage()
|
||||
{
|
||||
return MallocCString(PreferredLanguage::GetFirstPreferredLanguage());
|
||||
}
|
||||
|
||||
CArrStr FfiI18nSystemGetPreferredLanguageList()
|
||||
{
|
||||
return VectorStringToCArr(PreferredLanguage::GetPreferredLanguageList());
|
||||
}
|
||||
|
||||
bool FfiI18nSystemIs24HourClock()
|
||||
{
|
||||
return LocaleConfig::Is24HourClock();
|
||||
}
|
||||
|
||||
CArrStr FfiI18nSystemGetSystemLanguages()
|
||||
{
|
||||
std::vector<std::string> systemLanguages;
|
||||
LocaleConfig::GetSystemLanguages(systemLanguages);
|
||||
return VectorStringToCArr(systemLanguages);
|
||||
}
|
||||
|
||||
char* FfiI18nSystemGetDisplayLanguage(char* language, char* locale, bool sentenceCase, int32_t* errCode)
|
||||
{
|
||||
std::string languageStr(language);
|
||||
std::string localeStr(locale);
|
||||
if (!LocaleConfig::IsValidTag(localeStr)) {
|
||||
HILOG_ERROR_I18N("GetDisplayLanguage: Failed to get display language, because param locale is invalid!");
|
||||
*errCode = I18N_NOT_VALID;
|
||||
return MallocCString("");
|
||||
}
|
||||
std::string value = LocaleConfig::GetDisplayLanguage(languageStr, localeStr, sentenceCase);
|
||||
if (value.length() == 0) {
|
||||
HILOG_ERROR_I18N("GetDisplayLanguage: result is empty.");
|
||||
}
|
||||
return MallocCString(value);
|
||||
}
|
||||
|
||||
char* FfiI18nSystemGetSystemLocale()
|
||||
{
|
||||
return MallocCString(LocaleConfig::GetSystemLocale());
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
126
interfaces/cj/src/i18n_timezone_ffi.cpp
Normal file
126
interfaces/cj/src/i18n_timezone_ffi.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "i18n_hilog.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_struct.h"
|
||||
#include "i18n_timezone_ffi.h"
|
||||
#include "i18n_timezone_impl.h"
|
||||
#include <utility>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
extern "C"
|
||||
{
|
||||
int64_t FfiI18nTimezoneConstructor(char* id, bool isZoneId)
|
||||
{
|
||||
std::string zoneId(id);
|
||||
std::unique_ptr<I18nTimeZone> timezoneInstance = I18nTimeZone::CreateInstance(zoneId, isZoneId);
|
||||
if (timezoneInstance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create I18nTimeZone fail");
|
||||
return -1;
|
||||
}
|
||||
auto ffiTimezoneInstance = FFIData::Create<FfiI18nTimeZone>(std::move(timezoneInstance));
|
||||
if (ffiTimezoneInstance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create FfiI18nTimeZone fail");
|
||||
return -1;
|
||||
}
|
||||
return ffiTimezoneInstance->GetID();
|
||||
}
|
||||
|
||||
CArrStr FfiI18nTimezoneGetTimezonesByLocation(double longitude, double latitude)
|
||||
{
|
||||
return VectorStringToCArr(I18nTimeZone::GetTimezoneIdByLocation(longitude, latitude));
|
||||
}
|
||||
|
||||
char* FfiI18nTimezoneGetCityDisplayName(char* cityID, char* locale)
|
||||
{
|
||||
std::string zoneCityID(cityID);
|
||||
std::string zoneLocale(locale);
|
||||
return MallocCString(I18nTimeZone::GetCityDisplayName(zoneCityID, zoneLocale));
|
||||
}
|
||||
|
||||
CArrStr FfiI18nTimezoneGetAvailableZoneCityIDs()
|
||||
{
|
||||
std::set<std::string> cityIDSet = I18nTimeZone::GetAvailableZoneCityIDs();
|
||||
std::vector<std::string> cityIDVec(cityIDSet.begin(), cityIDSet.end());
|
||||
return VectorStringToCArr(cityIDVec);
|
||||
}
|
||||
|
||||
CArrStr FfiI18nTimezoneGetAvailableIDs()
|
||||
{
|
||||
I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
|
||||
std::set<std::string> timezoneIDSet = I18nTimeZone::GetAvailableIDs(errorCode);
|
||||
if (errorCode != I18nErrorCode::SUCCESS) {
|
||||
return { nullptr, 0 };
|
||||
}
|
||||
std::vector<std::string> timezoneIDVec(timezoneIDSet.begin(), timezoneIDSet.end());
|
||||
return VectorStringToCArr(timezoneIDVec);
|
||||
}
|
||||
|
||||
char* FfiI18nTimezoneGetDisplayName(int64_t remoteDataID, char* locale, bool isDST, int32_t parameterStatus)
|
||||
{
|
||||
auto timezone = FFIData::GetData<FfiI18nTimeZone>(remoteDataID);
|
||||
char* result;
|
||||
if (parameterStatus == 0) {
|
||||
result = timezone->getDisplayName();
|
||||
} else if (parameterStatus == 1) { // 1 represents one string parameter.
|
||||
result = timezone->getDisplayName(std::string(locale));
|
||||
} else if (parameterStatus == 2) { // 2 represents one boolean parameter.
|
||||
result = timezone->getDisplayName(isDST);
|
||||
} else {
|
||||
result = timezone->getDisplayName(std::string(locale), isDST);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t FfiI18nTimezoneGetOffset(int64_t remoteDataID, double date, int32_t parameterStatus)
|
||||
{
|
||||
auto timezone = FFIData::GetData<FfiI18nTimeZone>(remoteDataID);
|
||||
double cDate = 0;
|
||||
if (parameterStatus == 0) { // 0 reprensents date is null, use system time instead
|
||||
auto time = std::chrono::system_clock::now();
|
||||
auto since_epoch = time.time_since_epoch();
|
||||
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(since_epoch);
|
||||
cDate = (double)millis.count();
|
||||
} else {
|
||||
cDate = date;
|
||||
}
|
||||
return timezone->getOffset(cDate);
|
||||
}
|
||||
|
||||
int32_t FfiI18nTimezoneGetRawOffset(int64_t remoteDataID)
|
||||
{
|
||||
auto timezone = FFIData::GetData<FfiI18nTimeZone>(remoteDataID);
|
||||
return timezone->getRawOffset();
|
||||
}
|
||||
|
||||
char* FfiI18nTimezoneGetID(int64_t remoteDataID)
|
||||
{
|
||||
auto timezone = FFIData::GetData<FfiI18nTimeZone>(remoteDataID);
|
||||
return timezone->getID();
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
62
interfaces/cj/src/i18n_timezone_impl.cpp
Normal file
62
interfaces/cj/src/i18n_timezone_impl.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_timezone_impl.h"
|
||||
#include "i18n_ffi.h"
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
FfiI18nTimeZone::FfiI18nTimeZone(std::unique_ptr<I18nTimeZone> timezone)
|
||||
{
|
||||
timezone_ = std::move(timezone);
|
||||
}
|
||||
|
||||
char* FfiI18nTimeZone::getID()
|
||||
{
|
||||
return MallocCString(timezone_->GetID());
|
||||
}
|
||||
|
||||
int32_t FfiI18nTimeZone::getRawOffset()
|
||||
{
|
||||
return timezone_->GetRawOffset();
|
||||
}
|
||||
|
||||
int32_t FfiI18nTimeZone::getOffset(double date)
|
||||
{
|
||||
return timezone_->GetOffset(date);
|
||||
}
|
||||
|
||||
char* FfiI18nTimeZone::getDisplayName()
|
||||
{
|
||||
return MallocCString(timezone_->GetDisplayName());
|
||||
}
|
||||
|
||||
char* FfiI18nTimeZone::getDisplayName(std::string locale)
|
||||
{
|
||||
return MallocCString(timezone_->GetDisplayName(locale));
|
||||
}
|
||||
|
||||
char* FfiI18nTimeZone::getDisplayName(std::string locale, bool isDST)
|
||||
{
|
||||
return MallocCString(timezone_->GetDisplayName(locale, isDST));
|
||||
}
|
||||
|
||||
char* FfiI18nTimeZone::getDisplayName(bool isDST)
|
||||
{
|
||||
return MallocCString(timezone_->GetDisplayName(isDST));
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
79
interfaces/cj/src/i18n_transliterator_ffi.cpp
Normal file
79
interfaces/cj/src/i18n_transliterator_ffi.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include "i18n_hilog.h"
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_transliterator_ffi.h"
|
||||
#include "i18n_transliterator_impl.h"
|
||||
#include <utility>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::FFI;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
extern "C"
|
||||
{
|
||||
int64_t FfiI18nTransliteratorConstructor(char* id)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::UnicodeString unistr = icu::UnicodeString::fromUTF8(icu::StringPiece(id));
|
||||
icu::Transliterator *trans
|
||||
= icu::Transliterator::createInstance(unistr, UTransDirection::UTRANS_FORWARD, status);
|
||||
if (U_FAILURE(status) || (trans == nullptr)) {
|
||||
HILOG_ERROR_I18N("Create icuTransliterator fail");
|
||||
return -1;
|
||||
}
|
||||
auto ffiTransliteratorInstance
|
||||
= FFIData::Create<FfiI18nTransliterator>(std::unique_ptr<icu::Transliterator>(trans));
|
||||
if (ffiTransliteratorInstance == nullptr) {
|
||||
HILOG_ERROR_I18N("Create FfiI18nTransliterator fail");
|
||||
return -1;
|
||||
}
|
||||
return ffiTransliteratorInstance->GetID();
|
||||
}
|
||||
|
||||
CArrStr FfiI18nTransliteratorGetAvailableIDs()
|
||||
{
|
||||
UErrorCode icuStatus = U_ZERO_ERROR;
|
||||
icu::StringEnumeration* idStrEnum = icu::Transliterator::getAvailableIDs(icuStatus);
|
||||
if (U_FAILURE(icuStatus)) {
|
||||
HILOG_ERROR_I18N("Failed to get available ids");
|
||||
if (idStrEnum) {
|
||||
delete idStrEnum;
|
||||
}
|
||||
return { nullptr, 0 };
|
||||
}
|
||||
std::vector<std::string> idList;
|
||||
icu::UnicodeString temp = nullptr;
|
||||
while ((temp = idStrEnum->next(nullptr, icuStatus)) != nullptr) {
|
||||
std::string id;
|
||||
temp.toUTF8String(id);
|
||||
idList.push_back(id);
|
||||
}
|
||||
return VectorStringToCArr(idList);
|
||||
}
|
||||
|
||||
char* FfiI18nTransliteratorTransform(int64_t remoteDataId, char* text)
|
||||
{
|
||||
auto transLiterator_ = FFIData::GetData<FfiI18nTransliterator>(remoteDataId);
|
||||
return transLiterator_->transform(text);
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
36
interfaces/cj/src/i18n_transliterator_impl.cpp
Normal file
36
interfaces/cj/src/i18n_transliterator_impl.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_transliterator_impl.h"
|
||||
#include "i18n_ffi.h"
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
FfiI18nTransliterator::FfiI18nTransliterator(std::unique_ptr<icu::Transliterator> transliterator)
|
||||
{
|
||||
transliterator_ = std::move(transliterator);
|
||||
}
|
||||
|
||||
char* FfiI18nTransliterator::transform(char* text)
|
||||
{
|
||||
icu::UnicodeString unistr = icu::UnicodeString::fromUTF8(text);
|
||||
transliterator_->transliterate(unistr);
|
||||
std::string temp;
|
||||
unistr.toUTF8String(temp);
|
||||
return MallocCString(temp);
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
72
interfaces/cj/src/i18n_unicode_ffi.cpp
Normal file
72
interfaces/cj/src/i18n_unicode_ffi.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "i18n_unicode_ffi.h"
|
||||
#include <cstdlib>
|
||||
#include "character.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
extern "C"
|
||||
{
|
||||
char* FfiI18nUnicodeGetType(char* text)
|
||||
{
|
||||
return MallocCString(GetType(text));
|
||||
}
|
||||
|
||||
bool FfiI18nUnicodeIsUpperCase(char* text)
|
||||
{
|
||||
return IsUpperCase(text);
|
||||
}
|
||||
|
||||
bool FfiI18nUnicodeIsLowerCase(char* text)
|
||||
{
|
||||
return IsLowerCase(text);
|
||||
}
|
||||
|
||||
bool FfiI18nUnicodeIsLetter(char* text)
|
||||
{
|
||||
return IsLetter(text);
|
||||
}
|
||||
|
||||
bool FfiI18nUnicodeIsIdeograph(char* text)
|
||||
{
|
||||
return IsIdeoGraphic(text);
|
||||
}
|
||||
|
||||
bool FfiI18nUnicodeIsRTL(char* text)
|
||||
{
|
||||
return IsRTLCharacter(text);
|
||||
}
|
||||
|
||||
bool FfiI18nUnicodeIsWhitespace(char* text)
|
||||
{
|
||||
return IsWhiteSpace(text);
|
||||
}
|
||||
|
||||
bool FfiI18nUnicodeIsSpaceChar(char* text)
|
||||
{
|
||||
return IsSpaceChar(text);
|
||||
}
|
||||
|
||||
bool FfiI18nUnicodeIsDigit(char* text)
|
||||
{
|
||||
return IsDigit(text);
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
214
interfaces/cj/src/i18n_util_ffi.cpp
Normal file
214
interfaces/cj/src/i18n_util_ffi.cpp
Normal file
@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "i18n_ffi.h"
|
||||
#include "i18n_hilog.h"
|
||||
#include "i18n_util_ffi.h"
|
||||
#include "locale_config.h"
|
||||
#include "locale_info.h"
|
||||
#include "character.h"
|
||||
#include "utils.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/datefmt.h"
|
||||
#include "unicode/smpdtfmt.h"
|
||||
#include "i18n_struct.h"
|
||||
#include "locale_matcher.h"
|
||||
#include "measure_data.h"
|
||||
#include "number_format.h"
|
||||
#include "date_time_sequence.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
std::vector<std::string> convert2CppStringArray(const CArrStr& carrStr)
|
||||
{
|
||||
std::vector<std::string> cppStringArray;
|
||||
for (int i = 0; i < carrStr.length; ++i) {
|
||||
cppStringArray.push_back(carrStr.data[i]);
|
||||
}
|
||||
return cppStringArray;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void ReleaseParam(LocaleInfo *locale, std::vector<LocaleInfo*> &candidateLocales)
|
||||
{
|
||||
delete locale;
|
||||
for (auto it = candidateLocales.begin(); it != candidateLocales.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
LocaleInfo* GetLocaleInfo(std::string localeStr, int32_t* errcode)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
|
||||
if (U_FAILURE(status) || !IsValidLocaleTag(locale)) {
|
||||
*errcode = I18N_NOT_VALID;
|
||||
return nullptr;
|
||||
}
|
||||
return new LocaleInfo(localeStr);
|
||||
}
|
||||
|
||||
bool ProcessLocaleList(std::vector<std::string> localeTagList,
|
||||
std::vector<LocaleInfo*> &candidateLocales, LocaleInfo *requestLocale, int32_t* errcode)
|
||||
{
|
||||
if (localeTagList.size() == 0) {
|
||||
*errcode = I18N_NOT_VALID;
|
||||
return true;
|
||||
}
|
||||
for (auto it = localeTagList.begin(); it != localeTagList.end(); ++it) {
|
||||
UErrorCode icuStatus = U_ZERO_ERROR;
|
||||
icu::Locale locale = icu::Locale::forLanguageTag(it->data(), icuStatus);
|
||||
if (U_FAILURE(icuStatus) || !IsValidLocaleTag(locale)) {
|
||||
*errcode = I18N_NOT_VALID;
|
||||
return false;
|
||||
}
|
||||
LocaleInfo *temp = new LocaleInfo(*it);
|
||||
if (LocaleMatcher::Match(requestLocale, temp)) {
|
||||
candidateLocales.push_back(temp);
|
||||
} else {
|
||||
delete temp;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
char* FfiI18nUtilUnitConvert(UnitInfo fromUnit, UnitInfo toUnit, double value, char* locale, char* style)
|
||||
{
|
||||
double number = value;
|
||||
std::string fromInfoUnit(fromUnit.unit);
|
||||
std::string fromInfoMeasureSystem(fromUnit.measureSystem);
|
||||
std::string toInfoUnit(toUnit.unit);
|
||||
std::string toInfoMeasureSystem(toUnit.measureSystem);
|
||||
|
||||
int32_t convertStatus = Convert(number, fromInfoUnit, fromInfoMeasureSystem, toInfoUnit, toInfoMeasureSystem);
|
||||
|
||||
std::vector<std::string> localeTags;
|
||||
std::map<std::string, std::string> map = {};
|
||||
|
||||
map.insert(std::make_pair("style", "unit"));
|
||||
if (!convertStatus) {
|
||||
map.insert(std::make_pair("unit", fromInfoUnit));
|
||||
} else {
|
||||
map.insert(std::make_pair("unit", toInfoUnit));
|
||||
}
|
||||
map.insert(std::make_pair("unitDisplay", std::string(style)));
|
||||
std::string localeTag(locale);
|
||||
localeTags.push_back(localeTag);
|
||||
std::unique_ptr<NumberFormat> numberFmt = nullptr;
|
||||
numberFmt = std::make_unique<NumberFormat>(localeTags, map);
|
||||
std::string result = numberFmt->Format(number);
|
||||
char* res = MallocCString(result);
|
||||
return res;
|
||||
}
|
||||
|
||||
char* FfiI18nUtilGetBestMatchLocale(char* locale, CArrStr localeList, int32_t* errCode)
|
||||
{
|
||||
std::vector<std::string> localeArr = convert2CppStringArray(localeList);
|
||||
std::string localeStr(locale);
|
||||
LocaleInfo *requestLocale = GetLocaleInfo(localeStr, errCode);
|
||||
if (requestLocale == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<LocaleInfo*> candidateLocales;
|
||||
bool isVaildParam = ProcessLocaleList(localeArr, candidateLocales, requestLocale, errCode);
|
||||
if (!isVaildParam) {
|
||||
*errCode = I18N_NOT_VALID;
|
||||
ReleaseParam(requestLocale, candidateLocales);
|
||||
return nullptr;
|
||||
}
|
||||
std::string bestMatchLocaleTag = "";
|
||||
if (candidateLocales.size() > 0) {
|
||||
LocaleInfo *bestMatch = candidateLocales[0];
|
||||
for (size_t i = 1; i < candidateLocales.size(); ++i) {
|
||||
if (LocaleMatcher::IsMoreSuitable(bestMatch, candidateLocales[i], requestLocale) < 0) {
|
||||
bestMatch = candidateLocales[i];
|
||||
}
|
||||
}
|
||||
bestMatchLocaleTag = bestMatch->ToString();
|
||||
}
|
||||
ReleaseParam(requestLocale, candidateLocales);
|
||||
char* res = MallocCString(bestMatchLocaleTag);
|
||||
return res;
|
||||
}
|
||||
|
||||
char* FfiI18nUtilGetDateOrder(char* locale)
|
||||
{
|
||||
std::string loacleStr(locale);
|
||||
char* res = MallocCString(DateTimeSequence::GetDateOrder(loacleStr));
|
||||
return res;
|
||||
}
|
||||
|
||||
char* FfiI18nUtilGetTimePeriodName(int32_t hour, char* locale, int32_t* errcode)
|
||||
{
|
||||
std::string localeTag;
|
||||
if (locale == nullptr) {
|
||||
localeTag = LocaleConfig::GetSystemLocale();
|
||||
} else {
|
||||
localeTag = std::string(locale);
|
||||
}
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::Locale localeIcu = icu::Locale::forLanguageTag(localeTag, status);
|
||||
if (U_FAILURE(status) || !IsValidLocaleTag(localeIcu)) {
|
||||
*errcode = I18N_NOT_VALID;
|
||||
return nullptr;
|
||||
}
|
||||
icu::DateFormat* dateFormatter = icu::DateFormat::createDateInstance(icu::DateFormat::EStyle::kDefault, locale);
|
||||
icu::SimpleDateFormat* formatter = static_cast<icu::SimpleDateFormat*>(dateFormatter);
|
||||
formatter->applyPattern("B");
|
||||
std::string temp;
|
||||
icu::UnicodeString name;
|
||||
icu::Calendar *calendar = icu::Calendar::createInstance(locale, status);
|
||||
calendar->set(UCalendarDateFields::UCAL_HOUR_OF_DAY, hour);
|
||||
formatter->format(calendar->getTime(status), name);
|
||||
name.toUTF8String(temp);
|
||||
char* res = MallocCString(PseudoLocalizationProcessor(temp));
|
||||
delete formatter;
|
||||
delete calendar;
|
||||
return res;
|
||||
}
|
||||
|
||||
char* FfiI18nUtilGetThreeLetterLanguage(char* locale, int32_t* errcode)
|
||||
{
|
||||
std::string language = GetISO3Language(std::string(locale));
|
||||
if (language == "") {
|
||||
*errcode = I18N_NOT_VALID;
|
||||
HILOG_ERROR_I18N("GetThreeLetterLanguage create string fail or empty");
|
||||
return nullptr;
|
||||
}
|
||||
char* res = MallocCString(language);
|
||||
return res;
|
||||
}
|
||||
|
||||
char* FfiI18nUtilGetThreeLetterRegion(char* locale, int32_t* errcode)
|
||||
{
|
||||
std::string country = GetISO3Country(std::string(locale));
|
||||
if (country == "") {
|
||||
HILOG_ERROR_I18N("GetThreeLetterRegion create string fail or empty");
|
||||
*errcode = I18N_NOT_VALID;
|
||||
return nullptr;
|
||||
}
|
||||
char* res = MallocCString(country);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
@ -37,8 +38,11 @@ void ErrorUtil::NapiThrow(napi_env env, int32_t errCode, const std::string& valu
|
||||
return;
|
||||
}
|
||||
napi_value code = nullptr;
|
||||
napi_create_string_latin1(env, std::to_string(errCode).c_str(), NAPI_AUTO_LENGTH, &code);
|
||||
|
||||
napi_status status = napi_create_string_latin1(env, std::to_string(errCode).c_str(), NAPI_AUTO_LENGTH, &code);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("ErrorUtil::NapiThrow: create string %{public}d failed", errCode);
|
||||
return;
|
||||
}
|
||||
napi_value message = nullptr;
|
||||
auto iter = ErrorCodeToMsg.find(errCode);
|
||||
std::string errMsg = iter != ErrorCodeToMsg.end() ? iter->second : "";
|
||||
@ -54,10 +58,17 @@ void ErrorUtil::NapiThrow(napi_env env, int32_t errCode, const std::string& valu
|
||||
allErrMsg = errMsg + ", the type of " + valueName + " must be " + valueContent + ".";
|
||||
}
|
||||
|
||||
napi_create_string_latin1(env, allErrMsg.c_str(), NAPI_AUTO_LENGTH, &message);
|
||||
|
||||
status = napi_create_string_latin1(env, allErrMsg.c_str(), NAPI_AUTO_LENGTH, &message);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("ErrorUtil::NapiThrow: create string %{public}s failed", allErrMsg.c_str());
|
||||
return;
|
||||
}
|
||||
napi_value error = nullptr;
|
||||
napi_create_error(env, code, message, &error);
|
||||
status = napi_create_error(env, code, message, &error);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("ErrorUtil::NapiThrow: create error failed");
|
||||
return;
|
||||
}
|
||||
napi_throw(env, error);
|
||||
}
|
||||
} // namespace I18n
|
||||
|
@ -563,7 +563,7 @@ bool I18nAddon::InitTransliteratorContext(napi_env env, napi_callback_info info,
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::UnicodeString unistr = icu::UnicodeString::fromUTF8(idTag);
|
||||
icu::Transliterator *trans = icu::Transliterator::createInstance(unistr, UTransDirection::UTRANS_FORWARD, status);
|
||||
if ((status != U_ZERO_ERROR) || (trans == nullptr)) {
|
||||
if (U_FAILURE(status) || (trans == nullptr)) {
|
||||
return false;
|
||||
}
|
||||
transliterator_ = std::unique_ptr<icu::Transliterator>(trans);
|
||||
@ -629,7 +629,7 @@ napi_value I18nAddon::GetAvailableIDs(napi_env env, napi_callback_info info)
|
||||
}
|
||||
UErrorCode icuStatus = U_ZERO_ERROR;
|
||||
icu::StringEnumeration *strenum = icu::Transliterator::getAvailableIDs(icuStatus);
|
||||
if (icuStatus != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(icuStatus)) {
|
||||
HILOG_ERROR_I18N("Failed to get available ids");
|
||||
if (strenum) {
|
||||
delete strenum;
|
||||
@ -645,7 +645,7 @@ napi_value I18nAddon::GetAvailableIDs(napi_env env, napi_callback_info info)
|
||||
return nullptr;
|
||||
}
|
||||
while ((temp = strenum->next(nullptr, icuStatus)) != nullptr) {
|
||||
if (icuStatus != U_ZERO_ERROR) {
|
||||
if (U_FAILURE(icuStatus)) {
|
||||
break;
|
||||
}
|
||||
napi_value val = nullptr;
|
||||
|
@ -509,11 +509,15 @@ napi_value I18nSystemAddon::GetSystemCountriesImpl(napi_env env, napi_callback_i
|
||||
}
|
||||
VariableConvertor::VerifyType(env, "language", "string", argv[0]);
|
||||
size_t len = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
|
||||
status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("GetSystemCountriesImpl: Failed to get string len argv[0].");
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<char> localeBuf(len + 1);
|
||||
status = napi_get_value_string_utf8(env, argv[0], localeBuf.data(), len + 1, &len);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("GetSystemCountriesImpl: Failed to get string item.");
|
||||
HILOG_ERROR_I18N("GetSystemCountriesImpl: Failed to get string item argv[0].");
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<std::string> systemCountries;
|
||||
@ -556,7 +560,11 @@ napi_value I18nSystemAddon::IsSuggestedImpl(napi_env env, napi_callback_info inf
|
||||
}
|
||||
VariableConvertor::VerifyType(env, "language", "string", argv[0]);
|
||||
size_t len = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
|
||||
status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("IsSuggestedImpl: Failed to get string len argv[0].");
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<char> languageBuf(len + 1);
|
||||
status = napi_get_value_string_utf8(env, argv[0], languageBuf.data(), len + 1, &len);
|
||||
if (status != napi_ok) {
|
||||
@ -565,7 +573,11 @@ napi_value I18nSystemAddon::IsSuggestedImpl(napi_env env, napi_callback_info inf
|
||||
}
|
||||
bool isSuggested = false;
|
||||
if (VariableConvertor::CheckNapiValueType(env, argv[1])) {
|
||||
napi_get_value_string_utf8(env, argv[1], nullptr, 0, &len);
|
||||
status = napi_get_value_string_utf8(env, argv[1], nullptr, 0, &len);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("IsSuggestedImpl: Failed to get string len argv[1].");
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<char> regionBuf(len + 1);
|
||||
status = napi_get_value_string_utf8(env, argv[1], regionBuf.data(), len + 1, &len);
|
||||
if (status != napi_ok) {
|
||||
@ -601,7 +613,11 @@ napi_value I18nSystemAddon::SetSystemLanguageImpl(napi_env env, napi_callback_in
|
||||
return nullptr;
|
||||
}
|
||||
size_t len = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
|
||||
status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("SetSystemLanguageImpl: Failed to get string len argv[0].");
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<char> languageBuf(len + 1);
|
||||
status = napi_get_value_string_utf8(env, argv[0], languageBuf.data(), len + 1, &len);
|
||||
if (status != napi_ok) {
|
||||
|
@ -45,7 +45,11 @@ napi_value I18nTimeZoneAddon::GetI18nTimeZone(napi_env env, napi_callback_info i
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
|
||||
if (!VariableConvertor::CheckNapiValueType(env, argv[0])) {
|
||||
napi_create_string_utf8(env, "", NAPI_AUTO_LENGTH, &argv[0]);
|
||||
napi_status status = napi_create_string_utf8(env, "", NAPI_AUTO_LENGTH, &argv[0]);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("I18nTimeZoneAddon::GetI18nTimeZone: create string failed.");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return StaticGetTimeZone(env, argv, true);
|
||||
}
|
||||
|
@ -199,7 +199,11 @@ napi_value I18nUnicodeAddon::IsRTLCharacterAddon(napi_env env, napi_callback_inf
|
||||
return nullptr;
|
||||
}
|
||||
napi_valuetype valueType = napi_valuetype::napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
status = napi_typeof(env, argv[0], &valueType);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("I18nUnicodeAddon::IsRTLCharacterAddon: get argv[0] type failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (valueType != napi_valuetype::napi_string) {
|
||||
HILOG_ERROR_I18N("IsRTLCharacterAddon: Parameter type does not match");
|
||||
return nullptr;
|
||||
@ -230,7 +234,11 @@ napi_value I18nUnicodeAddon::IsIdeoGraphicAddon(napi_env env, napi_callback_info
|
||||
return nullptr;
|
||||
}
|
||||
napi_valuetype valueType = napi_valuetype::napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
status = napi_typeof(env, argv[0], &valueType);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("I18nUnicodeAddon::IsIdeoGraphicAddon: get argv[0] type failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (valueType != napi_valuetype::napi_string) {
|
||||
HILOG_ERROR_I18N("IsIdeoGraphicAddon: Parameter type does not match");
|
||||
return nullptr;
|
||||
@ -261,7 +269,11 @@ napi_value I18nUnicodeAddon::IsLetterAddon(napi_env env, napi_callback_info info
|
||||
return nullptr;
|
||||
}
|
||||
napi_valuetype valueType = napi_valuetype::napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
status = napi_typeof(env, argv[0], &valueType);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("I18nUnicodeAddon::IsLetterAddon: get argv[0] type failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (valueType != napi_valuetype::napi_string) {
|
||||
HILOG_ERROR_I18N("IsLetterAddon: Parameter type does not match");
|
||||
return nullptr;
|
||||
@ -292,7 +304,11 @@ napi_value I18nUnicodeAddon::IsLowerCaseAddon(napi_env env, napi_callback_info i
|
||||
return nullptr;
|
||||
}
|
||||
napi_valuetype valueType = napi_valuetype::napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
status = napi_typeof(env, argv[0], &valueType);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("I18nUnicodeAddon::IsLowerCaseAddon: get argv[0] type failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (valueType != napi_valuetype::napi_string) {
|
||||
HILOG_ERROR_I18N("IsLowerCaseAddon: Parameter type does not match");
|
||||
return nullptr;
|
||||
@ -323,7 +339,11 @@ napi_value I18nUnicodeAddon::IsUpperCaseAddon(napi_env env, napi_callback_info i
|
||||
return nullptr;
|
||||
}
|
||||
napi_valuetype valueType = napi_valuetype::napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
status = napi_typeof(env, argv[0], &valueType);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("I18nUnicodeAddon::IsUpperCaseAddon: get argv[0] type failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (valueType != napi_valuetype::napi_string) {
|
||||
HILOG_ERROR_I18N("IsUpperCaseAddon: Parameter type does not match");
|
||||
return nullptr;
|
||||
@ -354,7 +374,11 @@ napi_value I18nUnicodeAddon::GetTypeAddon(napi_env env, napi_callback_info info)
|
||||
return nullptr;
|
||||
}
|
||||
napi_valuetype valueType = napi_valuetype::napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
status = napi_typeof(env, argv[0], &valueType);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR_I18N("I18nUnicodeAddon::GetTypeAddon: get argv[0] type failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (valueType != napi_valuetype::napi_string) {
|
||||
HILOG_ERROR_I18N("GetTypeAddon: Parameter type does not match");
|
||||
return nullptr;
|
||||
|
@ -192,7 +192,10 @@ void GetOptionValue(napi_env env, napi_value options, const std::string &optionN
|
||||
if (status != napi_ok) {
|
||||
return;
|
||||
}
|
||||
map.insert(make_pair(optionName, optionBuf.data()));
|
||||
auto ret = map.insert(make_pair(optionName, optionBuf.data()));
|
||||
if (!ret.second) {
|
||||
HILOG_ERROR_I18N("GetOptionValue: map insert failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,7 +243,10 @@ void GetBoolOptionValue(napi_env env, napi_value options, const std::string &opt
|
||||
bool boolValue = false;
|
||||
napi_get_value_bool(env, optionValue, &boolValue);
|
||||
std::string value = boolValue ? "true" : "false";
|
||||
map.insert(make_pair(optionName, value));
|
||||
auto ret = map.insert(make_pair(optionName, value));
|
||||
if (!ret.second) {
|
||||
HILOG_ERROR_I18N("GetBoolOptionValue: map insert failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user