mirror of
https://gitee.com/openharmony/global_i18n
synced 2025-02-16 22:21:13 +00:00
intl add
Signed-off-by: 小城茶语 <guorunzhi@huawei.com>
This commit is contained in:
parent
091e22d5c0
commit
be39424011
71
interfaces/cj/intl/BUILD.gn
Normal file
71
interfaces/cj/intl/BUILD.gn
Normal file
@ -0,0 +1,71 @@
|
||||
# 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.
|
||||
|
||||
import("//base/global/i18n/i18n.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
group("build_module") {
|
||||
deps = [ ":cj_intl_ffi" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("cj_intl_ffi") {
|
||||
include_dirs = [
|
||||
"../../../frameworks/intl/include",
|
||||
"../../js/kits/include",
|
||||
"../../cj/include",
|
||||
]
|
||||
|
||||
if (!defined(defines)) {
|
||||
defines = []
|
||||
}
|
||||
|
||||
deps = [ "../../../frameworks/intl:intl_util" ]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hilog:libhilog",
|
||||
"icu:shared_icui18n",
|
||||
"icu:shared_icuuc",
|
||||
"ipc:ipc_core",
|
||||
"libphonenumber:phonenumber_standard",
|
||||
"libphonenumber:phonenumber_standard",
|
||||
"libpng:libpng",
|
||||
"libpng:libpng",
|
||||
"libxml2:libxml2",
|
||||
"napi:ace_napi",
|
||||
"napi:cj_bind_ffi",
|
||||
"napi:cj_bind_native",
|
||||
"preferences:native_preferences",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
sources = [
|
||||
"intl_ffi.cpp",
|
||||
"intl_impl.cpp",
|
||||
]
|
||||
|
||||
if (current_os == "ohos") {
|
||||
defines += [ "OHOS_PLATFORM" ]
|
||||
}
|
||||
|
||||
if (current_os == "mingw") {
|
||||
defines += [ "WINDOWS_PLATFORM" ]
|
||||
}
|
||||
|
||||
if (i18n_support_app_preferred_language) {
|
||||
defines += [ "SUPPORT_APP_PREFERRED_LANGUAGE" ]
|
||||
}
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "global"
|
||||
part_name = "i18n"
|
||||
}
|
437
interfaces/cj/intl/intl_ffi.cpp
Normal file
437
interfaces/cj/intl/intl_ffi.cpp
Normal file
@ -0,0 +1,437 @@
|
||||
/*
|
||||
* 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 "intl_ffi.h"
|
||||
#include "intl_impl.h"
|
||||
#include <string>
|
||||
|
||||
using namespace OHOS::FFI;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
namespace Intl {
|
||||
extern "C" {
|
||||
char *FfiOHOSNumberFormatImplFormat(int64_t id, double number)
|
||||
{
|
||||
auto instance = FFIData::GetData<NumberFormatImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The NumberFormatImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->Format(number);
|
||||
}
|
||||
|
||||
int64_t FfiOHOSNumberFormatImplConstructor(int32_t *errCode)
|
||||
{
|
||||
auto nativeCJNumberFormat = FFIData::Create<NumberFormatImpl>(errCode);
|
||||
if (!nativeCJNumberFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJNumberFormat->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSNumberFormatImplConstructorwithLocale(
|
||||
char *locale, CNumberOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJNumberFormat = FFIData::Create<NumberFormatImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJNumberFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJNumberFormat->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSNumberFormatImplConstructorwithArrayLocale(
|
||||
CArrString locale, CNumberOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJNumberFormat = FFIData::Create<NumberFormatImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJNumberFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJNumberFormat->GetID();
|
||||
}
|
||||
|
||||
CNumberOptions FfiOHOSNumberFormatImplGetNumberResolvedOptions(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<NumberFormatImpl>(id);
|
||||
struct CNumberOptions numberOptions;
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The NumberFormatImpl instance is nullptr");
|
||||
return numberOptions;
|
||||
}
|
||||
return instance->ResolveOptions();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSRelativeTimeFormatImplConstructor(int32_t *errCode)
|
||||
{
|
||||
auto nativeCJRelativeTimeFormat = FFIData::Create<RelativeTimeFormatImpl>(errCode);
|
||||
if (!nativeCJRelativeTimeFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJRelativeTimeFormat->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSRelativeTimeFormatImplConstructorwithLocale(
|
||||
char *locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJRelativeTimeFormat = FFIData::Create<RelativeTimeFormatImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJRelativeTimeFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJRelativeTimeFormat->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSRelativeTimeFormatImplConstructorwithArrayLocale(
|
||||
CArrString locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJRelativeTimeFormat = FFIData::Create<RelativeTimeFormatImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJRelativeTimeFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJRelativeTimeFormat->GetID();
|
||||
}
|
||||
|
||||
char *FfiOHOSRelativeTimeFormatImplFormat(int64_t id, double number, char *unit)
|
||||
{
|
||||
auto instance = FFIData::GetData<RelativeTimeFormatImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The RelativeTimeFormatImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->Format(number, unit);
|
||||
}
|
||||
|
||||
CArrArrString FfiOHOSRelativeTimeFormatImplFormatToParts(int64_t id, double number, char *unit)
|
||||
{
|
||||
auto instance = FFIData::GetData<RelativeTimeFormatImpl>(id);
|
||||
if (!instance) {
|
||||
CArrArrString ret = {.head = nullptr, .size = 0};
|
||||
HILOG_ERROR_I18N("The RelativeTimeFormatImpl instance is nullptr");
|
||||
return ret;
|
||||
}
|
||||
return instance->FormatToParts(number, unit);
|
||||
}
|
||||
|
||||
CRelativeTimeFormatResolveOptions FfiOHOSRelativeTimeFormatImplResolvedOptions(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<RelativeTimeFormatImpl>(id);
|
||||
if (!instance) {
|
||||
struct CRelativeTimeFormatResolveOptions relativeTimeFormatResolveOptions;
|
||||
HILOG_ERROR_I18N("The RelativeTimeFormatImpl instance is nullptr");
|
||||
return relativeTimeFormatResolveOptions;
|
||||
}
|
||||
return instance->ResolveOptions();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSPluralRulesImplConstructor(int32_t *errCode)
|
||||
{
|
||||
auto nativeCJPluralRules = FFIData::Create<PluralRulesImpl>(errCode);
|
||||
if (!nativeCJPluralRules) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJPluralRules->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSPluralRulesImplConstructorwithLocale(
|
||||
char *locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJPluralRules = FFIData::Create<PluralRulesImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJPluralRules) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJPluralRules->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSPluralRulesImplConstructorwithArrayLocale(
|
||||
CArrString locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJPluralRules = FFIData::Create<PluralRulesImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJPluralRules) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJPluralRules->GetID();
|
||||
}
|
||||
|
||||
char *FfiOHOSPluralRulesImplSelect(int64_t id, double n)
|
||||
{
|
||||
auto instance = FFIData::GetData<PluralRulesImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The PluralRulesImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->Select(n);
|
||||
}
|
||||
|
||||
int64_t FfiOHOSCollatorImplConstructor(int32_t *errCode)
|
||||
{
|
||||
auto nativeCJCollator = FFIData::Create<CollatorImpl>(errCode);
|
||||
if (!nativeCJCollator) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJCollator->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSCollatorImplConstructorwithLocale(char *locale, CCollatorOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJCollator = FFIData::Create<CollatorImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJCollator) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJCollator->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSCollatorImplConstructorwithArrayLocale(
|
||||
CArrString locale, CCollatorOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJCollator = FFIData::Create<CollatorImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJCollator) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJCollator->GetID();
|
||||
}
|
||||
|
||||
CCollatorOptions FfiOHOSCollatorOptionsImplResolvedOptions(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<CollatorImpl>(id);
|
||||
if (!instance) {
|
||||
struct CCollatorOptions collatorResolveOptions;
|
||||
HILOG_ERROR_I18N("The CollatorImpl instance is nullptr");
|
||||
return collatorResolveOptions;
|
||||
}
|
||||
return instance->ResolveOptions();
|
||||
}
|
||||
|
||||
int32_t FfiOHOSCollatorImplCompare(int64_t id, char *str1, char *str2)
|
||||
{
|
||||
auto instance = FFIData::GetData<CollatorImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The CollatorImpl instance is nullptr");
|
||||
return 0;
|
||||
}
|
||||
return instance->Compare(str1, str2);
|
||||
}
|
||||
|
||||
int64_t FfiOHOSDateTimeFormatImplConstructor(int32_t *errCode)
|
||||
{
|
||||
auto nativeCJDateTimeFormat = FFIData::Create<DateTimeFormatImpl>(errCode);
|
||||
if (!nativeCJDateTimeFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJDateTimeFormat->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSDateTimeFormatImplConstructorwithLocale(
|
||||
char *locale, CDateTimeOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJDateTimeFormat = FFIData::Create<DateTimeFormatImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJDateTimeFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJDateTimeFormat->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSDateTimeFormatImplConstructorwithArrayLocale(
|
||||
CArrString locale, CDateTimeOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJDateTimeFormat = FFIData::Create<DateTimeFormatImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJDateTimeFormat) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJDateTimeFormat->GetID();
|
||||
}
|
||||
|
||||
CDateTimeOptions FfiOHOSDateTimeFormatOptionsImplResolvedOptions(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<DateTimeFormatImpl>(id);
|
||||
if (!instance) {
|
||||
struct CDateTimeOptions dateTimeOptions;
|
||||
HILOG_ERROR_I18N("The DateTimeFormatImpl instance is nullptr");
|
||||
return dateTimeOptions;
|
||||
}
|
||||
return instance->ResolveOptions();
|
||||
}
|
||||
|
||||
char *FfiOHOSDateTimeFormatOptionsImplFormat(int64_t id, int64_t date)
|
||||
{
|
||||
auto instance = FFIData::GetData<DateTimeFormatImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The DateTimeFormatImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->Format(date);
|
||||
}
|
||||
|
||||
char *FfiOHOSDateTimeFormatOptionsImplFormatRange(int64_t id, int64_t startDate, int64_t endDate)
|
||||
{
|
||||
auto instance = FFIData::GetData<DateTimeFormatImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The DateTimeFormatImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->FormatRange(startDate, endDate);
|
||||
}
|
||||
|
||||
int64_t FfiOHOSLocaleImplConstructor(int32_t *errCode)
|
||||
{
|
||||
auto nativeCJLocale = FFIData::Create<LocaleImpl>(errCode);
|
||||
if (!nativeCJLocale) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return nativeCJLocale->GetID();
|
||||
}
|
||||
|
||||
int64_t FfiOHOSLocaleImplConstructorwithLocale(char *locale, CLocaleOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
auto nativeCJLocale = FFIData::Create<LocaleImpl>(locale, options, flag, errCode);
|
||||
if (!nativeCJLocale) {
|
||||
return 0;
|
||||
}
|
||||
return nativeCJLocale->GetID();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplToString(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->ToString();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplMaximize(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->Maximize();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplMinimize(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->Minimize();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetLanguage(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetLanguage();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetRegion(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetRegion();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetScript(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetScript();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetBaseName(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetBaseName();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetCaseFirst(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetCaseFirst();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetCalendar(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetCalendar();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetCollation(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetCollation();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetHourCycle(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetHourCycle();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetNumberingSystem(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetNumberingSystem();
|
||||
}
|
||||
|
||||
char *FfiOHOSLocaleImplGetNumeric(int64_t id)
|
||||
{
|
||||
auto instance = FFIData::GetData<LocaleImpl>(id);
|
||||
if (!instance) {
|
||||
HILOG_ERROR_I18N("The LocaleImpl instance is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return instance->GetNumeric();
|
||||
}
|
||||
}
|
||||
} // namespace Intl
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
191
interfaces/cj/intl/intl_ffi.h
Normal file
191
interfaces/cj/intl/intl_ffi.h
Normal file
@ -0,0 +1,191 @@
|
||||
/*
|
||||
* 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 INTL_FFI_H
|
||||
#define INTL_FFI_H
|
||||
|
||||
#include "number_format.h"
|
||||
#include "relative_time_format.h"
|
||||
#include "plural_rules.h"
|
||||
#include "collator.h"
|
||||
#include "date_time_format.h"
|
||||
#include "locale_info.h"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "cj_common_ffi.h"
|
||||
#include "ffi_remote_data.h"
|
||||
#include "hilog/log.h"
|
||||
#include "i18n_hilog.h"
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
struct CNumberOptions {
|
||||
char *locale;
|
||||
char *currency;
|
||||
char *currencySign;
|
||||
char *currencyDisplay;
|
||||
char *unit;
|
||||
char *unitDisplay;
|
||||
char *unitUsage;
|
||||
char *signDispaly;
|
||||
char *compactDisplay;
|
||||
char *notation;
|
||||
char *localeMather;
|
||||
char *style;
|
||||
char *numberingSystem;
|
||||
bool useGrouping;
|
||||
int64_t minimumIntegerDigits;
|
||||
int64_t minimumFractionDigits;
|
||||
int64_t maximumFractionDigits;
|
||||
int64_t minimumSignificantDigits;
|
||||
int64_t maximumSignificantDigits;
|
||||
};
|
||||
|
||||
struct CRelativeTimeFormatInputOptions {
|
||||
char *localeMatcher;
|
||||
char *numeric;
|
||||
char *style;
|
||||
};
|
||||
|
||||
struct CRelativeTimeFormatResolveOptions {
|
||||
char *localeMatcher;
|
||||
char *numeric;
|
||||
char *style;
|
||||
char *numberingSystem;
|
||||
};
|
||||
|
||||
struct CPluralRulesOptions {
|
||||
char *localeMatcher;
|
||||
char *type;
|
||||
int32_t minimumIntegerDigits;
|
||||
int32_t minimumFractionDigits;
|
||||
int32_t maximumFractionDigits;
|
||||
int32_t minimumSignificantDigits;
|
||||
int32_t maximumSignificantDigits;
|
||||
};
|
||||
|
||||
struct CCollatorOptions {
|
||||
char *localeMatcher;
|
||||
char *usage;
|
||||
char *sensitivity;
|
||||
bool ignorePunctuation;
|
||||
char *collation;
|
||||
bool numeric;
|
||||
char *caseFirst;
|
||||
};
|
||||
|
||||
struct CLocaleOptions {
|
||||
char *calendar;
|
||||
char *collation;
|
||||
char *hourCycle;
|
||||
char *numberingSystem;
|
||||
bool numeric;
|
||||
char *caseFirst;
|
||||
};
|
||||
|
||||
struct CDateTimeOptions {
|
||||
char *locale;
|
||||
char *dateStyle;
|
||||
char *timeStyle;
|
||||
char *hourCycle;
|
||||
char *timeZone;
|
||||
char *numberingSystem;
|
||||
bool hour12;
|
||||
char *weekday;
|
||||
char *era;
|
||||
char *year;
|
||||
char *month;
|
||||
char *day;
|
||||
char *hour;
|
||||
char *minute;
|
||||
char *second;
|
||||
char *timeZoneName;
|
||||
char *dayPeriod;
|
||||
char *localeMatcher;
|
||||
char *formatMatcher;
|
||||
};
|
||||
|
||||
struct CArrArrString {
|
||||
CArrString *head;
|
||||
int64_t size;
|
||||
};
|
||||
|
||||
// NumberFormat
|
||||
FFI_EXPORT int64_t FfiOHOSNumberFormatImplConstructor(int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSNumberFormatImplConstructorwithLocale(
|
||||
char *locale, CNumberOptions, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSNumberFormatImplConstructorwithArrayLocale(
|
||||
CArrString locale, CNumberOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT char *FfiOHOSNumberFormatImplFormat(int64_t id, double number);
|
||||
FFI_EXPORT CNumberOptions FfiOHOSNumberFormatImplGetNumberResolvedOptions(int64_t id);
|
||||
|
||||
// RelativeTimeFormat
|
||||
FFI_EXPORT int64_t FfiOHOSRelativeTimeFormatImplConstructor(int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSRelativeTimeFormatImplConstructorwithLocale(
|
||||
char *locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSRelativeTimeFormatImplConstructorwithArrayLocale(
|
||||
CArrString locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT char *FfiOHOSRelativeTimeFormatImplFormat(int64_t id, double number, char *unit);
|
||||
FFI_EXPORT CArrArrString FfiOHOSRelativeTimeFormatImplFormatToParts(int64_t id, double number, char *unit);
|
||||
FFI_EXPORT CRelativeTimeFormatResolveOptions FfiOHOSRelativeTimeFormatImplResolvedOptions(int64_t id);
|
||||
|
||||
// PluralRules
|
||||
FFI_EXPORT int64_t FfiOHOSPluralRulesImplConstructor(int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSPluralRulesImplConstructorwithLocale(
|
||||
char *locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSPluralRulesImplConstructorwithArrayLocale(
|
||||
CArrString locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT char *FfiOHOSPluralRulesImplSelect(int64_t id, double n);
|
||||
|
||||
// Collator
|
||||
FFI_EXPORT int64_t FfiOHOSCollatorImplConstructor(int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSCollatorImplConstructorwithLocale(
|
||||
char *locale, CCollatorOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSCollatorImplConstructorwithArrayLocale(
|
||||
CArrString locale, CCollatorOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSCollatorImplCompare(int64_t id, char *first, char *second);
|
||||
FFI_EXPORT CCollatorOptions FfiOHOSCollatorOptionsImplResolvedOptions(int64_t id);
|
||||
|
||||
// DateTimeFormat
|
||||
FFI_EXPORT int64_t FfiOHOSDateTimeFormatImplConstructor(int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSDateTimeFormatImplConstructorwithLocale(
|
||||
char *locale, CDateTimeOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSDateTimeFormatImplConstructorwithArrayLocale(
|
||||
CArrString locale, CDateTimeOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT CDateTimeOptions FfiOHOSDateTimeFormatOptionsImplResolvedOptions(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSDateTimeFormatOptionsImplFormat(int64_t id, int64_t date);
|
||||
FFI_EXPORT char *FfiOHOSDateTimeFormatOptionsImplFormatRange(int64_t id, int64_t startDate, int64_t endDate);
|
||||
|
||||
// Locale
|
||||
FFI_EXPORT int64_t FfiOHOSLocaleImplConstructor(int32_t *errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSLocaleImplConstructorwithLocale(
|
||||
char *locale, CLocaleOptions options, int64_t flag, int32_t *errCode);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplToString(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplMinimize(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplMaximize(int64_t id);
|
||||
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetLanguage(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetScript(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetRegion(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetBaseName(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetCaseFirst(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetCalendar(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetCollation(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetHourCycle(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetNumberingSystem(int64_t id);
|
||||
FFI_EXPORT char *FfiOHOSLocaleImplGetNumeric(int64_t id);
|
||||
}
|
||||
|
||||
#endif
|
835
interfaces/cj/intl/intl_impl.cpp
Normal file
835
interfaces/cj/intl/intl_impl.cpp
Normal file
@ -0,0 +1,835 @@
|
||||
/*
|
||||
* 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 "intl_impl.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "cj_lambda.h"
|
||||
|
||||
using namespace OHOS::FFI;
|
||||
|
||||
namespace OHOS::Global::I18n::Intl
|
||||
{
|
||||
std::vector<std::string> ArrayStringToVectorString(CArrString arrString)
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
for (int i = 0; i < arrString.size; i++)
|
||||
{
|
||||
std::string value = arrString.head[i];
|
||||
res.push_back(value);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
char *IMallocCString(const std::string &origin)
|
||||
{
|
||||
if (origin.empty())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
auto length = origin.length() + 1;
|
||||
char *res = static_cast<char *>(malloc(sizeof(char) * length));
|
||||
if (res == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return std::char_traits<char>::copy(res, origin.c_str(), length);
|
||||
}
|
||||
|
||||
NumberFormatImpl::NumberFormatImpl(int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale;
|
||||
std::map<std::string, std::string> map = {};
|
||||
numberFmt_ = std::make_unique<NumberFormat>(locale, map);
|
||||
|
||||
if (numberFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The numberFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NumberFormatImpl::NumberFormatImpl(char *locale, CNumberOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list;
|
||||
std::string locale_str = locale;
|
||||
locale_list.push_back(locale_str);
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
if (std::strlen(options.locale) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("locale", options.locale));
|
||||
}
|
||||
if (std::strlen(options.currency) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("currency", options.currency));
|
||||
}
|
||||
map.insert(std::make_pair("currencySign", options.currencySign));
|
||||
map.insert(std::make_pair("currencyDisplay", options.currencyDisplay));
|
||||
if (std::strlen(options.unit) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("unit", options.unit));
|
||||
}
|
||||
map.insert(std::make_pair("unitDisplay", options.unitDisplay));
|
||||
map.insert(std::make_pair("unitUsage", options.unitUsage));
|
||||
map.insert(std::make_pair("signDispaly", options.signDispaly));
|
||||
map.insert(std::make_pair("compactDisplay", options.compactDisplay));
|
||||
map.insert(std::make_pair("notation", options.notation));
|
||||
map.insert(std::make_pair("localeMather", options.localeMather));
|
||||
map.insert(std::make_pair("style", options.style));
|
||||
if (std::strlen(options.numberingSystem) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("numberingSystem", options.numberingSystem));
|
||||
}
|
||||
std::string value = std::to_string(options.useGrouping) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("useGrouping", value));
|
||||
map.insert(std::make_pair("minimumIntegerDigits", std::to_string(options.minimumIntegerDigits)));
|
||||
map.insert(std::make_pair("minimumFractionDigits", std::to_string(options.minimumFractionDigits)));
|
||||
map.insert(std::make_pair("maximumFractionDigits", std::to_string(options.maximumFractionDigits)));
|
||||
map.insert(std::make_pair("minimumSignificantDigits", std::to_string(options.minimumSignificantDigits)));
|
||||
map.insert(std::make_pair("maximumSignificantDigits", std::to_string(options.maximumSignificantDigits)));
|
||||
if (options.minimumFractionDigits != -1 && options.maximumFractionDigits != -1 &&
|
||||
options.minimumFractionDigits > options.maximumFractionDigits)
|
||||
{
|
||||
HILOG_ERROR_I18N(
|
||||
"GetNumberOptionValues: Invalid parameter value: minimumFractionDigits > maximumFractionDigits");
|
||||
}
|
||||
}
|
||||
numberFmt_ = std::make_unique<NumberFormat>(locale_list, map);
|
||||
|
||||
if (numberFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The numberFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NumberFormatImpl::NumberFormatImpl(CArrString locale, CNumberOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list = ArrayStringToVectorString(locale);
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
if (std::strlen(options.locale) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("locale", options.locale));
|
||||
}
|
||||
if (std::strlen(options.currency) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("currency", options.currency));
|
||||
}
|
||||
map.insert(std::make_pair("currencySign", options.currencySign));
|
||||
map.insert(std::make_pair("currencyDisplay", options.currencyDisplay));
|
||||
if (std::strlen(options.unit) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("unit", options.unit));
|
||||
}
|
||||
map.insert(std::make_pair("unitDisplay", options.unitDisplay));
|
||||
map.insert(std::make_pair("unitUsage", options.unitUsage));
|
||||
map.insert(std::make_pair("signDispaly", options.signDispaly));
|
||||
map.insert(std::make_pair("compactDisplay", options.compactDisplay));
|
||||
map.insert(std::make_pair("notation", options.notation));
|
||||
map.insert(std::make_pair("localeMather", options.localeMather));
|
||||
map.insert(std::make_pair("style", options.style));
|
||||
if (std::strlen(options.numberingSystem) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("numberingSystem", options.numberingSystem));
|
||||
}
|
||||
std::string value = std::to_string(options.useGrouping) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("useGrouping", value));
|
||||
map.insert(std::make_pair("minimumIntegerDigits", std::to_string(options.minimumIntegerDigits)));
|
||||
map.insert(std::make_pair("minimumFractionDigits", std::to_string(options.minimumFractionDigits)));
|
||||
map.insert(std::make_pair("maximumFractionDigits", std::to_string(options.maximumFractionDigits)));
|
||||
map.insert(std::make_pair("minimumSignificantDigits", std::to_string(options.minimumSignificantDigits)));
|
||||
map.insert(std::make_pair("maximumSignificantDigits", std::to_string(options.maximumSignificantDigits)));
|
||||
|
||||
if (options.minimumFractionDigits != -1 && options.maximumFractionDigits != -1 &&
|
||||
options.minimumFractionDigits > options.maximumFractionDigits)
|
||||
{
|
||||
HILOG_ERROR_I18N(
|
||||
"GetNumberOptionValues: Invalid parameter value: minimumFractionDigits > maximumFractionDigits");
|
||||
}
|
||||
}
|
||||
numberFmt_ = std::make_unique<NumberFormat>(locale_list, map);
|
||||
|
||||
if (numberFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The numberFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
char *NumberFormatImpl::Format(double number)
|
||||
{
|
||||
std::string value = numberFmt_->Format(number);
|
||||
return IMallocCString(value);
|
||||
}
|
||||
|
||||
CNumberOptions NumberFormatImpl::ResolveOptions()
|
||||
{
|
||||
std::map<std::string, std::string> options = {};
|
||||
numberFmt_->GetResolvedOptions(options);
|
||||
struct CNumberOptions numberOptions;
|
||||
numberOptions.locale = IMallocCString(options["locale"]);
|
||||
numberOptions.currency = IMallocCString(options["currency"]);
|
||||
numberOptions.currencySign = IMallocCString(options["currencySign"]);
|
||||
numberOptions.unit = IMallocCString(options["unit"]);
|
||||
numberOptions.unitDisplay = IMallocCString(options["unitDisplay"]);
|
||||
numberOptions.unitUsage = IMallocCString(options["unitUsage"]);
|
||||
numberOptions.signDispaly = IMallocCString(options["signDispaly"]);
|
||||
numberOptions.compactDisplay = IMallocCString(options["compactDisplay"]);
|
||||
numberOptions.notation = IMallocCString(options["notation"]);
|
||||
numberOptions.localeMather = IMallocCString(options["localeMather"]);
|
||||
numberOptions.style = IMallocCString(options["style"]);
|
||||
numberOptions.numberingSystem = IMallocCString(options["numberingSystem"]);
|
||||
numberOptions.useGrouping = (options["useGrouping"] == "true");
|
||||
numberOptions.minimumIntegerDigits = atoi(options["minimumIntegerDigits"].c_str());
|
||||
numberOptions.minimumFractionDigits = atoi(options["minimumFractionDigits"].c_str());
|
||||
numberOptions.maximumFractionDigits = atoi(options["maximumFractionDigits"].c_str());
|
||||
numberOptions.minimumSignificantDigits = atoi(options["minimumSignificantDigits"].c_str());
|
||||
numberOptions.maximumSignificantDigits = atoi(options["maximumSignificantDigits"].c_str());
|
||||
|
||||
return numberOptions;
|
||||
}
|
||||
|
||||
RelativeTimeFormatImpl::RelativeTimeFormatImpl(int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale;
|
||||
std::map<std::string, std::string> options = {};
|
||||
relativeTimeFmt_ = std::make_unique<RelativeTimeFormat>(locale, options);
|
||||
|
||||
if (relativeTimeFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The RelativeTimeFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RelativeTimeFormatImpl::RelativeTimeFormatImpl(
|
||||
char *locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list;
|
||||
std::string locale_str = locale;
|
||||
locale_list.push_back(locale_str);
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
map.insert(std::make_pair("localeMatcher", options.localeMatcher));
|
||||
map.insert(std::make_pair("numeric", options.numeric));
|
||||
map.insert(std::make_pair("style", options.style));
|
||||
}
|
||||
relativeTimeFmt_ = std::make_unique<RelativeTimeFormat>(locale_list, map);
|
||||
if (relativeTimeFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The RelativeTimeFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RelativeTimeFormatImpl::RelativeTimeFormatImpl(
|
||||
CArrString locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list = ArrayStringToVectorString(locale);
|
||||
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
map.insert(std::make_pair("localeMatcher", options.localeMatcher));
|
||||
map.insert(std::make_pair("numeric", options.numeric));
|
||||
map.insert(std::make_pair("style", options.style));
|
||||
}
|
||||
relativeTimeFmt_ = std::make_unique<RelativeTimeFormat>(locale_list, map);
|
||||
|
||||
if (relativeTimeFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The RelativeTimeFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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 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];
|
||||
CArrString retime = {.head = nullptr, .size = 0};
|
||||
char **time = reinterpret_cast<char **>(malloc(sizeof(char *) * timeVector.size()));
|
||||
if (time == nullptr)
|
||||
{
|
||||
HILOG_ERROR_I18N("The char** is nullptr");
|
||||
return ret;
|
||||
}
|
||||
for (size_t j = 0; j < timeVector.size(); j++)
|
||||
{
|
||||
std::string value = timeVector[j];
|
||||
time[j] = IMallocCString(value);
|
||||
}
|
||||
retime.head = time;
|
||||
retime.size = timeVector.size();
|
||||
res[i] = retime;
|
||||
}
|
||||
ret.head = res;
|
||||
ret.size = static_cast<int64_t>(timeVectorStr.size());
|
||||
return ret;
|
||||
}
|
||||
|
||||
CRelativeTimeFormatResolveOptions RelativeTimeFormatImpl::ResolveOptions()
|
||||
{
|
||||
std::map<std::string, std::string> options = {};
|
||||
relativeTimeFmt_->GetResolvedOptions(options);
|
||||
struct CRelativeTimeFormatResolveOptions relativeTimeFormatResolveOptions;
|
||||
relativeTimeFormatResolveOptions.localeMatcher = IMallocCString(options["localeMatcher"]);
|
||||
relativeTimeFormatResolveOptions.numeric = IMallocCString(options["numeric"]);
|
||||
relativeTimeFormatResolveOptions.style = IMallocCString(options["style"]);
|
||||
relativeTimeFormatResolveOptions.numberingSystem = IMallocCString(options["numberingSystem"]);
|
||||
return relativeTimeFormatResolveOptions;
|
||||
}
|
||||
|
||||
PluralRulesImpl::PluralRulesImpl(int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale;
|
||||
std::map<std::string, std::string> options = {};
|
||||
pluralRules_ = std::make_unique<PluralRules>(locale, options);
|
||||
|
||||
if (pluralRules_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The PluralRules is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PluralRulesImpl::PluralRulesImpl(char *locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list;
|
||||
std::string locale_str = locale;
|
||||
locale_list.push_back(locale_str);
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
map.insert(std::make_pair("localeMatcher", options.localeMatcher));
|
||||
map.insert(std::make_pair("type", options.type));
|
||||
map.insert(std::make_pair("minimumIntegerDigits", std::to_string(options.minimumIntegerDigits)));
|
||||
map.insert(std::make_pair("minimumFractionDigits", std::to_string(options.minimumFractionDigits)));
|
||||
map.insert(std::make_pair("maximumFractionDigits", std::to_string(options.maximumFractionDigits)));
|
||||
map.insert(std::make_pair("minimumSignificantDigits", std::to_string(options.minimumSignificantDigits)));
|
||||
map.insert(std::make_pair("maximumSignificantDigits", std::to_string(options.maximumSignificantDigits)));
|
||||
}
|
||||
pluralRules_ = std::make_unique<PluralRules>(locale_list, map);
|
||||
|
||||
if (pluralRules_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The PluralRules is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PluralRulesImpl::PluralRulesImpl(CArrString locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list = ArrayStringToVectorString(locale);
|
||||
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
map.insert(std::make_pair("localeMatcher", options.localeMatcher));
|
||||
map.insert(std::make_pair("type", options.type));
|
||||
map.insert(std::make_pair("minimumIntegerDigits", std::to_string(options.minimumIntegerDigits)));
|
||||
map.insert(std::make_pair("minimumFractionDigits", std::to_string(options.minimumFractionDigits)));
|
||||
map.insert(std::make_pair("maximumFractionDigits", std::to_string(options.maximumFractionDigits)));
|
||||
map.insert(std::make_pair("minimumSignificantDigits", std::to_string(options.minimumSignificantDigits)));
|
||||
map.insert(std::make_pair("maximumSignificantDigits", std::to_string(options.maximumSignificantDigits)));
|
||||
}
|
||||
pluralRules_ = std::make_unique<PluralRules>(locale_list, map);
|
||||
|
||||
if (pluralRules_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The PluralRules is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
char *PluralRulesImpl::Select(double n)
|
||||
{
|
||||
std::string value = pluralRules_->Select(n);
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
|
||||
CollatorImpl::CollatorImpl(int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale;
|
||||
std::map<std::string, std::string> options = {};
|
||||
collator_ = std::make_unique<Collator>(locale, options);
|
||||
|
||||
if (collator_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The Collator is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CollatorImpl::CollatorImpl(char *locale, CCollatorOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list;
|
||||
std::string locale_str = locale;
|
||||
locale_list.push_back(locale_str);
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
map.insert(std::make_pair("localeMatcher", options.localeMatcher));
|
||||
map.insert(std::make_pair("usage", options.usage));
|
||||
map.insert(std::make_pair("sensitivity", options.sensitivity));
|
||||
std::string ignore = std::to_string(options.ignorePunctuation) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("ignorePunctuation", ignore));
|
||||
map.insert(std::make_pair("collation", options.collation));
|
||||
std::string num = std::to_string(options.numeric) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("numeric", num));
|
||||
map.insert(std::make_pair("caseFirst", options.caseFirst));
|
||||
}
|
||||
collator_ = std::make_unique<Collator>(locale_list, map);
|
||||
|
||||
if (collator_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The Collator is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CollatorImpl::CollatorImpl(CArrString locale, CCollatorOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list = ArrayStringToVectorString(locale);
|
||||
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
map.insert(std::make_pair("localeMatcher", options.localeMatcher));
|
||||
map.insert(std::make_pair("usage", options.usage));
|
||||
map.insert(std::make_pair("sensitivity", options.sensitivity));
|
||||
std::string ignore = std::to_string(options.ignorePunctuation) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("ignorePunctuation", ignore));
|
||||
map.insert(std::make_pair("collation", options.collation));
|
||||
std::string num = std::to_string(options.numeric) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("numeric", num));
|
||||
map.insert(std::make_pair("caseFirst", options.caseFirst));
|
||||
}
|
||||
collator_ = std::make_unique<Collator>(locale_list, map);
|
||||
|
||||
if (collator_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The Collator is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CCollatorOptions CollatorImpl::ResolveOptions()
|
||||
{
|
||||
std::map<std::string, std::string> options = {};
|
||||
collator_->ResolvedOptions(options);
|
||||
struct CCollatorOptions collatorResolveOptions;
|
||||
collatorResolveOptions.localeMatcher = IMallocCString(options["localeMatcher"]);
|
||||
collatorResolveOptions.usage = IMallocCString(options["usage"]);
|
||||
collatorResolveOptions.sensitivity = IMallocCString(options["sensitivity"]);
|
||||
collatorResolveOptions.ignorePunctuation = (options["ignorePunctuation"] == "true");
|
||||
collatorResolveOptions.collation = IMallocCString(options["collation"]);
|
||||
collatorResolveOptions.numeric = (options["numeric"] == "true");
|
||||
collatorResolveOptions.caseFirst = IMallocCString(options["caseFirst"]);
|
||||
|
||||
return collatorResolveOptions;
|
||||
}
|
||||
|
||||
int32_t CollatorImpl::Compare(char *str1, char *str2)
|
||||
{
|
||||
std::string str1_str = str1;
|
||||
std::string str2_str = str2;
|
||||
int32_t result = collator_->Compare(str1_str, str2_str);
|
||||
return result;
|
||||
}
|
||||
|
||||
DateTimeFormatImpl::DateTimeFormatImpl(int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale;
|
||||
std::map<std::string, std::string> options = {};
|
||||
dateFmt_ = std::make_unique<DateTimeFormat>(locale, options);
|
||||
|
||||
if (dateFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The DateTimeFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DateTimeFormatImpl::DateTimeFormatImpl(char *locale, CDateTimeOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list;
|
||||
std::string locale_str = locale;
|
||||
locale_list.push_back(locale_str);
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
if (std::strlen(options.locale) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("locale", options.locale));
|
||||
}
|
||||
if (std::strlen(options.dateStyle) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("dateStyle", options.dateStyle));
|
||||
}
|
||||
if (std::strlen(options.timeStyle) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("timeStyle", options.timeStyle));
|
||||
}
|
||||
if (std::strlen(options.hourCycle) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("hourCycle", options.hourCycle));
|
||||
}
|
||||
if (std::strlen(options.timeZone) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("timeZone", options.timeZone));
|
||||
}
|
||||
if (std::strlen(options.numberingSystem) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("numberingSystem", options.numberingSystem));
|
||||
}
|
||||
std::string h12 = std::to_string(options.hour12) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("hour12", h12));
|
||||
if (std::strlen(options.weekday) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("weekday", options.weekday));
|
||||
}
|
||||
std::map<std::string, std::string> map1 = MapInsert(options);
|
||||
map.insert(map1.begin(), map1.end());
|
||||
}
|
||||
dateFmt_ = std::make_unique<DateTimeFormat>(locale_list, map);
|
||||
|
||||
if (dateFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The DateTimeFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> DateTimeFormatImpl::MapInsert(CDateTimeOptions options)
|
||||
{
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (std::strlen(options.era) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("era", options.era));
|
||||
}
|
||||
if (std::strlen(options.year) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("year", options.year));
|
||||
}
|
||||
if (std::strlen(options.month) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("month", options.month));
|
||||
}
|
||||
if (std::strlen(options.day) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("day", options.day));
|
||||
}
|
||||
if (std::strlen(options.hour) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("hour", options.hour));
|
||||
}
|
||||
if (std::strlen(options.minute) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("minute", options.minute));
|
||||
}
|
||||
if (std::strlen(options.second) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("second", options.second));
|
||||
}
|
||||
if (std::strlen(options.timeZoneName) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("timeZoneName", options.timeZoneName));
|
||||
}
|
||||
if (std::strlen(options.dayPeriod) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("dayPeriod", options.dayPeriod));
|
||||
}
|
||||
if (std::strlen(options.localeMatcher) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("localeMatcher", options.localeMatcher));
|
||||
}
|
||||
if (std::strlen(options.formatMatcher) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("formatMatcher", options.formatMatcher));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
DateTimeFormatImpl::DateTimeFormatImpl(CArrString locale, CDateTimeOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::vector<std::string> locale_list = ArrayStringToVectorString(locale);
|
||||
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
if (std::strlen(options.locale) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("locale", options.locale));
|
||||
}
|
||||
if (std::strlen(options.dateStyle) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("dateStyle", options.dateStyle));
|
||||
}
|
||||
if (std::strlen(options.timeStyle) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("timeStyle", options.timeStyle));
|
||||
}
|
||||
if (std::strlen(options.hourCycle) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("hourCycle", options.hourCycle));
|
||||
}
|
||||
if (std::strlen(options.timeZone) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("timeZone", options.timeZone));
|
||||
}
|
||||
if (std::strlen(options.numberingSystem) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("numberingSystem", options.numberingSystem));
|
||||
}
|
||||
std::string h12 = std::to_string(options.hour12) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("hour12", h12));
|
||||
if (std::strlen(options.weekday) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("weekday", options.weekday));
|
||||
}
|
||||
std::map<std::string, std::string> map1 = MapInsert(options);
|
||||
map.insert(map1.begin(), map1.end());
|
||||
}
|
||||
dateFmt_ = std::make_unique<DateTimeFormat>(locale_list, map);
|
||||
|
||||
if (dateFmt_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The DateTimeFormat is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CDateTimeOptions DateTimeFormatImpl::ResolveOptions()
|
||||
{
|
||||
std::map<std::string, std::string> options = {};
|
||||
dateFmt_->GetResolvedOptions(options);
|
||||
struct CDateTimeOptions dateTimeOptions;
|
||||
dateTimeOptions.locale = IMallocCString(options["locale"]);
|
||||
dateTimeOptions.dateStyle = IMallocCString(options["dateStyle"]);
|
||||
dateTimeOptions.timeStyle = IMallocCString(options["timeStyle"]);
|
||||
dateTimeOptions.hourCycle = IMallocCString(options["hourCycle"]);
|
||||
dateTimeOptions.timeZone = IMallocCString(options["timeZone"]);
|
||||
dateTimeOptions.numberingSystem = IMallocCString(options["numberingSystem"]);
|
||||
bool h = (options["hour"] == "true");
|
||||
dateTimeOptions.hour12 = h;
|
||||
dateTimeOptions.weekday = IMallocCString(options["weekday"]);
|
||||
dateTimeOptions.era = IMallocCString(options["era"]);
|
||||
dateTimeOptions.year = IMallocCString(options["year"]);
|
||||
dateTimeOptions.month = IMallocCString(options["month"]);
|
||||
dateTimeOptions.day = IMallocCString(options["day"]);
|
||||
dateTimeOptions.hour = IMallocCString(options["hour"]);
|
||||
dateTimeOptions.minute = IMallocCString(options["minute"]);
|
||||
dateTimeOptions.second = IMallocCString(options["second"]);
|
||||
dateTimeOptions.timeZoneName = IMallocCString(options["timeZoneName"]);
|
||||
dateTimeOptions.localeMatcher = IMallocCString(options["localeMatcher"]);
|
||||
dateTimeOptions.formatMatcher = IMallocCString(options["formatMatcher"]);
|
||||
return dateTimeOptions;
|
||||
}
|
||||
|
||||
char *DateTimeFormatImpl::Format(int64_t date)
|
||||
{
|
||||
std::string date_str = dateFmt_->Format(date);
|
||||
char *res = IMallocCString(date_str);
|
||||
return res;
|
||||
}
|
||||
|
||||
char *DateTimeFormatImpl::FormatRange(int64_t startDate, int64_t endDate)
|
||||
{
|
||||
std::string date_str = dateFmt_->FormatRange(startDate, endDate);
|
||||
char *res = IMallocCString(date_str);
|
||||
return res;
|
||||
}
|
||||
|
||||
LocaleImpl::LocaleImpl(int32_t *errCode)
|
||||
{
|
||||
std::string locale_str = "";
|
||||
std::map<std::string, std::string> options = {};
|
||||
locale_ = std::make_unique<LocaleInfo>(locale_str, options);
|
||||
if (locale_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The Locale is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LocaleImpl::LocaleImpl(char *locale, CLocaleOptions options, int64_t flag, int32_t *errCode)
|
||||
{
|
||||
std::string locale_str = locale;
|
||||
|
||||
std::map<std::string, std::string> map = {};
|
||||
if (flag == 0)
|
||||
{
|
||||
if (std::strlen(options.calendar) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("calendar", options.calendar));
|
||||
}
|
||||
if (std::strlen(options.collation) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("collation", options.collation));
|
||||
}
|
||||
if (std::strlen(options.hourCycle) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("hourCycle", options.hourCycle));
|
||||
}
|
||||
if (std::strlen(options.numberingSystem) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("numberingSystem", options.numberingSystem));
|
||||
}
|
||||
std::string num = std::to_string(options.numeric) == "1" ? "true" : "false";
|
||||
map.insert(std::make_pair("numeric", num));
|
||||
if (std::strlen(options.caseFirst) != 0)
|
||||
{
|
||||
map.insert(std::make_pair("caseFirst", options.caseFirst));
|
||||
}
|
||||
}
|
||||
locale_ = std::make_unique<LocaleInfo>(locale_str, map);
|
||||
if (locale_ == nullptr)
|
||||
{
|
||||
*errCode = -1;
|
||||
HILOG_ERROR_I18N("The Locale is nullptr");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
char *LocaleImpl::ToString()
|
||||
{
|
||||
if (locale_ == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
std::string value = locale_->ToString();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
|
||||
char *LocaleImpl::Maximize()
|
||||
{
|
||||
std::string value = locale_->Maximize();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::Minimize()
|
||||
{
|
||||
std::string value = locale_->Minimize();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
|
||||
char *LocaleImpl::GetLanguage()
|
||||
{
|
||||
std::string value = locale_->GetLanguage();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetRegion()
|
||||
{
|
||||
std::string value = locale_->GetRegion();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetScript()
|
||||
{
|
||||
std::string value = locale_->GetScript();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetBaseName()
|
||||
{
|
||||
std::string value = locale_->GetBaseName();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetCaseFirst()
|
||||
{
|
||||
std::string value = locale_->GetCaseFirst();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetCalendar()
|
||||
{
|
||||
std::string value = locale_->GetCalendar();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetCollation()
|
||||
{
|
||||
std::string value = locale_->GetCollation();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetHourCycle()
|
||||
{
|
||||
std::string value = locale_->GetHourCycle();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetNumberingSystem()
|
||||
{
|
||||
std::string value = locale_->GetNumberingSystem();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
char *LocaleImpl::GetNumeric()
|
||||
{
|
||||
std::string value = locale_->GetNumeric();
|
||||
char *res = IMallocCString(value);
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Global::I18n::Intl
|
131
interfaces/cj/intl/intl_impl.h
Normal file
131
interfaces/cj/intl/intl_impl.h
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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 INTL_IMPL_H
|
||||
#define INTL_IMPL_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "intl_ffi.h"
|
||||
#include "ffi_remote_data.h"
|
||||
#include "preferences_observer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
namespace Intl {
|
||||
std::vector<std::string> ArrayStringToVectorString(CArrString arrString);
|
||||
char *IMallocCString(const std::string &origin);
|
||||
class NumberFormatImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(NumberFormatImpl, OHOS::FFI::FFIData)
|
||||
public:
|
||||
explicit NumberFormatImpl(int32_t *errCode);
|
||||
NumberFormatImpl(char *locale, CNumberOptions options, int64_t flag, int32_t *errCode);
|
||||
NumberFormatImpl(CArrString locale, CNumberOptions options, int64_t flag, int32_t *errCode);
|
||||
char *Format(double number);
|
||||
CNumberOptions ResolveOptions();
|
||||
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::NumberFormat> numberFmt_ = nullptr;
|
||||
};
|
||||
|
||||
class RelativeTimeFormatImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(RelativeTimeFormatImpl, OHOS::FFI::FFIData);
|
||||
|
||||
public:
|
||||
explicit RelativeTimeFormatImpl(int32_t *errCode);
|
||||
RelativeTimeFormatImpl(char *locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode);
|
||||
RelativeTimeFormatImpl(
|
||||
CArrString locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode);
|
||||
char *Format(double number, char *unit);
|
||||
CArrArrString FormatToParts(double number, char *unit);
|
||||
CRelativeTimeFormatResolveOptions ResolveOptions();
|
||||
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::RelativeTimeFormat> relativeTimeFmt_ = nullptr;
|
||||
};
|
||||
|
||||
class PluralRulesImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(PluralRulesImpl, OHOS::FFI::FFIData);
|
||||
|
||||
public:
|
||||
explicit PluralRulesImpl(int32_t *errCode);
|
||||
PluralRulesImpl(char *locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode);
|
||||
PluralRulesImpl(CArrString locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode);
|
||||
char *Select(double n);
|
||||
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::PluralRules> pluralRules_ = nullptr;
|
||||
};
|
||||
|
||||
class CollatorImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(CollatorImpl, OHOS::FFI::FFIData);
|
||||
|
||||
public:
|
||||
explicit CollatorImpl(int32_t *errCode);
|
||||
CollatorImpl(char *locale, CCollatorOptions options, int64_t flag, int32_t *errCode);
|
||||
CollatorImpl(CArrString locale, CCollatorOptions options, int64_t flag, int32_t *errCode);
|
||||
CCollatorOptions ResolveOptions();
|
||||
int32_t Compare(char *str1, char *str2);
|
||||
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::Collator> collator_ = nullptr;
|
||||
};
|
||||
|
||||
class DateTimeFormatImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(DateTimeFormatImpl, OHOS::FFI::FFIData);
|
||||
|
||||
public:
|
||||
explicit DateTimeFormatImpl(int32_t *errCode);
|
||||
DateTimeFormatImpl(char *locale, CDateTimeOptions options, int64_t flag, int32_t *errCode);
|
||||
DateTimeFormatImpl(CArrString locale, CDateTimeOptions options, int64_t flag, int32_t *errCode);
|
||||
CDateTimeOptions ResolveOptions();
|
||||
char *Format(int64_t date);
|
||||
char *FormatRange(int64_t startDate, int64_t endDate);
|
||||
std::map<std::string, std::string> MapInsert(CDateTimeOptions options);
|
||||
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::DateTimeFormat> dateFmt_ = nullptr;
|
||||
};
|
||||
|
||||
class LocaleImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(LocaleImpl, OHOS::FFI::FFIData);
|
||||
|
||||
public:
|
||||
explicit LocaleImpl(int32_t *errCode);
|
||||
LocaleImpl(char *locale, CLocaleOptions options, int64_t flag, int32_t *errCode);
|
||||
char *ToString();
|
||||
char *Maximize();
|
||||
char *Minimize();
|
||||
|
||||
char *GetLanguage();
|
||||
char *GetRegion();
|
||||
char *GetScript();
|
||||
char *GetBaseName();
|
||||
char *GetCaseFirst();
|
||||
char *GetCalendar();
|
||||
char *GetCollation();
|
||||
char *GetHourCycle();
|
||||
char *GetNumberingSystem();
|
||||
char *GetNumeric();
|
||||
|
||||
private:
|
||||
std::unique_ptr<OHOS::Global::I18n::LocaleInfo> locale_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Intl
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user