From 79620825bd7c7da25dccbb0e1c21ea11cb68c014 Mon Sep 17 00:00:00 2001 From: WJ Date: Fri, 20 Sep 2024 16:29:36 +0800 Subject: [PATCH 01/42] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=A1=A1=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- frameworks/intl/test/BUILD.gn | 2 +- .../test/unittest/intl_number_format_test.cpp | 216 ------- frameworks/intl/test/unittest/intl_test.h | 7 - .../intl/test/unittest/intl_test_extent.cpp | 20 +- .../intl/test/unittest/number_format_test.cpp | 533 ++++++++++++++++++ .../intl/test/unittest/number_format_test.h | 41 ++ 6 files changed, 585 insertions(+), 234 deletions(-) delete mode 100644 frameworks/intl/test/unittest/intl_number_format_test.cpp create mode 100644 frameworks/intl/test/unittest/number_format_test.cpp create mode 100644 frameworks/intl/test/unittest/number_format_test.h diff --git a/frameworks/intl/test/BUILD.gn b/frameworks/intl/test/BUILD.gn index 072c4034..07e4cf2c 100644 --- a/frameworks/intl/test/BUILD.gn +++ b/frameworks/intl/test/BUILD.gn @@ -23,10 +23,10 @@ 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/number_format_test.cpp", "unittest/mock/src/generate_ics_file.cpp", "unittest/mock/src/i18n_timezone_mock.cpp", "unittest/mock/src/phone_number_format_mock.cpp", diff --git a/frameworks/intl/test/unittest/intl_number_format_test.cpp b/frameworks/intl/test/unittest/intl_number_format_test.cpp deleted file mode 100644 index 7ec9201b..00000000 --- a/frameworks/intl/test/unittest/intl_number_format_test.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include "number_format.h" -#include "intl_test.h" -#include "generate_ics_file.h" -#include "signature_verifier.h" -#include -#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 locales{locale}; - string useGrouping = "true"; - string minimumIntegerDigits = "7"; - string maximumFractionDigits = "2"; - string style = "currency"; - string currency = "978"; - map options = { { "useGrouping", useGrouping }, - { "style", style }, - { "currency", currency }, - { "currencyDisplay", "name" }, - { "currencySign", "accounting" }, - { "signDisplay", "always" } }; - std::unique_ptr numFmt = std::make_unique(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 locales{locale}; - string useGrouping = "true"; - string minimumIntegerDigits = "7"; - string maximumFractionDigits = "2"; - string style = "currency"; - string currency = "111"; - map options = { { "useGrouping", useGrouping }, - { "style", style }, - { "currency", currency }, - { "currencyDisplay", "name" }, - { "currencySign", "accounting" }, - { "signDisplay", "always" } }; - std::unique_ptr numFmt = std::make_unique(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 locales{locale}; - string useGrouping = "true"; - string minimumIntegerDigits = "7"; - string maximumFractionDigits = "2"; - string style = "currency"; - string currency = "a1b"; - map options = { { "useGrouping", useGrouping }, - { "style", style }, - { "currency", currency }, - { "currencyDisplay", "name" }, - { "currencySign", "accounting" }, - { "signDisplay", "always" } }; - std::unique_ptr numFmt = std::make_unique(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 locales{locale}; - string useGrouping = "true"; - string minimumIntegerDigits = "7"; - string maximumFractionDigits = "2"; - string style = "currency"; - string currency = "a#b"; - map options = { { "useGrouping", useGrouping }, - { "style", style }, - { "currency", currency }, - { "currencyDisplay", "name" }, - { "currencySign", "accounting" }, - { "signDisplay", "always" } }; - std::unique_ptr numFmt = std::make_unique(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 locales{locale}; - string useGrouping = "true"; - string minimumIntegerDigits = "7"; - string maximumFractionDigits = "2"; - string style = "currency"; - string currency = "ab"; - map options = { { "useGrouping", useGrouping }, - { "style", style }, - { "currency", currency }, - { "currencyDisplay", "name" }, - { "currencySign", "accounting" }, - { "signDisplay", "always" } }; - std::unique_ptr numFmt = std::make_unique(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 locales{locale}; - string useGrouping = "true"; - string minimumIntegerDigits = "7"; - string maximumFractionDigits = "2"; - string style = "currency"; - string currency = "abcd"; - map options = { { "useGrouping", useGrouping }, - { "style", style }, - { "currency", currency }, - { "currencyDisplay", "name" }, - { "currencySign", "accounting" }, - { "signDisplay", "always" } }; - std::unique_ptr numFmt = std::make_unique(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 \ No newline at end of file diff --git a/frameworks/intl/test/unittest/intl_test.h b/frameworks/intl/test/unittest/intl_test.h index 99fe0ddb..f19540b8 100644 --- a/frameworks/intl/test/unittest/intl_test.h +++ b/frameworks/intl/test/unittest/intl_test.h @@ -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 diff --git a/frameworks/intl/test/unittest/intl_test_extent.cpp b/frameworks/intl/test/unittest/intl_test_extent.cpp index 57479da8..974f9d6f 100644 --- a/frameworks/intl/test/unittest/intl_test_extent.cpp +++ b/frameworks/intl/test/unittest/intl_test_extent.cpp @@ -1834,11 +1834,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) { std::string path = "/data/service/el1/public/i18n/global/GlobalParamData"; OHOS::NativePreferences::Options opt(path); @@ -1868,11 +1868,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"; @@ -1890,11 +1890,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"; @@ -1924,11 +1924,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-"; @@ -1948,11 +1948,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-"; diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp new file mode 100644 index 00000000..393f1d40 --- /dev/null +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -0,0 +1,533 @@ +/* + * Copyright (c) 2021-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. + */ + +#include "number_format_test.h" +#include +#include "locale_config.h" +#include "number_format.h" +#include "unicode/locid.h" +#include "parameter.h" + +using namespace OHOS::Global::I18n; +using testing::ext::TestSize; +using namespace std; + +namespace OHOS { +namespace Global { +namespace I18n { +class NumberFormatTest : public testing::Test { +public: + static string originalLanguage; + static string originalRegion; + static string originalLocale; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +string NumberFormatTest::originalLanguage; +string NumberFormatTest::originalRegion; +string NumberFormatTest::originalLocale; + +void NumberFormatTest::SetUpTestCase(void) +{ + originalLanguage = LocaleConfig::GetSystemLanguage(); + originalRegion = LocaleConfig::GetSystemRegion(); + originalLocale = LocaleConfig::GetSystemLocale(); + LocaleConfig::SetSystemLanguage("zh-Hans"); + LocaleConfig::SetSystemRegion("CN"); + LocaleConfig::SetSystemLocale("zh-Hans-CN"); +} + +void NumberFormatTest::TearDownTestCase(void) +{ + LocaleConfig::SetSystemLanguage(originalLanguage); + LocaleConfig::SetSystemRegion(originalRegion); + LocaleConfig::SetSystemLocale(originalLocale); +} + +void NumberFormatTest::SetUp(void) +{} + +void NumberFormatTest::TearDown(void) +{} + +/** + * @tc.name: NumberFormatFuncTest001 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest001, TestSize.Level1) +{ + string locale = "en-IN"; + string expects = "+1,23,456.79 euros"; + vector locales{locale}; + string useGrouping = "true"; + string minimumIntegerDigits = "7"; + string maximumFractionDigits = "2"; + string style = "currency"; + string currency = "978"; + map options = { { "useGrouping", useGrouping }, + { "style", style }, + { "currency", currency }, + { "currencyDisplay", "name" }, + { "currencySign", "accounting" }, + { "signDisplay", "always" } }; + std::unique_ptr numFmt = std::make_unique(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: NumberFormatFuncTest002 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest002, TestSize.Level1) +{ + string locale = "en-IN"; + string expects = "+1,23,456.789"; + vector locales{locale}; + string useGrouping = "true"; + string minimumIntegerDigits = "7"; + string maximumFractionDigits = "2"; + string style = "currency"; + string currency = "111"; + map options = { { "useGrouping", useGrouping }, + { "style", style }, + { "currency", currency }, + { "currencyDisplay", "name" }, + { "currencySign", "accounting" }, + { "signDisplay", "always" } }; + std::unique_ptr numFmt = std::make_unique(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: NumberFormatFuncTest003 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest003, TestSize.Level1) +{ + string locale = "en-IN"; + string expects = "+1,23,456.789"; + vector locales{locale}; + string useGrouping = "true"; + string minimumIntegerDigits = "7"; + string maximumFractionDigits = "2"; + string style = "currency"; + string currency = "a1b"; + map options = { { "useGrouping", useGrouping }, + { "style", style }, + { "currency", currency }, + { "currencyDisplay", "name" }, + { "currencySign", "accounting" }, + { "signDisplay", "always" } }; + std::unique_ptr numFmt = std::make_unique(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: NumberFormatFuncTest004 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest004, TestSize.Level1) +{ + string locale = "en-IN"; + string expects = "+1,23,456.789"; + vector locales{locale}; + string useGrouping = "true"; + string minimumIntegerDigits = "7"; + string maximumFractionDigits = "2"; + string style = "currency"; + string currency = "a#b"; + map options = { { "useGrouping", useGrouping }, + { "style", style }, + { "currency", currency }, + { "currencyDisplay", "name" }, + { "currencySign", "accounting" }, + { "signDisplay", "always" } }; + std::unique_ptr numFmt = std::make_unique(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: NumberFormatFuncTest005 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest005, TestSize.Level1) +{ + string locale = "en-IN"; + string expects = "+1,23,456.789"; + vector locales{locale}; + string useGrouping = "true"; + string minimumIntegerDigits = "7"; + string maximumFractionDigits = "2"; + string style = "currency"; + string currency = "ab"; + map options = { { "useGrouping", useGrouping }, + { "style", style }, + { "currency", currency }, + { "currencyDisplay", "name" }, + { "currencySign", "accounting" }, + { "signDisplay", "always" } }; + std::unique_ptr numFmt = std::make_unique(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: NumberFormatFuncTest006 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest006, TestSize.Level1) +{ + string locale = "en-IN"; + string expects = "+1,23,456.789"; + vector locales{locale}; + string useGrouping = "true"; + string minimumIntegerDigits = "7"; + string maximumFractionDigits = "2"; + string style = "currency"; + string currency = "abcd"; + map options = { { "useGrouping", useGrouping }, + { "style", style }, + { "currency", currency }, + { "currencyDisplay", "name" }, + { "currencySign", "accounting" }, + { "signDisplay", "always" } }; + std::unique_ptr numFmt = std::make_unique(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: NumberFormatFuncTest007 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest007, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "beat-per-minute"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 次/分钟"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 bpm"); +} + +/** + * @tc.name: NumberFormatFuncTest008 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest008, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "body-weight-per-second"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 BW/s"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 BW/s"); +} + +/** + * @tc.name: NumberFormatFuncTest009 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest009, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "breath-per-minute"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 次/分"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 brpm"); +} + +/** + * @tc.name: NumberFormatFuncTest0010 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0010, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "foot-per-hour"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 ft/h"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 ft/h"); +} + +/** + * @tc.name: NumberFormatFuncTest0011 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string locale_gb = "en-US"; + vector locales_gb{locale_gb}; + string style = "unit"; + string unit = "jump-rope-speed"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 个/分钟"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 jumps/minute"); + out = numFmt_us->Format(1); + EXPECT_EQ(out, "1 jump/minute"); + std::unique_ptr numFmt_gb = std::make_unique(locales_gb, options); + ASSERT_TRUE(numFmt_gb != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 skips/minute"); + out = numFmt_us->Format(1); + EXPECT_EQ(out, "1 skip/minute"); +} + +/** + * @tc.name: NumberFormatFuncTest0012 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0012, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "meter-per-hour"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 m/h"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 m/h"); +} + +/** + * @tc.name: NumberFormatFuncTest0013 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0013, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "milliliter-per-minute-per-kilogram"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 ml/kg/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0014 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0014, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "rotation-per-minute"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 转/分钟"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 rpm"); +} + +/** + * @tc.name: NumberFormatFuncTest0015 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "step-per-minute"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 步/分钟"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 steps/min"); + out = numFmt_us->Format(1); + EXPECT_EQ(out, "1 step/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0016 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1) +{ + string locale_cn = "zh-CN"; + vector locales_cn{locale_cn}; + string locale_us = "en-US"; + vector locales_us{locale_us}; + string style = "unit"; + string unit = "stroke-per-minute"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); + ASSERT_TRUE(numFmt_cn != nullptr); + string out = numFmt_cn->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 次/分钟"); + std::unique_ptr numFmt_us = std::make_unique(locales_us, options); + ASSERT_TRUE(numFmt_us != nullptr); + out = numFmt_us->Format(1234567.89); + EXPECT_EQ(out, "1,234,567.89 strokes/min"); + out = numFmt_us->Format(1); + EXPECT_EQ(out, "1 stroke/min"); +} +} // namespace I18n +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/intl/test/unittest/number_format_test.h b/frameworks/intl/test/unittest/number_format_test.h new file mode 100644 index 00000000..fb7ad110 --- /dev/null +++ b/frameworks/intl/test/unittest/number_format_test.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021-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. + */ + +#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); +} // namespace I18n +} // namespace Global +} // namespace OHOS +#endif \ No newline at end of file From 0a2c9423a565da15930cbdb8ebef82984571314b Mon Sep 17 00:00:00 2001 From: WJ Date: Fri, 20 Sep 2024 16:34:10 +0800 Subject: [PATCH 02/42] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=A1=A1=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- frameworks/intl/test/unittest/number_format_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index 393f1d40..07255da5 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -364,7 +364,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1) vector locales_cn{locale_cn}; string locale_us = "en-US"; vector locales_us{locale_us}; - string locale_gb = "en-US"; + string locale_gb = "en-GB"; vector locales_gb{locale_gb}; string style = "unit"; string unit = "jump-rope-speed"; From 47f226938bffec43044d1faecbf9c3bacb7ad0b7 Mon Sep 17 00:00:00 2001 From: WJ Date: Fri, 20 Sep 2024 16:43:37 +0800 Subject: [PATCH 03/42] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=A1=A1=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- frameworks/intl/test/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/intl/test/BUILD.gn b/frameworks/intl/test/BUILD.gn index 07e4cf2c..b7340240 100644 --- a/frameworks/intl/test/BUILD.gn +++ b/frameworks/intl/test/BUILD.gn @@ -26,10 +26,10 @@ ohos_unittest("intl_test") { "unittest/intl_test.cpp", "unittest/intl_test_extent.cpp", "unittest/locale_config_test.cpp", - "unittest/number_format_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", From f705b7c003a85a170557b1cc7c1c1f0743a9c052 Mon Sep 17 00:00:00 2001 From: WJ Date: Mon, 23 Sep 2024 09:15:13 +0800 Subject: [PATCH 04/42] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=A1=A1=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- frameworks/intl/test/unittest/number_format_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index 07255da5..16a08193 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -384,9 +384,9 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1) EXPECT_EQ(out, "1 jump/minute"); std::unique_ptr numFmt_gb = std::make_unique(locales_gb, options); ASSERT_TRUE(numFmt_gb != nullptr); - out = numFmt_us->Format(1234567.89); + out = numFmt_gb->Format(1234567.89); EXPECT_EQ(out, "1,234,567.89 skips/minute"); - out = numFmt_us->Format(1); + out = numFmt_gb->Format(1); EXPECT_EQ(out, "1 skip/minute"); } From 9d5d46c530852aba1caff4a38a949514f8ae341c Mon Sep 17 00:00:00 2001 From: WJ Date: Mon, 23 Sep 2024 14:23:30 +0800 Subject: [PATCH 05/42] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=A1=A1=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- frameworks/intl/test/unittest/number_format_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index 16a08193..e6b79cd1 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -505,8 +505,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1) * @tc.desc: Test Intl NumberFormat.format * @tc.type: FUNC */ -HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1) -{ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1) { string locale_cn = "zh-CN"; vector locales_cn{locale_cn}; string locale_us = "en-US"; From 5e9e171199739ded580d4d921f4d6611356c6142 Mon Sep 17 00:00:00 2001 From: WJ Date: Mon, 23 Sep 2024 14:23:47 +0800 Subject: [PATCH 06/42] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=A1=A1=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- frameworks/intl/test/unittest/number_format_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index e6b79cd1..16a08193 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -505,7 +505,8 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1) * @tc.desc: Test Intl NumberFormat.format * @tc.type: FUNC */ -HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1) { +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1) +{ string locale_cn = "zh-CN"; vector locales_cn{locale_cn}; string locale_us = "en-US"; From 5325ca4a2c746756f9e47588d84f6b97a7cd35d8 Mon Sep 17 00:00:00 2001 From: WJ Date: Mon, 23 Sep 2024 16:08:18 +0800 Subject: [PATCH 07/42] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=A1=A1=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- frameworks/intl/test/unittest/number_format_test.cpp | 2 +- frameworks/intl/test/unittest/number_format_test.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index 16a08193..1cab0b5d 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 diff --git a/frameworks/intl/test/unittest/number_format_test.h b/frameworks/intl/test/unittest/number_format_test.h index fb7ad110..27ac4bff 100644 --- a/frameworks/intl/test/unittest/number_format_test.h +++ b/frameworks/intl/test/unittest/number_format_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 From abc951fe9431a83104c1c3d35c8f708f02c542c8 Mon Sep 17 00:00:00 2001 From: WJ Date: Tue, 24 Sep 2024 14:18:41 +0800 Subject: [PATCH 08/42] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BA=A6=E9=87=8F?= =?UTF-8?q?=E8=A1=A1=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- .../intl/test/unittest/number_format_test.cpp | 810 ++++++++++++++---- .../intl/test/unittest/number_format_test.h | 20 + 2 files changed, 682 insertions(+), 148 deletions(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index 1cab0b5d..85886397 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -252,24 +252,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest006, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest007, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; string unit = "beat-per-minute"; string unitStyle = "long"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 次/分钟"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 bpm"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 bpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm"); } /** @@ -279,24 +278,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest007, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest008, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; - string unit = "body-weight-per-second"; - string unitStyle = "long"; + string unit = "beat-per-minute"; + string unitStyle = "short"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 BW/s"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 BW/s"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 bpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm"); } /** @@ -306,24 +304,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest008, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest009, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; - string unit = "breath-per-minute"; - string unitStyle = "long"; + string unit = "beat-per-minute"; + string unitStyle = "narrow"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 次/分"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 brpm"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 bpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm"); } /** @@ -333,24 +330,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest009, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0010, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; - string unit = "foot-per-hour"; + string unit = "body-weight-per-second"; string unitStyle = "long"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 ft/h"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 ft/h"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s"); } /** @@ -360,34 +356,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0010, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; - string locale_gb = "en-GB"; - vector locales_gb{locale_gb}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; - string unit = "jump-rope-speed"; - string unitStyle = "long"; + string unit = "body-weight-per-second"; + string unitStyle = "short"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 个/分钟"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 jumps/minute"); - out = numFmt_us->Format(1); - EXPECT_EQ(out, "1 jump/minute"); - std::unique_ptr numFmt_gb = std::make_unique(locales_gb, options); - ASSERT_TRUE(numFmt_gb != nullptr); - out = numFmt_gb->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 skips/minute"); - out = numFmt_gb->Format(1); - EXPECT_EQ(out, "1 skip/minute"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s"); } /** @@ -397,24 +382,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0012, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; - string unit = "meter-per-hour"; - string unitStyle = "long"; + string unit = "body-weight-per-second"; + string unitStyle = "narrow"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 m/h"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 m/h"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s"); } /** @@ -424,24 +408,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0012, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0013, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; - string unit = "milliliter-per-minute-per-kilogram"; + string unit = "breath-per-minute"; string unitStyle = "long"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 ml/kg/min"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 brpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm"); } /** @@ -451,24 +434,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0013, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0014, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; - string unit = "rotation-per-minute"; - string unitStyle = "long"; + string unit = "breath-per-minute"; + string unitStyle = "short"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 转/分钟"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 rpm"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 brpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm"); } /** @@ -478,26 +460,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0014, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; - string unit = "step-per-minute"; - string unitStyle = "long"; + string unit = "breath-per-minute"; + string unitStyle = "narrow"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 步/分钟"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 steps/min"); - out = numFmt_us->Format(1); - EXPECT_EQ(out, "1 step/min"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 brpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm"); } /** @@ -507,26 +486,561 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1) */ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1) { - string locale_cn = "zh-CN"; - vector locales_cn{locale_cn}; - string locale_us = "en-US"; - vector locales_us{locale_us}; + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "foot-per-hour"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h"); +} + +/** + * @tc.name: NumberFormatFuncTest0017 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0017, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "foot-per-hour"; + string unitStyle = "short"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h"); +} + +/** + * @tc.name: NumberFormatFuncTest0018 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0018, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "foot-per-hour"; + string unitStyle = "narrow"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h"); +} + +/** + * @tc.name: NumberFormatFuncTest0019 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0019, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string style = "unit"; + string unit = "jump-rope-speed"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 个/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 jump/minute"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 jumps/minute"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute"); +} + +/** + * @tc.name: NumberFormatFuncTest0020 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0020, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string style = "unit"; + string unit = "jump-rope-speed"; + string unitStyle = "short"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 个/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 jump/minute"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 jumps/minute"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute"); +} + +/** + * @tc.name: NumberFormatFuncTest0021 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0021, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string style = "unit"; + string unit = "jump-rope-speed"; + string unitStyle = "narrow"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 个/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 jump/minute"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 jumps/minute"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute"); +} + +/** + * @tc.name: NumberFormatFuncTest0022 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0022, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "meter-per-hour"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 m/h"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h"); +} + +/** + * @tc.name: NumberFormatFuncTest0023 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0023, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "meter-per-hour"; + string unitStyle = "short"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 m/h"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h"); +} + +/** + * @tc.name: NumberFormatFuncTest0024 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0024, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "meter-per-hour"; + string unitStyle = "narrow"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 m/h"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h"); +} + +/** + * @tc.name: NumberFormatFuncTest0025 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0025, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "milliliter-per-minute-per-kilogram"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0026 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0026, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "milliliter-per-minute-per-kilogram"; + string unitStyle = "short"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0027 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0027, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "milliliter-per-minute-per-kilogram"; + string unitStyle = "narrow"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0028 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0028, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "rotation-per-minute"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 转/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 rpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm"); +} + +/** + * @tc.name: NumberFormatFuncTest0029 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0029, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "rotation-per-minute"; + string unitStyle = "short"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 转/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 rpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm"); +} + +/** + * @tc.name: NumberFormatFuncTest0030 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0030, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "rotation-per-minute"; + string unitStyle = "narrow"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 转/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 rpm"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm"); +} + +/** + * @tc.name: NumberFormatFuncTest0031 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0031, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "step-per-minute"; + string unitStyle = "long"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 步/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 step/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0032 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0032, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "step-per-minute"; + string unitStyle = "short"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 步/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 step/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0033 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0033, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "step-per-minute"; + string unitStyle = "narrow"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 步/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 step/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0034 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0034, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; string style = "unit"; string unit = "stroke-per-minute"; string unitStyle = "long"; map options = { { "style", style}, { "unit", unit }, { "unitStyle", unitStyle } }; - std::unique_ptr numFmt_cn = std::make_unique(locales_cn, options); - ASSERT_TRUE(numFmt_cn != nullptr); - string out = numFmt_cn->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 次/分钟"); - std::unique_ptr numFmt_us = std::make_unique(locales_us, options); - ASSERT_TRUE(numFmt_us != nullptr); - out = numFmt_us->Format(1234567.89); - EXPECT_EQ(out, "1,234,567.89 strokes/min"); - out = numFmt_us->Format(1); - EXPECT_EQ(out, "1 stroke/min"); + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0035 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0035, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "stroke-per-minute"; + string unitStyle = "short"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min"); +} + +/** + * @tc.name: NumberFormatFuncTest0036 + * @tc.desc: Test Intl NumberFormat.format + * @tc.type: FUNC + */ +HWTEST_F(NumberFormatTest, NumberFormatFuncTest0036, TestSize.Level1) +{ + string localeCN = "zh-CN"; + vector localesCN{localeCN}; + string localeUS = "en-US"; + vector localesUS{localeUS}; + string style = "unit"; + string unit = "stroke-per-minute"; + string unitStyle = "narrow"; + map options = { { "style", style}, + { "unit", unit }, + { "unitStyle", unitStyle } }; + std::unique_ptr numFmtCN = std::make_unique(localesCN, options); + ASSERT_TRUE(numFmtCN != nullptr); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟"); + std::unique_ptr numFmtUS = std::make_unique(localesUS, options); + ASSERT_TRUE(numFmtUS != nullptr); + EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min"); + EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min"); } } // namespace I18n } // namespace Global diff --git a/frameworks/intl/test/unittest/number_format_test.h b/frameworks/intl/test/unittest/number_format_test.h index 27ac4bff..4c81c4b5 100644 --- a/frameworks/intl/test/unittest/number_format_test.h +++ b/frameworks/intl/test/unittest/number_format_test.h @@ -35,6 +35,26 @@ 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 From c979a9218144f27f0c0366c24f02f5686d433fbc Mon Sep 17 00:00:00 2001 From: WJ Date: Thu, 26 Sep 2024 21:21:08 +0800 Subject: [PATCH 09/42] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: WJ --- frameworks/intl/test/BUILD.gn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/intl/test/BUILD.gn b/frameworks/intl/test/BUILD.gn index b82145b3..69b868b3 100644 --- a/frameworks/intl/test/BUILD.gn +++ b/frameworks/intl/test/BUILD.gn @@ -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" ] From 2da5df4d6b2f4f951d1234c56bc70aae71b37c51 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Wed, 9 Oct 2024 13:19:34 +0000 Subject: [PATCH 10/42] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!8?= =?UTF-8?q?32=20:=20=E4=BF=AE=E6=94=B9=E6=95=8F=E6=84=9F=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/intl/BUILD.gn | 8 ++++ frameworks/intl/etc/lang/bo.xml | 4 ++ frameworks/intl/etc/lang/en-Latn.xml | 4 ++ .../intl/etc/lang/supported_locales.xml | 1 + frameworks/intl/etc/lang/ug.xml | 4 ++ frameworks/intl/etc/lang/zh-Hans.xml | 4 ++ frameworks/intl/etc/lang/zh-Hant-HK.xml | 40 +++++++++++++++++++ frameworks/intl/etc/lang/zh-Hant.xml | 4 ++ frameworks/intl/etc/region/en-Latn-US.xml | 6 +-- .../intl/test/unittest/locale_config_test.cpp | 8 ++-- 10 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 frameworks/intl/etc/lang/zh-Hant-HK.xml diff --git a/frameworks/intl/BUILD.gn b/frameworks/intl/BUILD.gn index bee5af94..50043591 100644 --- a/frameworks/intl/BUILD.gn +++ b/frameworks/intl/BUILD.gn @@ -149,6 +149,7 @@ ohos_shared_library("intl_util") { ":zh_Hans_lang_xml", ":zh_Hans_region_xml", ":zh_Hans_timezone_xml", + ":zh_Hant_HK_lang_xml", ":zh_Hant_lang_xml", ":zh_datetime_xml", ] @@ -291,6 +292,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/" diff --git a/frameworks/intl/etc/lang/bo.xml b/frameworks/intl/etc/lang/bo.xml index 6c9d553c..9c10bcaf 100644 --- a/frameworks/intl/etc/lang/bo.xml +++ b/frameworks/intl/etc/lang/bo.xml @@ -25,6 +25,10 @@ zh-Hant བརྡ་རྙིང་རྒྱ་ཡིག + + zh-Hant-HK + བརྡ་རྙིང་རྒྱ་ཡིག(ཀྲུང་གོའི་ཞང་ཀང་།) + ro རོ་མ་ནི་ཡའི་སྐད། diff --git a/frameworks/intl/etc/lang/en-Latn.xml b/frameworks/intl/etc/lang/en-Latn.xml index 3021c2b3..31e09e96 100644 --- a/frameworks/intl/etc/lang/en-Latn.xml +++ b/frameworks/intl/etc/lang/en-Latn.xml @@ -25,6 +25,10 @@ zh-Hant Traditional Chinese + + zh-Hant-HK + Traditional Chinese(Hong Kong, China) + ro Romanian diff --git a/frameworks/intl/etc/lang/supported_locales.xml b/frameworks/intl/etc/lang/supported_locales.xml index 83905f83..1f199eab 100644 --- a/frameworks/intl/etc/lang/supported_locales.xml +++ b/frameworks/intl/etc/lang/supported_locales.xml @@ -16,6 +16,7 @@ en-Latn zh-Hans zh-Hant + zh-Hant-HK bo ug \ No newline at end of file diff --git a/frameworks/intl/etc/lang/ug.xml b/frameworks/intl/etc/lang/ug.xml index f161075d..c8281e85 100644 --- a/frameworks/intl/etc/lang/ug.xml +++ b/frameworks/intl/etc/lang/ug.xml @@ -17,6 +17,10 @@ zh-Hant ئەنئەنىۋىي خەنزۇچە + + zh-Hant-HK + ئەنئەنىۋىي خەنزۇچە (جۇڭگو شياڭگاڭ) + ro رومىنچە diff --git a/frameworks/intl/etc/lang/zh-Hans.xml b/frameworks/intl/etc/lang/zh-Hans.xml index eac8beaf..2f5937cf 100644 --- a/frameworks/intl/etc/lang/zh-Hans.xml +++ b/frameworks/intl/etc/lang/zh-Hans.xml @@ -25,6 +25,10 @@ zh-Hant 繁体中文 + + zh-Hant-HK + 繁体中文(中国香港) + ro 罗马尼亚文 diff --git a/frameworks/intl/etc/lang/zh-Hant-HK.xml b/frameworks/intl/etc/lang/zh-Hant-HK.xml new file mode 100644 index 00000000..1baf3e91 --- /dev/null +++ b/frameworks/intl/etc/lang/zh-Hant-HK.xml @@ -0,0 +1,40 @@ + + + + + zh + 中文 + + + zh-Hans + 簡體中文 + + + zh-Hant + 繁體中文 + + + zh-Hant-HK + 繁體中文(中國香港) + + + ro + 羅馬尼亞文 + + + fa + 波斯文 + + \ No newline at end of file diff --git a/frameworks/intl/etc/lang/zh-Hant.xml b/frameworks/intl/etc/lang/zh-Hant.xml index 97745021..1baf3e91 100644 --- a/frameworks/intl/etc/lang/zh-Hant.xml +++ b/frameworks/intl/etc/lang/zh-Hant.xml @@ -25,6 +25,10 @@ zh-Hant 繁體中文 + + zh-Hant-HK + 繁體中文(中國香港) + ro 羅馬尼亞文 diff --git a/frameworks/intl/etc/region/en-Latn-US.xml b/frameworks/intl/etc/region/en-Latn-US.xml index 52c88fe0..b7c06fb8 100644 --- a/frameworks/intl/etc/region/en-Latn-US.xml +++ b/frameworks/intl/etc/region/en-Latn-US.xml @@ -15,14 +15,14 @@ HK - Hong Kong (China) + Hong Kong, China MO - Macao (China) + Macao, China TW - Taiwan (China) + Taiwan, China \ No newline at end of file diff --git a/frameworks/intl/test/unittest/locale_config_test.cpp b/frameworks/intl/test/unittest/locale_config_test.cpp index c82acfd4..9ef95679 100644 --- a/frameworks/intl/test/unittest/locale_config_test.cpp +++ b/frameworks/intl/test/unittest/locale_config_test.cpp @@ -251,7 +251,7 @@ HWTEST_F(LocaleConfigTest, LocaleConfigFuncTest009, TestSize.Level1) regionTag = "HK"; displayName = LocaleConfig::GetDisplayRegion(regionTag, localeTag, false); - EXPECT_EQ(displayName, "Hong Kong (China)"); + EXPECT_EQ(displayName, "Hong Kong, China"); } /** @@ -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)"); } /** From 5783d49343f370a579bc0f9160b640f3e6dc194b Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Sat, 12 Oct 2024 14:31:32 +0800 Subject: [PATCH 11/42] =?UTF-8?q?UErrorCode=E7=94=A8=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=88=A4=E6=96=AD=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/src/collator.cpp | 2 +- frameworks/intl/src/i18n_calendar.cpp | 8 +++--- frameworks/intl/src/i18n_timezone.cpp | 2 +- frameworks/intl/src/locale_config.cpp | 30 ++++++++++---------- frameworks/intl/src/locale_info.cpp | 8 +++--- frameworks/intl/src/number_format.cpp | 2 +- frameworks/intl/src/plural_rules.cpp | 2 +- frameworks/intl/src/relative_time_format.cpp | 2 +- frameworks/zone/src/zone_util.cpp | 16 +++++------ interfaces/js/kits/src/i18n_addon.cpp | 6 ++-- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/frameworks/intl/src/collator.cpp b/frameworks/intl/src/collator.cpp index 93821a29..4926c427 100644 --- a/frameworks/intl/src/collator.cpp +++ b/frameworks/intl/src/collator.cpp @@ -78,7 +78,7 @@ Collator::Collator(std::vector &localeTags, std::mapgetOffset(date, (UBool)local, rawOffset, dstOffset, status); - if (status != U_ZERO_ERROR) { + if (U_FAILURE(status)) { return 0; } return rawOffset + dstOffset; diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index eb5cf6aa..5b5427e9 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -247,13 +247,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 +263,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 +637,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(status); - if (status != U_ZERO_ERROR) { + if (U_FAILURE(status)) { return ""; } if (dialectMap.find(fullLanguage) != dialectMap.end()) { @@ -659,11 +659,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(status); - if (status != U_ZERO_ERROR) { + if (U_FAILURE(status)) { return ""; } return fullLanguage; @@ -676,11 +676,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 +907,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 +937,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; diff --git a/frameworks/intl/src/locale_info.cpp b/frameworks/intl/src/locale_info.cpp index 9c72fc8e..51ed571f 100644 --- a/frameworks/intl/src/locale_info.cpp +++ b/frameworks/intl/src/locale_info.cpp @@ -63,14 +63,14 @@ void LocaleInfo::InitLocaleInfo(const std::string &localeTag, std::map &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; } diff --git a/frameworks/intl/src/plural_rules.cpp b/frameworks/intl/src/plural_rules.cpp index ff1e8893..8964e200 100644 --- a/frameworks/intl/src/plural_rules.cpp +++ b/frameworks/intl/src/plural_rules.cpp @@ -108,7 +108,7 @@ void PluralRules::InitPluralRules(std::vector &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; } diff --git a/frameworks/intl/src/relative_time_format.cpp b/frameworks/intl/src/relative_time_format.cpp index e2f2af90..c1f30e81 100644 --- a/frameworks/intl/src/relative_time_format.cpp +++ b/frameworks/intl/src/relative_time_format.cpp @@ -63,7 +63,7 @@ RelativeTimeFormat::RelativeTimeFormat(const std::vector &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; } diff --git a/frameworks/zone/src/zone_util.cpp b/frameworks/zone/src/zone_util.cpp index 47d0eb99..0c9fb8cc 100644 --- a/frameworks/zone/src/zone_util.cpp +++ b/frameworks/zone/src/zone_util.cpp @@ -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, vectorcount(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 &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; } diff --git a/interfaces/js/kits/src/i18n_addon.cpp b/interfaces/js/kits/src/i18n_addon.cpp index eb72e646..52b2ab93 100644 --- a/interfaces/js/kits/src/i18n_addon.cpp +++ b/interfaces/js/kits/src/i18n_addon.cpp @@ -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(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; From ed8a545ce6834035abc12ca427ab55a475a6bf4c Mon Sep 17 00:00:00 2001 From: LY Date: Tue, 15 Oct 2024 16:17:58 +0800 Subject: [PATCH 12/42] =?UTF-8?q?=E9=80=82=E9=85=8Dohos=5Fsdk=E7=BC=96?= =?UTF-8?q?=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LY --- frameworks/intl/BUILD.gn | 216 ++++++++++++----------- frameworks/intl/include/lunar_calendar.h | 7 - 2 files changed, 109 insertions(+), 114 deletions(-) diff --git a/frameworks/intl/BUILD.gn b/frameworks/intl/BUILD.gn index 16f40b29..7d61e9c8 100644 --- a/frameworks/intl/BUILD.gn +++ b/frameworks/intl/BUILD.gn @@ -77,123 +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", - ] - version_script = "libintl_util.map" + sources = [ "src/lunar_calendar.cpp" ] + external_deps = [ "hilog:libhilog" ] 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_HK_lang_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_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_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", + "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", ] - 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" diff --git a/frameworks/intl/include/lunar_calendar.h b/frameworks/intl/include/lunar_calendar.h index d7c056ee..0ae4bfc2 100644 --- a/frameworks/intl/include/lunar_calendar.h +++ b/frameworks/intl/include/lunar_calendar.h @@ -19,11 +19,6 @@ #include #include -#include "unicode/locid.h" -#include "unicode/calendar.h" -#include "unicode/ucal.h" -#include "unicode/utypes.h" - namespace OHOS { namespace Global { namespace I18n { @@ -73,8 +68,6 @@ private: bool isLeapMonth = false; bool isGregorianLeapYear = false; bool isValidDate = false; - - // icu::Calendar* gregorianCalendar; }; } // namespace I18n } // namespace Global From b5635007954fd8defa8455625d0b741d68a78a3f Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Wed, 16 Oct 2024 17:39:00 +0800 Subject: [PATCH 13/42] =?UTF-8?q?=E6=95=8F=E6=84=9F=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/etc/region/en-Latn-US.xml | 6 +++--- frameworks/intl/test/unittest/locale_config_test.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/intl/etc/region/en-Latn-US.xml b/frameworks/intl/etc/region/en-Latn-US.xml index b7c06fb8..52c88fe0 100644 --- a/frameworks/intl/etc/region/en-Latn-US.xml +++ b/frameworks/intl/etc/region/en-Latn-US.xml @@ -15,14 +15,14 @@ HK - Hong Kong, China + Hong Kong (China) MO - Macao, China + Macao (China) TW - Taiwan, China + Taiwan (China) \ No newline at end of file diff --git a/frameworks/intl/test/unittest/locale_config_test.cpp b/frameworks/intl/test/unittest/locale_config_test.cpp index 9ef95679..e7c20e46 100644 --- a/frameworks/intl/test/unittest/locale_config_test.cpp +++ b/frameworks/intl/test/unittest/locale_config_test.cpp @@ -251,7 +251,7 @@ HWTEST_F(LocaleConfigTest, LocaleConfigFuncTest009, TestSize.Level1) regionTag = "HK"; displayName = LocaleConfig::GetDisplayRegion(regionTag, localeTag, false); - EXPECT_EQ(displayName, "Hong Kong, China"); + EXPECT_EQ(displayName, "Hong Kong (China)"); } /** From bac414c20c7de88079d3fa4ab6940f36c4789a61 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Wed, 16 Oct 2024 20:26:54 +0800 Subject: [PATCH 14/42] =?UTF-8?q?=E6=95=8F=E6=84=9F=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/BUILD.gn | 8 -- frameworks/intl/etc/region/en-Latn-US.xml | 28 ----- .../intl/etc/region/supported_regions.xml | 18 --- frameworks/intl/etc/region/zh-Hans.xml | 28 ----- frameworks/intl/include/locale_config.h | 5 - frameworks/intl/src/locale_config.cpp | 104 +----------------- 6 files changed, 4 insertions(+), 187 deletions(-) delete mode 100644 frameworks/intl/etc/region/en-Latn-US.xml delete mode 100644 frameworks/intl/etc/region/supported_regions.xml delete mode 100644 frameworks/intl/etc/region/zh-Hans.xml diff --git a/frameworks/intl/BUILD.gn b/frameworks/intl/BUILD.gn index 7d61e9c8..13859c99 100644 --- a/frameworks/intl/BUILD.gn +++ b/frameworks/intl/BUILD.gn @@ -146,7 +146,6 @@ ohos_shared_library("intl_util") { ":i18n.para.dac", ":i18n_param_config_xml", ":lang_supported_locales", - ":region_supported_locales_xml", ":root_timezone_xml", ":timezones_xml", ":ug_lang_xml", @@ -344,13 +343,6 @@ ohos_prebuilt_etc("timezones_xml") { subsystem_name = "global" } -ohos_prebuilt_etc("region_supported_locales_xml") { - source = "//base/global/i18n/frameworks/intl/etc/region/supported_regions.xml" - module_install_dir = "usr/ohos_locale_config/region/" - part_name = "i18n" - 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/" diff --git a/frameworks/intl/etc/region/en-Latn-US.xml b/frameworks/intl/etc/region/en-Latn-US.xml deleted file mode 100644 index 52c88fe0..00000000 --- a/frameworks/intl/etc/region/en-Latn-US.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - HK - Hong Kong (China) - - - MO - Macao (China) - - - TW - Taiwan (China) - - \ No newline at end of file diff --git a/frameworks/intl/etc/region/supported_regions.xml b/frameworks/intl/etc/region/supported_regions.xml deleted file mode 100644 index c261d4a1..00000000 --- a/frameworks/intl/etc/region/supported_regions.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - en-Latn-US - zh-Hans - \ No newline at end of file diff --git a/frameworks/intl/etc/region/zh-Hans.xml b/frameworks/intl/etc/region/zh-Hans.xml deleted file mode 100644 index 42baf866..00000000 --- a/frameworks/intl/etc/region/zh-Hans.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - HK - 中国香港 - - - MO - 中国澳门 - - - TW - 中国台湾 - - \ No newline at end of file diff --git a/frameworks/intl/include/locale_config.h b/frameworks/intl/include/locale_config.h index d5e31a18..813d0ba0 100644 --- a/frameworks/intl/include/locale_config.h +++ b/frameworks/intl/include/locale_config.h @@ -151,9 +151,7 @@ private: static const char *OVERRIDE_SUPPORTED_REGIONS_PATH; static const char *DIALECT_LANGS_PATH; static const char *DIALECT_LANGS_NAME; - static const char *REGION_PATH; static std::mutex dialectLocaleMutex; - static std::mutex region2DisplayNameMutex; static std::mutex locale2DisplayNameMutex; static const std::unordered_set& GetSupportedLocales(); @@ -174,7 +172,6 @@ private: static void ReadRegionData(const char *regionDataPath); static void ProcessForbiddenRegions(const std::unordered_set &forbiddenRegions); static void SetSupportedDialectLocales(const char* key, const char* value); - static void SetRegion2DisplayName(const char* key, const char* value); static void SetLocale2DisplayName(const char* key, const char* value); static bool Is24HourLocale(const std::string& systemLocale); static bool HasDesignator(const std::string& inFormat, const char designator); @@ -262,7 +259,6 @@ private: static std::unordered_set supportedRegions; static std::unordered_set supportLocales; static std::unordered_set dialectLang; - static std::unordered_set overrideSupportedRegions; static std::unordered_set blockedLanguages; static std::unordered_set blockedRegions; static std::unordered_map> blockedLanguageRegions; @@ -272,7 +268,6 @@ private: static std::unordered_map dialectMap; static std::unordered_map localDigitMap; static std::map locale2DisplayName; - static std::map region2DisplayName; static std::string currentDialectLocale; static std::string currentOverrideRegion; static std::set validCaTag; diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index b53b7137..5dec9fc2 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -69,13 +69,9 @@ const char *LocaleConfig::SUPPORT_LOCALES_PATH = "/etc/ohos_lang_config/supporte const char *LocaleConfig::SUPPORT_LOCALES_NAME = "supported_locales"; const char *LocaleConfig::DIALECT_LANGS_PATH = "/system/usr/ohos_locale_config/dialect_languages.xml"; const char *LocaleConfig::DIALECT_LANGS_NAME = "dialect_langs"; -const char *LocaleConfig::OVERRIDE_SUPPORTED_REGIONS_NAME = "supported_regions"; -const char *LocaleConfig::OVERRIDE_SUPPORTED_REGIONS_PATH = - "/system/usr/ohos_locale_config/region/supported_regions.xml"; const char *LocaleConfig::DEFAULT_LOCALE = "en-Latn"; const char *LocaleConfig::supportLocalesTag = "supported_locales"; const char *LocaleConfig::LANG_PATH = "/etc/ohos_lang_config/"; -const char *LocaleConfig::REGION_PATH = "/system/usr/ohos_locale_config/region/"; const char *LocaleConfig::rootTag = "languages"; const char *LocaleConfig::secondRootTag = "lang"; const char *LocaleConfig::rootRegion = "regions"; @@ -84,7 +80,6 @@ const char *LocaleConfig::NUMBER_SYSTEM_KEY = "-nu-"; unordered_set LocaleConfig::supportedLocales; unordered_set LocaleConfig::supportLocales; unordered_set LocaleConfig::supportedRegions; -unordered_set LocaleConfig::overrideSupportedRegions; unordered_set LocaleConfig::dialectLang; unordered_set LocaleConfig::blockedLanguages; unordered_set LocaleConfig::blockedRegions; @@ -131,11 +126,9 @@ unordered_map LocaleConfig::localDigitMap { std::map LocaleConfig::supportedDialectLocales; std::map LocaleConfig::locale2DisplayName {}; -std::map LocaleConfig::region2DisplayName {}; std::string LocaleConfig::currentDialectLocale = ""; std::string LocaleConfig::currentOverrideRegion = ""; std::mutex LocaleConfig::dialectLocaleMutex; -std::mutex LocaleConfig::region2DisplayNameMutex; std::mutex LocaleConfig::locale2DisplayNameMutex; set LocaleConfig::validCaTag { @@ -586,7 +579,6 @@ bool LocaleConfig::InitializeLists() Expunge(whiteLanguages, blockedLanguages); GetListFromFile(SUPPORTED_LOCALES_PATH, SUPPORTED_LOCALES_NAME, supportedLocales); GetListFromFile(SUPPORT_LOCALES_PATH, SUPPORT_LOCALES_NAME, supportLocales); - GetListFromFile(OVERRIDE_SUPPORTED_REGIONS_PATH, OVERRIDE_SUPPORTED_REGIONS_NAME, overrideSupportedRegions); GetListFromFile(DIALECT_LANGS_PATH, DIALECT_LANGS_NAME, dialectLang); ExtendWhiteLanguages(); return true; @@ -792,13 +784,6 @@ void LocaleConfig::ReadLangData(const char *langDataPath) xmlFreeDoc(doc); } -void LocaleConfig::SetRegion2DisplayName(const char* key, const char* value) -{ - std::lock_guard regionDisplayLock(region2DisplayNameMutex); - region2DisplayName.insert( - std::make_pair(key, value)); -} - void LocaleConfig::SetLocale2DisplayName(const char* key, const char* value) { std::lock_guard localeDisplayLock(locale2DisplayNameMutex); @@ -806,54 +791,6 @@ void LocaleConfig::SetLocale2DisplayName(const char* key, const char* value) std::make_pair(key, value)); } -void LocaleConfig::ReadRegionData(const char *regionDataPath) -{ - xmlKeepBlanksDefault(0); - if (regionDataPath == nullptr) { - return; - } - xmlDocPtr doc = xmlParseFile(regionDataPath); - if (!doc) { - HILOG_INFO_I18N("can not open region data file"); - return; - } - xmlNodePtr cur = xmlDocGetRootElement(doc); - if (cur) { - HILOG_INFO_I18N("cur pointer is true"); - } - if (!cur || xmlStrcmp(cur->name, reinterpret_cast(rootRegion))) { - xmlFreeDoc(doc); - HILOG_INFO_I18N("parse region data file failed"); - return; - } - cur = cur->xmlChildrenNode; - while (cur != nullptr && !xmlStrcmp(cur->name, reinterpret_cast(secondRootRegion))) { - xmlChar *regionContents[ELEMENT_NUM] = { 0 }; - xmlNodePtr regionValue = cur->xmlChildrenNode; - bool xmlNodeNull = false; - for (size_t i = 0; i < ELEMENT_NUM && regionValue != nullptr; i++) { - regionContents[i] = xmlNodeGetContent(regionValue); - regionValue = regionValue->next; - if (regionContents[i] == nullptr) { - xmlNodeNull = true; - } - } - if (!xmlNodeNull) { - // 0 represents langid index, 1 represents displayname index - const char* regionKey = reinterpret_cast(regionContents[0]); - const char* regionVal = reinterpret_cast(regionContents[1]); - SetRegion2DisplayName(regionKey, regionVal); - } - for (size_t i = 0; i < ELEMENT_NUM; i++) { - if (regionContents[i] != nullptr) { - xmlFree(regionContents[i]); - } - } - cur = cur->next; - } - xmlFreeDoc(doc); -} - string LocaleConfig::GetDisplayLanguageWithDialect(const std::string &localeStr, const std::string &displayLocale) { std::string finalLocale = ComputeLocale(displayLocale); @@ -892,37 +829,6 @@ string LocaleConfig::GetDisplayLanguageWithDialect(const std::string &localeStr, return ""; } -string LocaleConfig::GetDisplayOverrideRegion(const std::string ®ion, const std::string &displayLocale) -{ - UErrorCode status = U_ZERO_ERROR; - icu::Locale originLocale; - icu::UnicodeString displayRegion; - if (displayLocale.compare(currentOverrideRegion) != 0) { - std::string xmlPath = REGION_PATH + displayLocale + ".xml"; - region2DisplayName.clear(); - ReadRegionData(xmlPath.c_str()); - currentOverrideRegion = displayLocale; - } - if (region2DisplayName.find(region) != region2DisplayName.end()) { - return region2DisplayName.at(region); - } else { - icu::Locale locale = icu::Locale::forLanguageTag(displayLocale, status); - if (U_FAILURE(status)) { - return ""; - } - if (IsValidRegion(region)) { - icu::LocaleBuilder builder = icu::LocaleBuilder().setRegion(region); - originLocale = builder.build(status); - } else { - originLocale = icu::Locale::forLanguageTag(region, status); - } - originLocale.getDisplayCountry(locale, displayRegion); - std::string result; - displayRegion.toUTF8String(result); - return result; - } -} - string LocaleConfig::GetDisplayRegion(const string ®ion, const string &displayLocale, bool sentenceCase) { UErrorCode status = U_ZERO_ERROR; @@ -947,12 +853,10 @@ string LocaleConfig::GetDisplayRegion(const string ®ion, const string &displa icu::UnicodeString unistr; icu::UnicodeString displayRegion; std::string result; - if (overrideSupportedRegions.find(displayLocale) != overrideSupportedRegions.end()) { - result = GetDisplayOverrideRegion(region, displayLocale); - } else { - originLocale.getDisplayCountry(locale, displayRegion); - displayRegion.toUTF8String(result); - } + + originLocale.getDisplayCountry(locale, displayRegion); + displayRegion.toUTF8String(result); + if (sentenceCase) { char ch = static_cast(toupper(result[0])); return PseudoLocalizationProcessor(result.replace(0, 1, 1, ch)); From ff95efe1dcf3456fbd0e2effede661ce95ba37b6 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Wed, 16 Oct 2024 20:30:24 +0800 Subject: [PATCH 15/42] =?UTF-8?q?=E6=95=8F=E6=84=9F=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/src/locale_config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index 5dec9fc2..2e79bc55 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -857,7 +857,7 @@ string LocaleConfig::GetDisplayRegion(const string ®ion, const string &displa originLocale.getDisplayCountry(locale, displayRegion); displayRegion.toUTF8String(result); - if (sentenceCase) { + if (sentenceCase && !result.empty()) { char ch = static_cast(toupper(result[0])); return PseudoLocalizationProcessor(result.replace(0, 1, 1, ch)); } From 17a310f08caccd6e7f991eed0a1ddca6dab7b6f9 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Thu, 17 Oct 2024 09:14:34 +0800 Subject: [PATCH 16/42] =?UTF-8?q?=E6=95=8F=E6=84=9F=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/BUILD.gn | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/frameworks/intl/BUILD.gn b/frameworks/intl/BUILD.gn index 13859c99..82531491 100644 --- a/frameworks/intl/BUILD.gn +++ b/frameworks/intl/BUILD.gn @@ -140,7 +140,6 @@ ohos_shared_library("intl_util") { ":config_locales_xml", ":dialect_languages_xml", ":en_Latn_lang_xml", - ":en_Latn_region_xml", ":en_datetime_xml", ":i18n.para", ":i18n.para.dac", @@ -150,7 +149,6 @@ ohos_shared_library("intl_util") { ":timezones_xml", ":ug_lang_xml", ":zh_Hans_lang_xml", - ":zh_Hans_region_xml", ":zh_Hans_timezone_xml", ":zh_Hant_HK_lang_xml", ":zh_Hant_lang_xml", @@ -343,20 +341,6 @@ ohos_prebuilt_etc("timezones_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/" From ab31e31f58ff173e383ec058c622b70f69eaa2cf Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Fri, 18 Oct 2024 11:14:59 +0800 Subject: [PATCH 17/42] =?UTF-8?q?=E5=BD=92=E5=B1=9E=E5=9C=B0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=9C=B0=E5=8C=BA=E5=90=8D=E7=A7=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/src/phone_number_format.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/frameworks/intl/src/phone_number_format.cpp b/frameworks/intl/src/phone_number_format.cpp index cbe35edb..560232a3 100644 --- a/frameworks/intl/src/phone_number_format.cpp +++ b/frameworks/intl/src/phone_number_format.cpp @@ -302,9 +302,6 @@ std::string PhoneNumberFormat::getPhoneLocationName( locName = recvArr; } } - if (locName.empty()) { - locName = LocaleConfig::GetDisplayRegion(regionCode, displayLocale, false); - } return locName; } From e6cdc3c6903010c7ada23e25aa0e573c61007345 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Tue, 22 Oct 2024 09:48:48 +0800 Subject: [PATCH 18/42] =?UTF-8?q?=E6=95=8F=E6=84=9F=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/BUILD.gn | 8 ++ .../intl/etc/region/supported_regions.xml | 16 +++ frameworks/intl/include/locale_config.h | 5 + frameworks/intl/src/locale_config.cpp | 106 +++++++++++++++++- 4 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 frameworks/intl/etc/region/supported_regions.xml diff --git a/frameworks/intl/BUILD.gn b/frameworks/intl/BUILD.gn index 82531491..21bdd775 100644 --- a/frameworks/intl/BUILD.gn +++ b/frameworks/intl/BUILD.gn @@ -145,6 +145,7 @@ ohos_shared_library("intl_util") { ":i18n.para.dac", ":i18n_param_config_xml", ":lang_supported_locales", + ":region_supported_locales_xml", ":root_timezone_xml", ":timezones_xml", ":ug_lang_xml", @@ -341,6 +342,13 @@ ohos_prebuilt_etc("timezones_xml") { subsystem_name = "global" } +ohos_prebuilt_etc("region_supported_locales_xml") { + source = "//base/global/i18n/frameworks/intl/etc/region/supported_regions.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/" diff --git a/frameworks/intl/etc/region/supported_regions.xml b/frameworks/intl/etc/region/supported_regions.xml new file mode 100644 index 00000000..9d1fffca --- /dev/null +++ b/frameworks/intl/etc/region/supported_regions.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/frameworks/intl/include/locale_config.h b/frameworks/intl/include/locale_config.h index 813d0ba0..d5e31a18 100644 --- a/frameworks/intl/include/locale_config.h +++ b/frameworks/intl/include/locale_config.h @@ -151,7 +151,9 @@ private: static const char *OVERRIDE_SUPPORTED_REGIONS_PATH; static const char *DIALECT_LANGS_PATH; static const char *DIALECT_LANGS_NAME; + static const char *REGION_PATH; static std::mutex dialectLocaleMutex; + static std::mutex region2DisplayNameMutex; static std::mutex locale2DisplayNameMutex; static const std::unordered_set& GetSupportedLocales(); @@ -172,6 +174,7 @@ private: static void ReadRegionData(const char *regionDataPath); static void ProcessForbiddenRegions(const std::unordered_set &forbiddenRegions); static void SetSupportedDialectLocales(const char* key, const char* value); + static void SetRegion2DisplayName(const char* key, const char* value); static void SetLocale2DisplayName(const char* key, const char* value); static bool Is24HourLocale(const std::string& systemLocale); static bool HasDesignator(const std::string& inFormat, const char designator); @@ -259,6 +262,7 @@ private: static std::unordered_set supportedRegions; static std::unordered_set supportLocales; static std::unordered_set dialectLang; + static std::unordered_set overrideSupportedRegions; static std::unordered_set blockedLanguages; static std::unordered_set blockedRegions; static std::unordered_map> blockedLanguageRegions; @@ -268,6 +272,7 @@ private: static std::unordered_map dialectMap; static std::unordered_map localDigitMap; static std::map locale2DisplayName; + static std::map region2DisplayName; static std::string currentDialectLocale; static std::string currentOverrideRegion; static std::set validCaTag; diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index 2e79bc55..b53b7137 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -69,9 +69,13 @@ const char *LocaleConfig::SUPPORT_LOCALES_PATH = "/etc/ohos_lang_config/supporte const char *LocaleConfig::SUPPORT_LOCALES_NAME = "supported_locales"; const char *LocaleConfig::DIALECT_LANGS_PATH = "/system/usr/ohos_locale_config/dialect_languages.xml"; const char *LocaleConfig::DIALECT_LANGS_NAME = "dialect_langs"; +const char *LocaleConfig::OVERRIDE_SUPPORTED_REGIONS_NAME = "supported_regions"; +const char *LocaleConfig::OVERRIDE_SUPPORTED_REGIONS_PATH = + "/system/usr/ohos_locale_config/region/supported_regions.xml"; const char *LocaleConfig::DEFAULT_LOCALE = "en-Latn"; const char *LocaleConfig::supportLocalesTag = "supported_locales"; const char *LocaleConfig::LANG_PATH = "/etc/ohos_lang_config/"; +const char *LocaleConfig::REGION_PATH = "/system/usr/ohos_locale_config/region/"; const char *LocaleConfig::rootTag = "languages"; const char *LocaleConfig::secondRootTag = "lang"; const char *LocaleConfig::rootRegion = "regions"; @@ -80,6 +84,7 @@ const char *LocaleConfig::NUMBER_SYSTEM_KEY = "-nu-"; unordered_set LocaleConfig::supportedLocales; unordered_set LocaleConfig::supportLocales; unordered_set LocaleConfig::supportedRegions; +unordered_set LocaleConfig::overrideSupportedRegions; unordered_set LocaleConfig::dialectLang; unordered_set LocaleConfig::blockedLanguages; unordered_set LocaleConfig::blockedRegions; @@ -126,9 +131,11 @@ unordered_map LocaleConfig::localDigitMap { std::map LocaleConfig::supportedDialectLocales; std::map LocaleConfig::locale2DisplayName {}; +std::map LocaleConfig::region2DisplayName {}; std::string LocaleConfig::currentDialectLocale = ""; std::string LocaleConfig::currentOverrideRegion = ""; std::mutex LocaleConfig::dialectLocaleMutex; +std::mutex LocaleConfig::region2DisplayNameMutex; std::mutex LocaleConfig::locale2DisplayNameMutex; set LocaleConfig::validCaTag { @@ -579,6 +586,7 @@ bool LocaleConfig::InitializeLists() Expunge(whiteLanguages, blockedLanguages); GetListFromFile(SUPPORTED_LOCALES_PATH, SUPPORTED_LOCALES_NAME, supportedLocales); GetListFromFile(SUPPORT_LOCALES_PATH, SUPPORT_LOCALES_NAME, supportLocales); + GetListFromFile(OVERRIDE_SUPPORTED_REGIONS_PATH, OVERRIDE_SUPPORTED_REGIONS_NAME, overrideSupportedRegions); GetListFromFile(DIALECT_LANGS_PATH, DIALECT_LANGS_NAME, dialectLang); ExtendWhiteLanguages(); return true; @@ -784,6 +792,13 @@ void LocaleConfig::ReadLangData(const char *langDataPath) xmlFreeDoc(doc); } +void LocaleConfig::SetRegion2DisplayName(const char* key, const char* value) +{ + std::lock_guard regionDisplayLock(region2DisplayNameMutex); + region2DisplayName.insert( + std::make_pair(key, value)); +} + void LocaleConfig::SetLocale2DisplayName(const char* key, const char* value) { std::lock_guard localeDisplayLock(locale2DisplayNameMutex); @@ -791,6 +806,54 @@ void LocaleConfig::SetLocale2DisplayName(const char* key, const char* value) std::make_pair(key, value)); } +void LocaleConfig::ReadRegionData(const char *regionDataPath) +{ + xmlKeepBlanksDefault(0); + if (regionDataPath == nullptr) { + return; + } + xmlDocPtr doc = xmlParseFile(regionDataPath); + if (!doc) { + HILOG_INFO_I18N("can not open region data file"); + return; + } + xmlNodePtr cur = xmlDocGetRootElement(doc); + if (cur) { + HILOG_INFO_I18N("cur pointer is true"); + } + if (!cur || xmlStrcmp(cur->name, reinterpret_cast(rootRegion))) { + xmlFreeDoc(doc); + HILOG_INFO_I18N("parse region data file failed"); + return; + } + cur = cur->xmlChildrenNode; + while (cur != nullptr && !xmlStrcmp(cur->name, reinterpret_cast(secondRootRegion))) { + xmlChar *regionContents[ELEMENT_NUM] = { 0 }; + xmlNodePtr regionValue = cur->xmlChildrenNode; + bool xmlNodeNull = false; + for (size_t i = 0; i < ELEMENT_NUM && regionValue != nullptr; i++) { + regionContents[i] = xmlNodeGetContent(regionValue); + regionValue = regionValue->next; + if (regionContents[i] == nullptr) { + xmlNodeNull = true; + } + } + if (!xmlNodeNull) { + // 0 represents langid index, 1 represents displayname index + const char* regionKey = reinterpret_cast(regionContents[0]); + const char* regionVal = reinterpret_cast(regionContents[1]); + SetRegion2DisplayName(regionKey, regionVal); + } + for (size_t i = 0; i < ELEMENT_NUM; i++) { + if (regionContents[i] != nullptr) { + xmlFree(regionContents[i]); + } + } + cur = cur->next; + } + xmlFreeDoc(doc); +} + string LocaleConfig::GetDisplayLanguageWithDialect(const std::string &localeStr, const std::string &displayLocale) { std::string finalLocale = ComputeLocale(displayLocale); @@ -829,6 +892,37 @@ string LocaleConfig::GetDisplayLanguageWithDialect(const std::string &localeStr, return ""; } +string LocaleConfig::GetDisplayOverrideRegion(const std::string ®ion, const std::string &displayLocale) +{ + UErrorCode status = U_ZERO_ERROR; + icu::Locale originLocale; + icu::UnicodeString displayRegion; + if (displayLocale.compare(currentOverrideRegion) != 0) { + std::string xmlPath = REGION_PATH + displayLocale + ".xml"; + region2DisplayName.clear(); + ReadRegionData(xmlPath.c_str()); + currentOverrideRegion = displayLocale; + } + if (region2DisplayName.find(region) != region2DisplayName.end()) { + return region2DisplayName.at(region); + } else { + icu::Locale locale = icu::Locale::forLanguageTag(displayLocale, status); + if (U_FAILURE(status)) { + return ""; + } + if (IsValidRegion(region)) { + icu::LocaleBuilder builder = icu::LocaleBuilder().setRegion(region); + originLocale = builder.build(status); + } else { + originLocale = icu::Locale::forLanguageTag(region, status); + } + originLocale.getDisplayCountry(locale, displayRegion); + std::string result; + displayRegion.toUTF8String(result); + return result; + } +} + string LocaleConfig::GetDisplayRegion(const string ®ion, const string &displayLocale, bool sentenceCase) { UErrorCode status = U_ZERO_ERROR; @@ -853,11 +947,13 @@ string LocaleConfig::GetDisplayRegion(const string ®ion, const string &displa icu::UnicodeString unistr; icu::UnicodeString displayRegion; std::string result; - - originLocale.getDisplayCountry(locale, displayRegion); - displayRegion.toUTF8String(result); - - if (sentenceCase && !result.empty()) { + if (overrideSupportedRegions.find(displayLocale) != overrideSupportedRegions.end()) { + result = GetDisplayOverrideRegion(region, displayLocale); + } else { + originLocale.getDisplayCountry(locale, displayRegion); + displayRegion.toUTF8String(result); + } + if (sentenceCase) { char ch = static_cast(toupper(result[0])); return PseudoLocalizationProcessor(result.replace(0, 1, 1, ch)); } From f460b96dcbb7299017f11fae4bac32bb9899eff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=89=91?= Date: Wed, 23 Oct 2024 10:30:36 +0800 Subject: [PATCH 19/42] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=9D=E9=B2=9C=E3=80=81=E4=B8=8D=E4=B8=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王剑 --- frameworks/intl/etc/i18n_param_config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/intl/etc/i18n_param_config.xml b/frameworks/intl/etc/i18n_param_config.xml index 766893bc..aa85c03c 100644 --- a/frameworks/intl/etc/i18n_param_config.xml +++ b/frameworks/intl/etc/i18n_param_config.xml @@ -13,7 +13,7 @@ limitations under the License. --> - 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 + 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,KP,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 zh-Hans,en-Latn-US,zh-Hant,bo,ug From 770f2a8241307c18a02143d36931b61a93145bfb Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Wed, 23 Oct 2024 16:20:24 +0800 Subject: [PATCH 20/42] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BD=92=E5=B1=9E?= =?UTF-8?q?=E5=9C=B0=E5=85=88=E6=A0=A1=E9=AA=8C=E5=8F=B7=E7=A0=81=E6=9C=89?= =?UTF-8?q?=E6=95=88=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/src/phone_number_format.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frameworks/intl/src/phone_number_format.cpp b/frameworks/intl/src/phone_number_format.cpp index 560232a3..c507534a 100644 --- a/frameworks/intl/src/phone_number_format.cpp +++ b/frameworks/intl/src/phone_number_format.cpp @@ -240,6 +240,9 @@ std::string PhoneNumberFormat::FormatAllInputNumber(const std::string &originalN std::string PhoneNumberFormat::getLocationName( const std::string &number, const std::string &locale) { + if (!isValidPhoneNumber(number)) { + return ""; + } // Combine country and locale parameters UErrorCode status = U_ZERO_ERROR; icu::Locale displayLocale = icu::Locale::createFromName(locale.c_str()); From 1cd035503271b11d69faadc87f9535dfe684a9e6 Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 23 Oct 2024 11:46:05 +0800 Subject: [PATCH 21/42] =?UTF-8?q?lunar=20calendar=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E8=A7=84=E6=95=B4=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LY --- frameworks/intl/BUILD.gn | 8 ++-- frameworks/intl/include/lunar_calendar.h | 8 +++- frameworks/intl/src/lunar_calendar.cpp | 46 ++++++++++++++++++++- frameworks/intl/test/unittest/i18n_test.cpp | 29 +++++++++++++ frameworks/intl/test/unittest/i18n_test.h | 1 + 5 files changed, 86 insertions(+), 6 deletions(-) diff --git a/frameworks/intl/BUILD.gn b/frameworks/intl/BUILD.gn index 21bdd775..17a555ab 100644 --- a/frameworks/intl/BUILD.gn +++ b/frameworks/intl/BUILD.gn @@ -78,7 +78,11 @@ ohos_shared_library("intl_util") { public_configs = [ ":intl_util_config" ] include_dirs = [] sources = [ "src/lunar_calendar.cpp" ] - external_deps = [ "hilog:libhilog" ] + external_deps = [ + "hilog:libhilog", + "icu:shared_icui18n", + "icu:shared_icuuc", + ] cflags_cc = [ "-Wall", "-fPIC", @@ -161,8 +165,6 @@ ohos_shared_library("intl_util") { "c_utils:utils", "config_policy:configpolicy_util", "icu:icundk", - "icu:shared_icui18n", - "icu:shared_icuuc", "init:libbegetutil", "ipc:ipc_core", "libphonenumber:phonenumber_standard", diff --git a/frameworks/intl/include/lunar_calendar.h b/frameworks/intl/include/lunar_calendar.h index 0ae4bfc2..80f2ec76 100644 --- a/frameworks/intl/include/lunar_calendar.h +++ b/frameworks/intl/include/lunar_calendar.h @@ -19,6 +19,10 @@ #include #include +#include "unicode/calendar.h" +#include "unicode/ucal.h" +#include "unicode/utypes.h" + namespace OHOS { namespace Global { namespace I18n { @@ -34,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); @@ -41,7 +46,7 @@ private: bool IsGregorianLeapYear(int32_t year); static std::unordered_map daysOfMonth; static std::unordered_map accDaysOfMonth; - static std::vector lunarDateInfo; + static std::vector 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; @@ -68,6 +73,7 @@ private: bool isLeapMonth = false; bool isGregorianLeapYear = false; bool isValidDate = false; + icu::Calendar* calendar_; }; } // namespace I18n } // namespace Global diff --git a/frameworks/intl/src/lunar_calendar.cpp b/frameworks/intl/src/lunar_calendar.cpp index a95a9a92..ae5b1577 100644 --- a/frameworks/intl/src/lunar_calendar.cpp +++ b/frameworks/intl/src/lunar_calendar.cpp @@ -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 LunarCalendar::accDaysOfMonth { { 12, 334 } }; -std::vector LunarCalendar::lunarDateInfo { +std::vector 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 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) && diff --git a/frameworks/intl/test/unittest/i18n_test.cpp b/frameworks/intl/test/unittest/i18n_test.cpp index 13c72585..7e50b69b 100644 --- a/frameworks/intl/test/unittest/i18n_test.cpp +++ b/frameworks/intl/test/unittest/i18n_test.cpp @@ -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 ptr = std::make_unique(); + 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 \ No newline at end of file diff --git a/frameworks/intl/test/unittest/i18n_test.h b/frameworks/intl/test/unittest/i18n_test.h index 410827a7..1e65a171 100644 --- a/frameworks/intl/test/unittest/i18n_test.h +++ b/frameworks/intl/test/unittest/i18n_test.h @@ -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 From 5833bd248fe93c3e9b23aa950e5713ff3d40fe86 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Thu, 24 Oct 2024 11:43:11 +0800 Subject: [PATCH 22/42] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/intl/src/phone_number_format.cpp | 3 --- frameworks/intl/src/utils.cpp | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/frameworks/intl/src/phone_number_format.cpp b/frameworks/intl/src/phone_number_format.cpp index c507534a..560232a3 100644 --- a/frameworks/intl/src/phone_number_format.cpp +++ b/frameworks/intl/src/phone_number_format.cpp @@ -240,9 +240,6 @@ std::string PhoneNumberFormat::FormatAllInputNumber(const std::string &originalN std::string PhoneNumberFormat::getLocationName( const std::string &number, const std::string &locale) { - if (!isValidPhoneNumber(number)) { - return ""; - } // Combine country and locale parameters UErrorCode status = U_ZERO_ERROR; icu::Locale displayLocale = icu::Locale::createFromName(locale.c_str()); diff --git a/frameworks/intl/src/utils.cpp b/frameworks/intl/src/utils.cpp index 0b656d00..a9700a79 100644 --- a/frameworks/intl/src/utils.cpp +++ b/frameworks/intl/src/utils.cpp @@ -335,7 +335,7 @@ std::set 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(); From d1570b37fca55590c20cb7fc150703fd8fe4a350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=89=91?= Date: Mon, 28 Oct 2024 21:12:29 +0800 Subject: [PATCH 23/42] =?UTF-8?q?=E6=B7=BB=E5=8A=A0TDD=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王剑 --- .../intl/test/unittest/number_format_test.cpp | 804 +++++++++++++++++- 1 file changed, 798 insertions(+), 6 deletions(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index 85886397..7dfb96d5 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -256,6 +256,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest007, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "beat-per-minute"; string unitStyle = "long"; @@ -269,6 +279,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest007, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 bpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 bpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 bpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "ق/م 1"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "ق/م 1,234,567.89"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘"); } /** @@ -282,6 +309,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest008, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "beat-per-minute"; string unitStyle = "short"; @@ -295,6 +332,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest008, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 bpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 bpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 bpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "ق/م 1"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "ق/م 1,234,567.89"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘"); } /** @@ -308,6 +362,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest009, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "beat-per-minute"; string unitStyle = "narrow"; @@ -321,6 +385,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest009, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 bpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 bpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 bpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "ق/م 1"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "ق/م 1,234,567.89"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘"); } /** @@ -334,6 +415,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0010, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "body-weight-per-second"; string unitStyle = "long"; @@ -347,6 +438,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0010, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 BW/s"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 BW/s"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 BW/s"); } /** @@ -360,6 +468,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "body-weight-per-second"; string unitStyle = "short"; @@ -373,6 +491,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 BW/s"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 BW/s"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 BW/s"); } /** @@ -386,6 +521,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0012, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "body-weight-per-second"; string unitStyle = "narrow"; @@ -399,6 +544,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0012, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 BW/s"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 BW/s"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 BW/s"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 BW/s"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 BW/s"); } /** @@ -412,6 +574,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0013, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "breath-per-minute"; string unitStyle = "long"; @@ -425,6 +597,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0013, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 brpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 brpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 brpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分"); } /** @@ -438,6 +627,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0014, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "breath-per-minute"; string unitStyle = "short"; @@ -451,6 +650,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0014, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 brpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 brpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 brpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分"); } /** @@ -464,6 +680,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "breath-per-minute"; string unitStyle = "narrow"; @@ -477,6 +703,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 brpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 brpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 brpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分"); } /** @@ -490,6 +733,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "foot-per-hour"; string unitStyle = "long"; @@ -498,11 +751,28 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1) { "unitStyle", unitStyle } }; std::unique_ptr numFmtCN = std::make_unique(localesCN, options); ASSERT_TRUE(numFmtCN != nullptr); - EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ft/h"); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 英尺/小时"); std::unique_ptr numFmtUS = std::make_unique(localesUS, options); ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 ft/h"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 呎/小時"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 英尺/小時"); } /** @@ -516,6 +786,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0017, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "foot-per-hour"; string unitStyle = "short"; @@ -524,11 +804,28 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0017, TestSize.Level1) { "unitStyle", unitStyle } }; std::unique_ptr numFmtCN = std::make_unique(localesCN, options); ASSERT_TRUE(numFmtCN != nullptr); - EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ft/h"); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 英尺/小时"); std::unique_ptr numFmtUS = std::make_unique(localesUS, options); ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 ft/h"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 呎/小時"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 英尺/小時"); } /** @@ -542,6 +839,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0018, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "foot-per-hour"; string unitStyle = "narrow"; @@ -550,11 +857,28 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0018, TestSize.Level1) { "unitStyle", unitStyle } }; std::unique_ptr numFmtCN = std::make_unique(localesCN, options); ASSERT_TRUE(numFmtCN != nullptr); - EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ft/h"); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 英尺/小时"); std::unique_ptr numFmtUS = std::make_unique(localesUS, options); ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 ft/h"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ft/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ft/h"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 呎/小時"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 英尺/小時"); } /** @@ -570,6 +894,14 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0019, TestSize.Level1) vector localesUS{localeUS}; string localeGB = "en-GB"; vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "jump-rope-speed"; string unitStyle = "long"; @@ -587,6 +919,19 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0019, TestSize.Level1) ASSERT_TRUE(numFmtGB != nullptr); EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute"); EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ئاتلام/مىنۇت"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 個/分鐘"); } /** @@ -602,6 +947,14 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0020, TestSize.Level1) vector localesUS{localeUS}; string localeGB = "en-GB"; vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "jump-rope-speed"; string unitStyle = "short"; @@ -619,6 +972,19 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0020, TestSize.Level1) ASSERT_TRUE(numFmtGB != nullptr); EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute"); EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ئاتلام/مىنۇت"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 個/分鐘"); } /** @@ -634,6 +1000,14 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0021, TestSize.Level1) vector localesUS{localeUS}; string localeGB = "en-GB"; vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "jump-rope-speed"; string unitStyle = "narrow"; @@ -651,6 +1025,19 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0021, TestSize.Level1) ASSERT_TRUE(numFmtGB != nullptr); EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute"); EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ئاتلام/مىنۇت"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 個/分鐘"); } /** @@ -664,6 +1051,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0022, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "meter-per-hour"; string unitStyle = "long"; @@ -672,11 +1069,28 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0022, TestSize.Level1) { "unitStyle", unitStyle } }; std::unique_ptr numFmtCN = std::make_unique(localesCN, options); ASSERT_TRUE(numFmtCN != nullptr); - EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 m/h"); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 米/小时"); std::unique_ptr numFmtUS = std::make_unique(localesUS, options); ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 m/h"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 m/h"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 m/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 m/h"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 公尺/小時"); } /** @@ -690,6 +1104,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0023, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "meter-per-hour"; string unitStyle = "short"; @@ -698,11 +1122,28 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0023, TestSize.Level1) { "unitStyle", unitStyle } }; std::unique_ptr numFmtCN = std::make_unique(localesCN, options); ASSERT_TRUE(numFmtCN != nullptr); - EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 m/h"); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 米/小时"); std::unique_ptr numFmtUS = std::make_unique(localesUS, options); ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 m/h"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 m/h"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 m/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 m/h"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 公尺/小時"); } /** @@ -716,6 +1157,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0024, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "meter-per-hour"; string unitStyle = "narrow"; @@ -724,11 +1175,28 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0024, TestSize.Level1) { "unitStyle", unitStyle } }; std::unique_ptr numFmtCN = std::make_unique(localesCN, options); ASSERT_TRUE(numFmtCN != nullptr); - EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 m/h"); + EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 米/小时"); std::unique_ptr numFmtUS = std::make_unique(localesUS, options); ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 m/h"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 m/h"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 m/h"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 m/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 m/h"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 公尺/小時"); } /** @@ -742,6 +1210,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0025, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "milliliter-per-minute-per-kilogram"; string unitStyle = "long"; @@ -755,6 +1233,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0025, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ml/kg/min"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 ml/kg/min"); } /** @@ -768,6 +1263,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0026, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "milliliter-per-minute-per-kilogram"; string unitStyle = "short"; @@ -781,6 +1286,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0026, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ml/kg/min"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 ml/kg/min"); } /** @@ -794,6 +1316,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0027, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "milliliter-per-minute-per-kilogram"; string unitStyle = "narrow"; @@ -807,6 +1339,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0027, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ml/kg/min"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 ml/kg/min"); } /** @@ -820,6 +1369,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0028, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "rotation-per-minute"; string unitStyle = "long"; @@ -833,6 +1392,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0028, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 rpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 rpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 rpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་སྐོར་བ་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 轉/分鐘"); } /** @@ -846,6 +1422,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0029, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "rotation-per-minute"; string unitStyle = "short"; @@ -859,6 +1445,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0029, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 rpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 rpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 rpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་སྐོར་བ་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 轉/分鐘"); } /** @@ -872,6 +1475,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0030, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "rotation-per-minute"; string unitStyle = "narrow"; @@ -885,6 +1498,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0030, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 rpm"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 rpm"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 rpm"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་སྐོར་བ་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 轉/分鐘"); } /** @@ -898,6 +1528,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0031, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "step-per-minute"; string unitStyle = "long"; @@ -911,6 +1551,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0031, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 step/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 step/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 steps/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "%1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 步/分鐘"); } /** @@ -924,6 +1581,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0032, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "step-per-minute"; string unitStyle = "short"; @@ -937,6 +1604,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0032, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 step/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 step/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 steps/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "%1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 步/分鐘"); } /** @@ -950,6 +1634,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0033, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "step-per-minute"; string unitStyle = "narrow"; @@ -963,6 +1657,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0033, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 step/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 step/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 steps/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "%1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 步/分鐘"); } /** @@ -976,6 +1687,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0034, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "stroke-per-minute"; string unitStyle = "long"; @@ -989,6 +1710,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0034, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 stroke/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 strokes/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 پالاق/مىنۇت"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘"); } /** @@ -1002,6 +1740,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0035, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "stroke-per-minute"; string unitStyle = "short"; @@ -1015,6 +1763,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0035, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 stroke/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 strokes/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 پالاق/مىنۇت"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘"); } /** @@ -1028,6 +1793,16 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0036, TestSize.Level1) vector localesCN{localeCN}; string localeUS = "en-US"; vector localesUS{localeUS}; + string localeGB = "en-GB"; + vector localesGB{localeGB}; + string localeBO = "bo"; + vector localesBO{localeBO}; + string localeUG = "ug"; + vector localesUG{localeUG}; + string localeHK = "zh-HK"; + vector localesHK{localeHK}; + string localeTW = "zh-TW"; + vector localesTW{localeTW}; string style = "unit"; string unit = "stroke-per-minute"; string unitStyle = "narrow"; @@ -1041,6 +1816,23 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0036, TestSize.Level1) ASSERT_TRUE(numFmtUS != nullptr); EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min"); EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min"); + std::unique_ptr numFmtGB = std::make_unique(localesGB, options); + ASSERT_TRUE(numFmtGB != nullptr); + EXPECT_EQ(numFmtGB->Format(1), "1 stroke/min"); + EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 strokes/min"); + std::unique_ptr numFmtBO = std::make_unique(localesBO, options); + ASSERT_TRUE(numFmtBO != nullptr); + EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); + std::unique_ptr numFmtUG = std::make_unique(localesUG, options); + ASSERT_TRUE(numFmtUG != nullptr); + EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 پالاق/مىنۇت"); + std::unique_ptr numFmtHK = std::make_unique(localesHK, options); + ASSERT_TRUE(numFmtHK != nullptr); + EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); + std::unique_ptr numFmtTW = std::make_unique(localesTW, options); + ASSERT_TRUE(numFmtTW != nullptr); + EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘"); } } // namespace I18n } // namespace Global From 99731fee978edc17e49390226e9d0fae5080b8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=89=91?= Date: Tue, 29 Oct 2024 10:06:25 +0800 Subject: [PATCH 24/42] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=B4=E8=AF=ADTDD?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王剑 --- .../intl/test/unittest/number_format_test.cpp | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index 7dfb96d5..c93983a7 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -288,8 +288,8 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest007, TestSize.Level1) EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); - EXPECT_EQ(numFmtUG->Format(1), "ق/م 1"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "ق/م 1,234,567.89"); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -341,8 +341,8 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest008, TestSize.Level1) EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); - EXPECT_EQ(numFmtUG->Format(1), "ق/م 1"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "ق/م 1,234,567.89"); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -394,8 +394,8 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest009, TestSize.Level1) EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89"); std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); - EXPECT_EQ(numFmtUG->Format(1), "ق/م 1"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "ق/م 1,234,567.89"); + EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -448,7 +448,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0010, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 BW/s"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 BW/s"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 BW/s"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒"); @@ -501,7 +501,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 BW/s"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 BW/s"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 BW/s"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒"); @@ -554,7 +554,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0012, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 BW/s"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 BW/s"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 BW/s"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒"); @@ -607,7 +607,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0013, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -660,7 +660,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0014, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -713,7 +713,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -925,7 +925,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0019, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ئاتلام/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ئاتلام/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -978,7 +978,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0020, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ئاتلام/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ئاتلام/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -1031,7 +1031,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0021, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ئاتلام/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ئاتلام/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -1084,7 +1084,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0022, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 m/h"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 m/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 m/h"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時"); @@ -1137,7 +1137,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0023, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 m/h"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 m/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 m/h"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時"); @@ -1190,7 +1190,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0024, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 m/h"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 m/h"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 m/h"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時"); @@ -1243,7 +1243,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0025, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ml/kg/min"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ml/kg/min"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min"); @@ -1296,7 +1296,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0026, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ml/kg/min"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ml/kg/min"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min"); @@ -1349,7 +1349,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0027, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ml/kg/min"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ml/kg/min"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min"); @@ -1402,7 +1402,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0028, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘"); @@ -1455,7 +1455,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0029, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘"); @@ -1508,7 +1508,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0030, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘"); @@ -1560,8 +1560,8 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0031, TestSize.Level1) EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89"); std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); - EXPECT_EQ(numFmtUG->Format(1), "%1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1), "1 قەدەم/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 قەدەم/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘"); @@ -1613,8 +1613,8 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0032, TestSize.Level1) EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89"); std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); - EXPECT_EQ(numFmtUG->Format(1), "%1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1), "1 قەدەم/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 قەدەم/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘"); @@ -1666,8 +1666,8 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0033, TestSize.Level1) EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89"); std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); - EXPECT_EQ(numFmtUG->Format(1), "%1 ق/م"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 ق/م"); + EXPECT_EQ(numFmtUG->Format(1), "1 قەدەم/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 قەدەم/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘"); @@ -1720,7 +1720,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0034, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 پالاق/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 پالاق/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -1773,7 +1773,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0035, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 پالاق/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 پالاق/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); @@ -1826,7 +1826,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0036, TestSize.Level1) std::unique_ptr numFmtUG = std::make_unique(localesUG, options); ASSERT_TRUE(numFmtUG != nullptr); EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت"); - EXPECT_EQ(numFmtUG->Format(1234567.89), "1234567.89 پالاق/مىنۇت"); + EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 پالاق/مىنۇت"); std::unique_ptr numFmtHK = std::make_unique(localesHK, options); ASSERT_TRUE(numFmtHK != nullptr); EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘"); From 561284086230ec087d85d8c3c4383f005dbde92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=89=91?= Date: Wed, 30 Oct 2024 09:18:33 +0800 Subject: [PATCH 25/42] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王剑 --- frameworks/intl/test/unittest/number_format_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/intl/test/unittest/number_format_test.cpp b/frameworks/intl/test/unittest/number_format_test.cpp index c93983a7..ca99923b 100644 --- a/frameworks/intl/test/unittest/number_format_test.cpp +++ b/frameworks/intl/test/unittest/number_format_test.cpp @@ -903,7 +903,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0019, TestSize.Level1) string localeTW = "zh-TW"; vector localesTW{localeTW}; string style = "unit"; - string unit = "jump-rope-speed"; + string unit = "jump-rope-per-minute"; string unitStyle = "long"; map options = { { "style", style}, { "unit", unit }, @@ -956,7 +956,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0020, TestSize.Level1) string localeTW = "zh-TW"; vector localesTW{localeTW}; string style = "unit"; - string unit = "jump-rope-speed"; + string unit = "jump-rope-per-minute"; string unitStyle = "short"; map options = { { "style", style}, { "unit", unit }, @@ -1009,7 +1009,7 @@ HWTEST_F(NumberFormatTest, NumberFormatFuncTest0021, TestSize.Level1) string localeTW = "zh-TW"; vector localesTW{localeTW}; string style = "unit"; - string unit = "jump-rope-speed"; + string unit = "jump-rope-per-minute"; string unitStyle = "narrow"; map options = { { "style", style}, { "unit", unit }, From ba823adab96f4068205c0e3cbe33f427a67ee035 Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 30 Oct 2024 02:31:34 +0000 Subject: [PATCH 26/42] update frameworks/intl/test/unittest/i18n_test.cpp. Signed-off-by: LY --- frameworks/intl/test/unittest/i18n_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/intl/test/unittest/i18n_test.cpp b/frameworks/intl/test/unittest/i18n_test.cpp index 7e50b69b..94ee8114 100644 --- a/frameworks/intl/test/unittest/i18n_test.cpp +++ b/frameworks/intl/test/unittest/i18n_test.cpp @@ -356,7 +356,7 @@ HWTEST_F(I18nTest, I18nFuncTest009, TestSize.Level1) for (size_t i = 0; i < sizeof(regionTags) / sizeof(std::string); ++i) { GetDefaultPreferredUnit(regionTags[i], usage, units); EXPECT_EQ(units.size(), 3); - units.clear(); + units.clear(); //test } } From 4f9cdb0635333677354f2c1335e36412b87f798b Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 30 Oct 2024 11:56:41 +0000 Subject: [PATCH 27/42] update frameworks/intl/src/locale_config.cpp. Signed-off-by: LY --- frameworks/intl/src/locale_config.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index b53b7137..f5cecd68 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -1351,6 +1351,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("24Hour"); + } if (!OHOS::EventFwk::CommonEventManager::PublishCommonEvent(event)) { HILOG_ERROR_I18N("LocaleConfig::PublishCommonEvent Failed to Publish event %{public}s", localeChangeWant.GetAction().c_str()); From ecefa2329be8f2fcddb49ff2b293275d841d336e Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 30 Oct 2024 11:58:41 +0000 Subject: [PATCH 28/42] update frameworks/intl/test/unittest/i18n_test.cpp. Signed-off-by: LY --- frameworks/intl/test/unittest/i18n_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/intl/test/unittest/i18n_test.cpp b/frameworks/intl/test/unittest/i18n_test.cpp index 94ee8114..7e50b69b 100644 --- a/frameworks/intl/test/unittest/i18n_test.cpp +++ b/frameworks/intl/test/unittest/i18n_test.cpp @@ -356,7 +356,7 @@ HWTEST_F(I18nTest, I18nFuncTest009, TestSize.Level1) for (size_t i = 0; i < sizeof(regionTags) / sizeof(std::string); ++i) { GetDefaultPreferredUnit(regionTags[i], usage, units); EXPECT_EQ(units.size(), 3); - units.clear(); //test + units.clear(); } } From d23087570aa14bd6500eb0b1db3de5d78cb75b45 Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 30 Oct 2024 12:00:26 +0000 Subject: [PATCH 29/42] update frameworks/intl/include/locale_config.h. Signed-off-by: LY --- frameworks/intl/include/locale_config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/intl/include/locale_config.h b/frameworks/intl/include/locale_config.h index d5e31a18..e9a12e83 100644 --- a/frameworks/intl/include/locale_config.h +++ b/frameworks/intl/include/locale_config.h @@ -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; From d15f8fae4f3b4924898429c310da6e2d1a0defce Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 30 Oct 2024 12:02:23 +0000 Subject: [PATCH 30/42] update frameworks/intl/src/locale_config.cpp. Signed-off-by: LY --- frameworks/intl/src/locale_config.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index f5cecd68..e182760f 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -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 LocaleConfig::supportedLocales; unordered_set LocaleConfig::supportLocales; unordered_set LocaleConfig::supportedRegions; @@ -1352,7 +1353,7 @@ I18nErrorCode LocaleConfig::PublishCommonEvent(const std::string &eventType) localeChangeWant.SetAction(eventType); OHOS::EventFwk::CommonEventData event(localeChangeWant); if (EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED.compare(eventType) == 0) { - event.SetData("24Hour"); + event.SetData(HOUR_EVENT_DATA); } if (!OHOS::EventFwk::CommonEventManager::PublishCommonEvent(event)) { HILOG_ERROR_I18N("LocaleConfig::PublishCommonEvent Failed to Publish event %{public}s", From ef2a0104139926dff9eea3b7ac2aa536920699bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=89=91?= Date: Mon, 4 Nov 2024 14:33:19 +0800 Subject: [PATCH 31/42] =?UTF-8?q?=E5=9B=9E=E9=80=80=E6=9C=9D=E9=B2=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王剑 --- frameworks/intl/etc/i18n_param_config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/intl/etc/i18n_param_config.xml b/frameworks/intl/etc/i18n_param_config.xml index aa85c03c..d6089dbb 100644 --- a/frameworks/intl/etc/i18n_param_config.xml +++ b/frameworks/intl/etc/i18n_param_config.xml @@ -13,7 +13,7 @@ limitations under the License. --> - 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,KP,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 + 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 zh-Hans,en-Latn-US,zh-Hant,bo,ug From 0ac2ab4ffb1f93027d945909694ef246d3f7a3d7 Mon Sep 17 00:00:00 2001 From: LY Date: Mon, 4 Nov 2024 15:54:04 +0800 Subject: [PATCH 32/42] =?UTF-8?q?=E8=A1=A5=E5=85=85=E7=BB=B4=E6=B5=8B?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LY --- frameworks/intl/include/utils.h | 1 + frameworks/intl/src/locale_config.cpp | 6 ++++++ frameworks/intl/src/utils.cpp | 17 +++++++++++++++-- .../intl/test/unittest/intl_test_extent.cpp | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/frameworks/intl/include/utils.h b/frameworks/intl/include/utils.h index 6e1676bb..3658c02d 100644 --- a/frameworks/intl/include/utils.h +++ b/frameworks/intl/include/utils.h @@ -52,6 +52,7 @@ bool CheckSystemPermission(); size_t ConvertBytesToSizeT(const char *byteArray); std::set 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 diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index e182760f..5a81d8c1 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -1198,6 +1198,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) { @@ -1223,6 +1225,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 resionCode = LocaleEncode(regionTag); + HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion: set region %{public}s.", resionCode.c_str()); return SetSystemLocale(UpdateRegionOfLocale(regionTag)); } @@ -1232,6 +1236,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; } diff --git a/frameworks/intl/src/utils.cpp b/frameworks/intl/src/utils.cpp index a9700a79..29e70a82 100644 --- a/frameworks/intl/src/utils.cpp +++ b/frameworks/intl/src/utils.cpp @@ -13,13 +13,14 @@ * limitations under the License. */ -#include #include +#include #include #include #include -#include +#include #include +#include #include #include #include @@ -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; @@ -350,6 +353,16 @@ bool RegexSearchNoExcept(const std::string& str, std::smatch& match, const std:: return false; } } + +std::string LocaleEncode(const std::string& locale) +{ + std::stringstream ss; + for (auto& c : locale) { + int32_t number = (c == '-') ? 0 : static_cast(c) - static_cast(CHAR_A) + 1; + ss << std::setw(CHAR2INT_SIZE) << std::setfill('0') << number; + } + return ss.str(); +} } // namespace I18n } // namespace Global } // namespace OHOS \ No newline at end of file diff --git a/frameworks/intl/test/unittest/intl_test_extent.cpp b/frameworks/intl/test/unittest/intl_test_extent.cpp index d7dbc203..7a5633b2 100644 --- a/frameworks/intl/test/unittest/intl_test_extent.cpp +++ b/frameworks/intl/test/unittest/intl_test_extent.cpp @@ -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(zh-Hans-CN); + std::string targetCode = "58400008334651000314"; + EXPECT_TRUE(localeCode, targetCode); + std::string localeRule = "zh-Hans"; DateTimeRule* dateTimeRule = new DateTimeRule(localeRule); DateTimeFilter* dateTimeFilter = new DateTimeFilter(localeRule, dateTimeRule); From b1bc9f9418f6da72476e9fffc4d6253722ac0279 Mon Sep 17 00:00:00 2001 From: LY Date: Mon, 4 Nov 2024 09:48:41 +0000 Subject: [PATCH 33/42] update frameworks/intl/test/unittest/intl_test_extent.cpp. Signed-off-by: LY --- frameworks/intl/test/unittest/intl_test_extent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/intl/test/unittest/intl_test_extent.cpp b/frameworks/intl/test/unittest/intl_test_extent.cpp index 7a5633b2..a16f8230 100644 --- a/frameworks/intl/test/unittest/intl_test_extent.cpp +++ b/frameworks/intl/test/unittest/intl_test_extent.cpp @@ -538,7 +538,7 @@ HWTEST_F(IntlTest, IntlFuncTest0062, TestSize.Level1) StrReplaceAll(str, target, replace); std::string localeTag = "zh-Hans-CN"; - std::string localeCode = LocaleEncode(zh-Hans-CN); + std::string localeCode = LocaleEncode(localeTag); std::string targetCode = "58400008334651000314"; EXPECT_TRUE(localeCode, targetCode); From 1349fbdb3d11dbe621869ea9012fb8a1735e9434 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Tue, 5 Nov 2024 09:46:20 +0800 Subject: [PATCH 34/42] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- .../date_time_recognition/src/date_time_filter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/intl/entity_recognition/date_time_recognition/src/date_time_filter.cpp b/frameworks/intl/entity_recognition/date_time_recognition/src/date_time_filter.cpp index 5b13831b..990e6ead 100644 --- a/frameworks/intl/entity_recognition/date_time_recognition/src/date_time_filter.cpp +++ b/frameworks/intl/entity_recognition/date_time_recognition/src/date_time_filter.cpp @@ -95,7 +95,7 @@ std::vector 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 +181,7 @@ std::vector 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; From a476a7c6191250aecfb9add668c1d48b40d81e4c Mon Sep 17 00:00:00 2001 From: LY Date: Tue, 5 Nov 2024 01:21:03 +0000 Subject: [PATCH 35/42] update frameworks/intl/test/unittest/intl_test_extent.cpp. Signed-off-by: LY --- frameworks/intl/src/locale_config.cpp | 5 +++-- frameworks/intl/test/unittest/intl_test_extent.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index 5a81d8c1..36257594 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -1225,8 +1225,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 resionCode = LocaleEncode(regionTag); - HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion: set region %{public}s.", resionCode.c_str()); + std::string regionCode = LocaleEncode(regionTag); + HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion: set region %{public}s.", regionCode.c_str()); return SetSystemLocale(UpdateRegionOfLocale(regionTag)); } @@ -1266,6 +1266,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()); diff --git a/frameworks/intl/test/unittest/intl_test_extent.cpp b/frameworks/intl/test/unittest/intl_test_extent.cpp index a16f8230..68fb1b29 100644 --- a/frameworks/intl/test/unittest/intl_test_extent.cpp +++ b/frameworks/intl/test/unittest/intl_test_extent.cpp @@ -540,7 +540,7 @@ HWTEST_F(IntlTest, IntlFuncTest0062, TestSize.Level1) std::string localeTag = "zh-Hans-CN"; std::string localeCode = LocaleEncode(localeTag); std::string targetCode = "58400008334651000314"; - EXPECT_TRUE(localeCode, targetCode); + EXPECT_EQ(localeCode, targetCode); std::string localeRule = "zh-Hans"; DateTimeRule* dateTimeRule = new DateTimeRule(localeRule); From a53e8ee9f1e441740f74225ba2c86392a494d81a Mon Sep 17 00:00:00 2001 From: zouruntong Date: Fri, 8 Nov 2024 10:40:05 +0800 Subject: [PATCH 36/42] gnFix Signed-off-by: zouruntong Change-Id: I15d1d59ae34200f513117ac947931ebb1cbd2cfe --- interfaces/cj/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/cj/BUILD.gn b/interfaces/cj/BUILD.gn index c928756d..9772c6e4 100644 --- a/interfaces/cj/BUILD.gn +++ b/interfaces/cj/BUILD.gn @@ -38,6 +38,7 @@ ohos_shared_library("cj_i18n_ffi") { ] external_deps = [ "c_utils:utils", + "common_event_service:cesfwk_innerkits", "hilog:libhilog", "icu:shared_icui18n", "icu:shared_icuuc", From 51cad3eb736e5d72ebd2e0944ae0a4b5f84e7057 Mon Sep 17 00:00:00 2001 From: LY Date: Thu, 7 Nov 2024 12:08:44 +0800 Subject: [PATCH 37/42] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LY --- .../src/date_time_filter.cpp | 4 +++ .../src/rules_engine.cpp | 2 +- .../include/border_rule.h | 3 ++ .../src/border_rule.cpp | 10 ++++-- .../intl/include/relative_time_format.h | 2 +- frameworks/intl/src/index_util.cpp | 10 ++++-- frameworks/intl/src/locale_util.cpp | 5 +++ frameworks/intl/src/measure_data.cpp | 6 ++++ frameworks/intl/src/relative_time_format.cpp | 4 +-- frameworks/intl/src/utils.cpp | 5 +++ interfaces/js/kits/src/error_util.cpp | 21 ++++++++--- interfaces/js/kits/src/i18n_system_addon.cpp | 26 +++++++++++--- .../js/kits/src/i18n_timezone_addon.cpp | 6 +++- interfaces/js/kits/src/i18n_unicode_addon.cpp | 36 +++++++++++++++---- interfaces/js/kits/src/intl_addon.cpp | 10 ++++-- 15 files changed, 122 insertions(+), 28 deletions(-) diff --git a/frameworks/intl/entity_recognition/date_time_recognition/src/date_time_filter.cpp b/frameworks/intl/entity_recognition/date_time_recognition/src/date_time_filter.cpp index 990e6ead..166127cb 100644 --- a/frameworks/intl/entity_recognition/date_time_recognition/src/date_time_filter.cpp +++ b/frameworks/intl/entity_recognition/date_time_recognition/src/date_time_filter.cpp @@ -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) { diff --git a/frameworks/intl/entity_recognition/date_time_recognition/src/rules_engine.cpp b/frameworks/intl/entity_recognition/date_time_recognition/src/rules_engine.cpp index cdb83c33..9acd369a 100644 --- a/frameworks/intl/entity_recognition/date_time_recognition/src/rules_engine.cpp +++ b/frameworks/intl/entity_recognition/date_time_recognition/src/rules_engine.cpp @@ -53,7 +53,7 @@ std::vector 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; } diff --git a/frameworks/intl/entity_recognition/phone_number_recognition/include/border_rule.h b/frameworks/intl/entity_recognition/phone_number_recognition/include/border_rule.h index 06abf4d8..d4c042c5 100644 --- a/frameworks/intl/entity_recognition/phone_number_recognition/include/border_rule.h +++ b/frameworks/intl/entity_recognition/phone_number_recognition/include/border_rule.h @@ -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 diff --git a/frameworks/intl/entity_recognition/phone_number_recognition/src/border_rule.cpp b/frameworks/intl/entity_recognition/phone_number_recognition/src/border_rule.cpp index 98be6caf..c107c48e 100644 --- a/frameworks/intl/entity_recognition/phone_number_recognition/src/border_rule.cpp +++ b/frameworks/intl/entity_recognition/phone_number_recognition/src/border_rule.cpp @@ -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); diff --git a/frameworks/intl/include/relative_time_format.h b/frameworks/intl/include/relative_time_format.h index f47a1771..5f3c8d5b 100644 --- a/frameworks/intl/include/relative_time_format.h +++ b/frameworks/intl/include/relative_time_format.h @@ -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 relativeUnits; static std::unordered_map relativeFormatStyle; static std::unordered_map defaultFormatStyle; diff --git a/frameworks/intl/src/index_util.cpp b/frameworks/intl/src/index_util.cpp index e211b191..c85e5a9f 100644 --- a/frameworks/intl/src/index_util.cpp +++ b/frameworks/intl/src/index_util.cpp @@ -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(locale, status); } else { icu::Locale locale(localeTag.c_str()); diff --git a/frameworks/intl/src/locale_util.cpp b/frameworks/intl/src/locale_util.cpp index 1edecb84..eafcb9b5 100644 --- a/frameworks/intl/src/locale_util.cpp +++ b/frameworks/intl/src/locale_util.cpp @@ -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(); } diff --git a/frameworks/intl/src/measure_data.cpp b/frameworks/intl/src/measure_data.cpp index 8f06045c..3955ab5a 100644 --- a/frameworks/intl/src/measure_data.cpp +++ b/frameworks/intl/src/measure_data.cpp @@ -16,6 +16,7 @@ #include #include #include +#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> USAGE_001 { { "area-land-agricult", { "hectare" } }, @@ -308,6 +310,10 @@ const std::unordered_map 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; diff --git a/frameworks/intl/src/relative_time_format.cpp b/frameworks/intl/src/relative_time_format.cpp index c1f30e81..a51471f1 100644 --- a/frameworks/intl/src/relative_time_format.cpp +++ b/frameworks/intl/src/relative_time_format.cpp @@ -223,8 +223,8 @@ void RelativeTimeFormat::GetResolvedOptions(std::map & 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()) { diff --git a/frameworks/intl/src/utils.cpp b/frameworks/intl/src/utils.cpp index a9700a79..0e8e890e 100644 --- a/frameworks/intl/src/utils.cpp +++ b/frameworks/intl/src/utils.cpp @@ -320,6 +320,10 @@ std::set 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 resolvedPath = std::make_unique(PATH_MAX + 1); if (realpath(tzIdConfigPath, resolvedPath.get()) == nullptr) { HILOG_ERROR_I18N("Get realpath failed, errno: %{public}d.", errno); @@ -347,6 +351,7 @@ 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; } } diff --git a/interfaces/js/kits/src/error_util.cpp b/interfaces/js/kits/src/error_util.cpp index bd24b0ce..711019ff 100644 --- a/interfaces/js/kits/src/error_util.cpp +++ b/interfaces/js/kits/src/error_util.cpp @@ -16,6 +16,7 @@ #include #include +#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 diff --git a/interfaces/js/kits/src/i18n_system_addon.cpp b/interfaces/js/kits/src/i18n_system_addon.cpp index 649653e9..437bae62 100644 --- a/interfaces/js/kits/src/i18n_system_addon.cpp +++ b/interfaces/js/kits/src/i18n_system_addon.cpp @@ -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 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 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 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 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 languageBuf(len + 1); status = napi_get_value_string_utf8(env, argv[0], languageBuf.data(), len + 1, &len); if (status != napi_ok) { diff --git a/interfaces/js/kits/src/i18n_timezone_addon.cpp b/interfaces/js/kits/src/i18n_timezone_addon.cpp index 3058f0ef..0944ec29 100644 --- a/interfaces/js/kits/src/i18n_timezone_addon.cpp +++ b/interfaces/js/kits/src/i18n_timezone_addon.cpp @@ -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); } diff --git a/interfaces/js/kits/src/i18n_unicode_addon.cpp b/interfaces/js/kits/src/i18n_unicode_addon.cpp index 378087cc..d6089318 100644 --- a/interfaces/js/kits/src/i18n_unicode_addon.cpp +++ b/interfaces/js/kits/src/i18n_unicode_addon.cpp @@ -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; diff --git a/interfaces/js/kits/src/intl_addon.cpp b/interfaces/js/kits/src/intl_addon.cpp index ccaf1f01..18a94873 100644 --- a/interfaces/js/kits/src/intl_addon.cpp +++ b/interfaces/js/kits/src/intl_addon.cpp @@ -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"); + } } } } From 5a6d09f5178de9b967fbc58ba4d727f924e81dd3 Mon Sep 17 00:00:00 2001 From: LY Date: Fri, 8 Nov 2024 20:08:23 +0800 Subject: [PATCH 38/42] =?UTF-8?q?es-US=E8=AF=AD=E8=A8=80=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LY --- frameworks/intl/src/locale_config.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/intl/src/locale_config.cpp b/frameworks/intl/src/locale_config.cpp index 36257594..93e67e47 100644 --- a/frameworks/intl/src/locale_config.cpp +++ b/frameworks/intl/src/locale_config.cpp @@ -214,6 +214,7 @@ static unordered_map 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" }, From cfa704a9c50a4e1b40a104260fba3f4d4ee2a5a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=9F=8E=E8=8C=B6=E8=AF=AD?= Date: Sat, 9 Nov 2024 08:14:36 +0000 Subject: [PATCH 39/42] update interfaces/cj/intl/src/intl_impl.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 小城茶语 --- interfaces/cj/intl/src/intl_impl.cpp | 1445 ++++++++++++-------------- 1 file changed, 684 insertions(+), 761 deletions(-) diff --git a/interfaces/cj/intl/src/intl_impl.cpp b/interfaces/cj/intl/src/intl_impl.cpp index 45530109..c6d80262 100644 --- a/interfaces/cj/intl/src/intl_impl.cpp +++ b/interfaces/cj/intl/src/intl_impl.cpp @@ -20,816 +20,739 @@ using namespace OHOS::FFI; -namespace OHOS::Global::I18n::Intl +namespace OHOS::Global::I18n::Intl { +std::vector ArrayStringToVectorString(CArrString arrString) { - std::vector ArrayStringToVectorString(CArrString arrString) - { - std::vector res; - for (int i = 0; i < arrString.size; i++) - { - std::string value = arrString.head[i]; - res.push_back(value); - } - return res; + std::vector 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(malloc(sizeof(char) * length)); - if (res == nullptr) - { - return nullptr; - } - return std::char_traits::copy(res, origin.c_str(), length); +char *IMallocCString(const std::string &origin) +{ + if (origin.empty()) { + return nullptr; } + auto length = origin.length() + 1; + char *res = static_cast(malloc(sizeof(char) * length)); + if (res == nullptr) { + return nullptr; + } + return std::char_traits::copy(res, origin.c_str(), length); +} - NumberFormatImpl::NumberFormatImpl(int32_t *errCode) - { - std::vector locale; - std::map map = {}; - numberFmt_ = std::make_unique(locale, map); +NumberFormatImpl::NumberFormatImpl(int32_t *errCode) +{ + std::vector locale; + std::map map = {}; + numberFmt_ = std::make_unique(locale, map); - if (numberFmt_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The numberFormat is nullptr"); - return; + 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 locale_list; + std::string locale_str = locale; + locale_list.push_back(locale_str); + std::map 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(locale_list, map); - NumberFormatImpl::NumberFormatImpl(char *locale, CNumberOptions options, int64_t flag, int32_t *errCode) - { - std::vector locale_list; - std::string locale_str = locale; - locale_list.push_back(locale_str); - std::map 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"); - } + 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 locale_list = ArrayStringToVectorString(locale); + std::map map = {}; + if (flag == 0) { + if (std::strlen(options.locale) != 0) { + map.insert(std::make_pair("locale", options.locale)); } - numberFmt_ = std::make_unique(locale_list, map); + 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 (numberFmt_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The numberFormat is nullptr"); - return; + if (options.minimumFractionDigits != -1 && options.maximumFractionDigits != -1 && + options.minimumFractionDigits > options.maximumFractionDigits) { + HILOG_ERROR_I18N( + "GetNumberOptionValues: Invalid parameter value: minimumFractionDigits > maximumFractionDigits"); } } + numberFmt_ = std::make_unique(locale_list, map); - NumberFormatImpl::NumberFormatImpl(CArrString locale, CNumberOptions options, int64_t flag, int32_t *errCode) - { - std::vector locale_list = ArrayStringToVectorString(locale); - std::map 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(locale_list, map); - - if (numberFmt_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The numberFormat is nullptr"); - return; - } + 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); +char *NumberFormatImpl::Format(double number) +{ + std::string value = numberFmt_->Format(number); + return IMallocCString(value); +} + +CNumberOptions NumberFormatImpl::ResolveOptions() +{ + std::map 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 locale; + std::map options = {}; + relativeTimeFmt_ = std::make_unique(locale, options); + + if (relativeTimeFmt_ == nullptr) { + *errCode = -1; + HILOG_ERROR_I18N("The RelativeTimeFormat is nullptr"); + return; } +} - CNumberOptions NumberFormatImpl::ResolveOptions() - { - std::map 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( + char *locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode) +{ + std::vector locale_list; + std::string locale_str = locale; + locale_list.push_back(locale_str); + std::map 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)); } - - RelativeTimeFormatImpl::RelativeTimeFormatImpl(int32_t *errCode) - { - std::vector locale; - std::map options = {}; - relativeTimeFmt_ = std::make_unique(locale, options); - - if (relativeTimeFmt_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The RelativeTimeFormat is nullptr"); - return; - } + relativeTimeFmt_ = std::make_unique(locale_list, map); + 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 locale_list; - std::string locale_str = locale; - locale_list.push_back(locale_str); - std::map 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(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 locale_list = ArrayStringToVectorString(locale); + + std::map 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(locale_list, map); - RelativeTimeFormatImpl::RelativeTimeFormatImpl( - CArrString locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode) - { - std::vector locale_list = ArrayStringToVectorString(locale); - - std::map 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(locale_list, map); - - if (relativeTimeFmt_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The RelativeTimeFormat is nullptr"); - return; - } + 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; - } +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> timeVectorStr; +CArrArrString RelativeTimeFormatImpl::FormatToParts(double number, char *unit) +{ + std::string unitStr = unit; + std::vector> timeVectorStr; - CArrArrString ret = {.head = nullptr, .size = 0}; - relativeTimeFmt_->FormatToParts(number, unitStr, timeVectorStr); - CArrString *res = static_cast(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 timeVector = timeVectorStr[i]; - CArrString retime = {.head = nullptr, .size = 0}; - char **time = reinterpret_cast(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(timeVectorStr.size()); + CArrArrString ret = {.head = nullptr, .size = 0}; + relativeTimeFmt_->FormatToParts(number, unitStr, timeVectorStr); + CArrString *res = static_cast(malloc(sizeof(char ***) * timeVectorStr.size())); + if (res == nullptr) { + HILOG_ERROR_I18N("The CArrString is nullptr"); return ret; } - CRelativeTimeFormatResolveOptions RelativeTimeFormatImpl::ResolveOptions() - { - std::map 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 locale; - std::map options = {}; - pluralRules_ = std::make_unique(locale, options); - - if (pluralRules_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The PluralRules is nullptr"); - return; + for (size_t i = 0; i < timeVectorStr.size(); i++) { + std::vector timeVector = timeVectorStr[i]; + CArrString retime = {.head = nullptr, .size = 0}; + char **time = reinterpret_cast(malloc(sizeof(char *) * timeVector.size())); + if (time == nullptr) { + HILOG_ERROR_I18N("The char** is nullptr"); + return ret; } - } - - PluralRulesImpl::PluralRulesImpl(char *locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode) - { - std::vector locale_list; - std::string locale_str = locale; - locale_list.push_back(locale_str); - std::map 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(locale_list, map); - - if (pluralRules_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The PluralRules is nullptr"); - return; + 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(timeVectorStr.size()); + return ret; +} - PluralRulesImpl::PluralRulesImpl(CArrString locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode) - { - std::vector locale_list = ArrayStringToVectorString(locale); +CRelativeTimeFormatResolveOptions RelativeTimeFormatImpl::ResolveOptions() +{ + std::map 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; +} - std::map 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(locale_list, map); +PluralRulesImpl::PluralRulesImpl(int32_t *errCode) +{ + std::vector locale; + std::map options = {}; + pluralRules_ = std::make_unique(locale, options); - if (pluralRules_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The PluralRules is nullptr"); - return; - } + 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; +PluralRulesImpl::PluralRulesImpl(char *locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode) +{ + std::vector locale_list; + std::string locale_str = locale; + locale_list.push_back(locale_str); + std::map 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(locale_list, map); - CollatorImpl::CollatorImpl(int32_t *errCode) - { - std::vector locale; - std::map options = {}; - collator_ = std::make_unique(locale, options); + if (pluralRules_ == nullptr) { + *errCode = -1; + HILOG_ERROR_I18N("The PluralRules is nullptr"); + return; + } +} - if (collator_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The Collator is nullptr"); - return; +PluralRulesImpl::PluralRulesImpl(CArrString locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode) +{ + std::vector locale_list = ArrayStringToVectorString(locale); + + std::map 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(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 locale; + std::map options = {}; + collator_ = std::make_unique(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 locale_list; + std::string locale_str = locale; + locale_list.push_back(locale_str); + std::map 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(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 locale_list = ArrayStringToVectorString(locale); + + std::map 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(locale_list, map); + + if (collator_ == nullptr) { + *errCode = -1; + HILOG_ERROR_I18N("The Collator is nullptr"); + return; + } +} + +CCollatorOptions CollatorImpl::ResolveOptions() +{ + std::map 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 locale; + std::map options = {}; + dateFmt_ = std::make_unique(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 locale_list; + std::string locale_str = locale; + locale_list.push_back(locale_str); + std::map 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 map1 = MapInsert(options); + map.insert(map1.begin(), map1.end()); } + dateFmt_ = std::make_unique(locale_list, map); - CollatorImpl::CollatorImpl(char *locale, CCollatorOptions options, int64_t flag, int32_t *errCode) - { - std::vector locale_list; - std::string locale_str = locale; - locale_list.push_back(locale_str); - std::map 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)); + if (dateFmt_ == nullptr) { + *errCode = -1; + HILOG_ERROR_I18N("The DateTimeFormat is nullptr"); + return; + } +} + +std::map DateTimeFormatImpl::MapInsert(CDateTimeOptions options) +{ + std::map 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 locale_list = ArrayStringToVectorString(locale); + + std::map 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 map1 = MapInsert(options); + map.insert(map1.begin(), map1.end()); + } + dateFmt_ = std::make_unique(locale_list, map); + + if (dateFmt_ == nullptr) { + *errCode = -1; + HILOG_ERROR_I18N("The DateTimeFormat is nullptr"); + return; + } +} + +CDateTimeOptions DateTimeFormatImpl::ResolveOptions() +{ + std::map 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 options = {}; + locale_ = std::make_unique(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 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)); - std::string num = std::to_string(options.numeric) == "1" ? "true" : "false"; - map.insert(std::make_pair("numeric", num)); + } + 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)); } - collator_ = std::make_unique(locale_list, map); + } + locale_ = std::make_unique(locale_str, map); + if (locale_ == nullptr) { + *errCode = -1; + HILOG_ERROR_I18N("The Locale is nullptr"); + return; + } +} - if (collator_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The Collator is nullptr"); - return; - } +char *LocaleImpl::ToString() +{ + if (locale_ == nullptr) { + return nullptr; } + std::string value = locale_->ToString(); + char *res = IMallocCString(value); + return res; +} - CollatorImpl::CollatorImpl(CArrString locale, CCollatorOptions options, int64_t flag, int32_t *errCode) - { - std::vector locale_list = ArrayStringToVectorString(locale); +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; +} - std::map 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(locale_list, map); +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; +} - if (collator_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The Collator is nullptr"); - return; - } - } - - CCollatorOptions CollatorImpl::ResolveOptions() - { - std::map 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 locale; - std::map options = {}; - dateFmt_ = std::make_unique(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 locale_list; - std::string locale_str = locale; - locale_list.push_back(locale_str); - std::map 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 map1 = MapInsert(options); - map.insert(map1.begin(), map1.end()); - } - dateFmt_ = std::make_unique(locale_list, map); - - if (dateFmt_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The DateTimeFormat is nullptr"); - return; - } - } - - std::map DateTimeFormatImpl::MapInsert(CDateTimeOptions options) - { - std::map 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 locale_list = ArrayStringToVectorString(locale); - - std::map 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 map1 = MapInsert(options); - map.insert(map1.begin(), map1.end()); - } - dateFmt_ = std::make_unique(locale_list, map); - - if (dateFmt_ == nullptr) - { - *errCode = -1; - HILOG_ERROR_I18N("The DateTimeFormat is nullptr"); - return; - } - } - - CDateTimeOptions DateTimeFormatImpl::ResolveOptions() - { - std::map 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 options = {}; - locale_ = std::make_unique(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 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(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 \ No newline at end of file +} // namespace OHOS::Global::I18n::Intl \ No newline at end of file From 294cb6b79312a7bfeb7351b07cc34052277ad401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=9F=8E=E8=8C=B6=E8=AF=AD?= Date: Sat, 9 Nov 2024 08:23:38 +0000 Subject: [PATCH 40/42] update interfaces/cj/intl/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 小城茶语 --- interfaces/cj/intl/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interfaces/cj/intl/BUILD.gn b/interfaces/cj/intl/BUILD.gn index 6c67f6cc..24d3c6ac 100644 --- a/interfaces/cj/intl/BUILD.gn +++ b/interfaces/cj/intl/BUILD.gn @@ -21,6 +21,8 @@ ohos_shared_library("cj_intl_ffi") { "include", ] + defines = [] + deps = [ "../../../frameworks/intl:intl_util" ] external_deps = [ "c_utils:utils", From 197910a92232d0772faa4f7370ea59627acf786c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=9F=8E=E8=8C=B6=E8=AF=AD?= Date: Sat, 9 Nov 2024 08:39:49 +0000 Subject: [PATCH 41/42] update interfaces/cj/intl/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 小城茶语 --- interfaces/cj/intl/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/cj/intl/BUILD.gn b/interfaces/cj/intl/BUILD.gn index 24d3c6ac..1fb967db 100644 --- a/interfaces/cj/intl/BUILD.gn +++ b/interfaces/cj/intl/BUILD.gn @@ -43,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) { From 950586226cb385a40f60b6a42787009ac2abc3b9 Mon Sep 17 00:00:00 2001 From: Gennji <3296766995@qq.com> Date: Tue, 5 Nov 2024 15:04:48 +0800 Subject: [PATCH 42/42] cj i18n develop Signed-off-by: zouruntong Change-Id: I2b2a95205d1298483388f68a59b9fab050fc6967 --- interfaces/cj/BUILD.gn | 40 +++- .../cj/include/i18n_breakIterator_ffi.h | 35 +++ .../cj/include/i18n_breakIterator_impl.h | 49 ++++ interfaces/cj/include/i18n_calendar_ffi.h | 42 ++++ interfaces/cj/include/i18n_calendar_impl.h | 58 +++++ interfaces/cj/include/i18n_entity_ffi.h | 25 ++ interfaces/cj/include/i18n_entity_impl.h | 43 ++++ interfaces/cj/include/i18n_ffi.h | 32 +++ interfaces/cj/include/i18n_holiday_ffi.h | 30 +++ interfaces/cj/include/i18n_holiday_impl.h | 45 ++++ interfaces/cj/include/i18n_index_util_ffi.h | 30 +++ interfaces/cj/include/i18n_index_util_impl.h | 43 ++++ .../i18n_normalizer_ffi.h} | 9 +- interfaces/cj/include/i18n_normalizer_impl.h | 41 ++++ .../cj/include/i18n_phone_number_format_ffi.h | 30 +++ .../include/i18n_phone_number_format_impl.h | 44 ++++ interfaces/cj/include/i18n_struct.h | 84 +++++++ interfaces/cj/include/i18n_system_ffi.h | 41 ++++ interfaces/cj/include/i18n_timezone_ffi.h | 37 +++ interfaces/cj/include/i18n_timezone_impl.h | 48 ++++ .../cj/include/i18n_transliterator_ffi.h | 29 +++ .../cj/include/i18n_transliterator_impl.h | 41 ++++ interfaces/cj/include/i18n_unicode_ffi.h | 35 +++ interfaces/cj/include/i18n_util_ffi.h | 33 +++ interfaces/cj/src/i18n_breakIterator_ffi.cpp | 93 +++++++ interfaces/cj/src/i18n_breakIterator_impl.cpp | 79 ++++++ interfaces/cj/src/i18n_calendar_ffi.cpp | 226 ++++++++++++++++++ interfaces/cj/src/i18n_calendar_impl.cpp | 113 +++++++++ interfaces/cj/src/i18n_entity_ffi.cpp | 47 ++++ interfaces/cj/src/i18n_entity_impl.cpp | 101 ++++++++ interfaces/cj/{ => src}/i18n_ffi.cpp | 40 ++-- interfaces/cj/src/i18n_holiday_ffi.cpp | 129 ++++++++++ interfaces/cj/src/i18n_holiday_impl.cpp | 55 +++++ interfaces/cj/src/i18n_index_util_ffi.cpp | 69 ++++++ interfaces/cj/src/i18n_index_util_impl.cpp | 46 ++++ interfaces/cj/src/i18n_normalizer_ffi.cpp | 55 +++++ interfaces/cj/src/i18n_normalizer_impl.cpp | 43 ++++ .../cj/src/i18n_phone_number_format_ffi.cpp | 74 ++++++ .../cj/src/i18n_phone_number_format_impl.cpp | 46 ++++ interfaces/cj/src/i18n_system_ffi.cpp | 161 +++++++++++++ interfaces/cj/src/i18n_timezone_ffi.cpp | 126 ++++++++++ interfaces/cj/src/i18n_timezone_impl.cpp | 62 +++++ interfaces/cj/src/i18n_transliterator_ffi.cpp | 79 ++++++ .../cj/src/i18n_transliterator_impl.cpp | 36 +++ interfaces/cj/src/i18n_unicode_ffi.cpp | 72 ++++++ interfaces/cj/src/i18n_util_ffi.cpp | 214 +++++++++++++++++ 46 files changed, 2880 insertions(+), 30 deletions(-) create mode 100644 interfaces/cj/include/i18n_breakIterator_ffi.h create mode 100644 interfaces/cj/include/i18n_breakIterator_impl.h create mode 100644 interfaces/cj/include/i18n_calendar_ffi.h create mode 100644 interfaces/cj/include/i18n_calendar_impl.h create mode 100644 interfaces/cj/include/i18n_entity_ffi.h create mode 100644 interfaces/cj/include/i18n_entity_impl.h create mode 100644 interfaces/cj/include/i18n_ffi.h create mode 100644 interfaces/cj/include/i18n_holiday_ffi.h create mode 100644 interfaces/cj/include/i18n_holiday_impl.h create mode 100644 interfaces/cj/include/i18n_index_util_ffi.h create mode 100644 interfaces/cj/include/i18n_index_util_impl.h rename interfaces/cj/{i18n_ffi.h => include/i18n_normalizer_ffi.h} (76%) create mode 100644 interfaces/cj/include/i18n_normalizer_impl.h create mode 100644 interfaces/cj/include/i18n_phone_number_format_ffi.h create mode 100644 interfaces/cj/include/i18n_phone_number_format_impl.h create mode 100644 interfaces/cj/include/i18n_struct.h create mode 100644 interfaces/cj/include/i18n_system_ffi.h create mode 100644 interfaces/cj/include/i18n_timezone_ffi.h create mode 100644 interfaces/cj/include/i18n_timezone_impl.h create mode 100644 interfaces/cj/include/i18n_transliterator_ffi.h create mode 100644 interfaces/cj/include/i18n_transliterator_impl.h create mode 100644 interfaces/cj/include/i18n_unicode_ffi.h create mode 100644 interfaces/cj/include/i18n_util_ffi.h create mode 100644 interfaces/cj/src/i18n_breakIterator_ffi.cpp create mode 100644 interfaces/cj/src/i18n_breakIterator_impl.cpp create mode 100644 interfaces/cj/src/i18n_calendar_ffi.cpp create mode 100644 interfaces/cj/src/i18n_calendar_impl.cpp create mode 100644 interfaces/cj/src/i18n_entity_ffi.cpp create mode 100644 interfaces/cj/src/i18n_entity_impl.cpp rename interfaces/cj/{ => src}/i18n_ffi.cpp (61%) create mode 100644 interfaces/cj/src/i18n_holiday_ffi.cpp create mode 100644 interfaces/cj/src/i18n_holiday_impl.cpp create mode 100644 interfaces/cj/src/i18n_index_util_ffi.cpp create mode 100644 interfaces/cj/src/i18n_index_util_impl.cpp create mode 100644 interfaces/cj/src/i18n_normalizer_ffi.cpp create mode 100644 interfaces/cj/src/i18n_normalizer_impl.cpp create mode 100644 interfaces/cj/src/i18n_phone_number_format_ffi.cpp create mode 100644 interfaces/cj/src/i18n_phone_number_format_impl.cpp create mode 100644 interfaces/cj/src/i18n_system_ffi.cpp create mode 100644 interfaces/cj/src/i18n_timezone_ffi.cpp create mode 100644 interfaces/cj/src/i18n_timezone_impl.cpp create mode 100644 interfaces/cj/src/i18n_transliterator_ffi.cpp create mode 100644 interfaces/cj/src/i18n_transliterator_impl.cpp create mode 100644 interfaces/cj/src/i18n_unicode_ffi.cpp create mode 100644 interfaces/cj/src/i18n_util_ffi.cpp diff --git a/interfaces/cj/BUILD.gn b/interfaces/cj/BUILD.gn index 9772c6e4..967aeb85 100644 --- a/interfaces/cj/BUILD.gn +++ b/interfaces/cj/BUILD.gn @@ -21,12 +21,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 = [] } @@ -42,11 +39,40 @@ ohos_shared_library("cj_i18n_ffi") { "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" ] @@ -61,6 +87,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" diff --git a/interfaces/cj/include/i18n_breakIterator_ffi.h b/interfaces/cj/include/i18n_breakIterator_ffi.h new file mode 100644 index 00000000..481e61ad --- /dev/null +++ b/interfaces/cj/include/i18n_breakIterator_ffi.h @@ -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 + +#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_ diff --git a/interfaces/cj/include/i18n_breakIterator_impl.h b/interfaces/cj/include/i18n_breakIterator_impl.h new file mode 100644 index 00000000..ed87ae12 --- /dev/null +++ b/interfaces/cj/include/i18n_breakIterator_impl.h @@ -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 +#include +#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 brkiter_ = nullptr; +}; + +} // namespace I18n +} // namespace Global +} // namespace OHOS + +#endif // INTERFACES_CJ_INCLUDE_I18N_BREAKITERATOR_IMPL_H_ diff --git a/interfaces/cj/include/i18n_calendar_ffi.h b/interfaces/cj/include/i18n_calendar_ffi.h new file mode 100644 index 00000000..7aef8f75 --- /dev/null +++ b/interfaces/cj/include/i18n_calendar_ffi.h @@ -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 +#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_ diff --git a/interfaces/cj/include/i18n_calendar_impl.h b/interfaces/cj/include/i18n_calendar_impl.h new file mode 100644 index 00000000..a9cac9f3 --- /dev/null +++ b/interfaces/cj/include/i18n_calendar_impl.h @@ -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 +#include +#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 calendar_; +}; + +} // namespace I18n +} // namespace Global +} // namespace OHOS + +#endif // INTERFACES_CJ_INCLUDE_I18N_CALENDAR_IMPL_H_ diff --git a/interfaces/cj/include/i18n_entity_ffi.h b/interfaces/cj/include/i18n_entity_ffi.h new file mode 100644 index 00000000..082d832d --- /dev/null +++ b/interfaces/cj/include/i18n_entity_ffi.h @@ -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_ diff --git a/interfaces/cj/include/i18n_entity_impl.h b/interfaces/cj/include/i18n_entity_impl.h new file mode 100644 index 00000000..5cd42852 --- /dev/null +++ b/interfaces/cj/include/i18n_entity_impl.h @@ -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 +#include +#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_ = nullptr; +}; + +} // namespace I18n +} // namespace Global +} // namespace OHOS + +#endif // INTERFACES_CJ_INCLUDE_I18N_ENTITY_IMPL_H_ diff --git a/interfaces/cj/include/i18n_ffi.h b/interfaces/cj/include/i18n_ffi.h new file mode 100644 index 00000000..8fc177e6 --- /dev/null +++ b/interfaces/cj/include/i18n_ffi.h @@ -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 +#include +#include "i18n_struct.h" +#include +#include + +#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& vectorString); +} + +#endif // INTERFACES_CJ_INCLUDE_I18N_FFI_H_ diff --git a/interfaces/cj/include/i18n_holiday_ffi.h b/interfaces/cj/include/i18n_holiday_ffi.h new file mode 100644 index 00000000..443f37f7 --- /dev/null +++ b/interfaces/cj/include/i18n_holiday_ffi.h @@ -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 +#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_ diff --git a/interfaces/cj/include/i18n_holiday_impl.h b/interfaces/cj/include/i18n_holiday_impl.h new file mode 100644 index 00000000..da1f2ab2 --- /dev/null +++ b/interfaces/cj/include/i18n_holiday_impl.h @@ -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 +#include +#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 getHolidayInfoItemArray(int32_t year); + std::vector getHolidayInfoItemArray(); + bool isHoliday(); + bool isHoliday(int32_t year, int32_t month, int32_t day); +private: + std::unique_ptr holidayManager_; +}; + +} // namespace I18n +} // namespace Global +} // namespace OHOS + +#endif // INTERFACES_CJ_INCLUDE_I18N_HOLIDAY_IMPL_H_ diff --git a/interfaces/cj/include/i18n_index_util_ffi.h b/interfaces/cj/include/i18n_index_util_ffi.h new file mode 100644 index 00000000..4e96ca1f --- /dev/null +++ b/interfaces/cj/include/i18n_index_util_ffi.h @@ -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 +#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 \ No newline at end of file diff --git a/interfaces/cj/include/i18n_index_util_impl.h b/interfaces/cj/include/i18n_index_util_impl.h new file mode 100644 index 00000000..762d372e --- /dev/null +++ b/interfaces/cj/include/i18n_index_util_impl.h @@ -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 +#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 indexUtil); + ~FfiI18nIndexUtil() = default; + void addLocale(std::string locale); + char* getIndex(std::string text); + CArrStr getIndexList(); +private: + std::unique_ptr 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_ diff --git a/interfaces/cj/i18n_ffi.h b/interfaces/cj/include/i18n_normalizer_ffi.h similarity index 76% rename from interfaces/cj/i18n_ffi.h rename to interfaces/cj/include/i18n_normalizer_ffi.h index 28649e50..c7ea3ced 100644 --- a/interfaces/cj/i18n_ffi.h +++ b/interfaces/cj/include/i18n_normalizer_ffi.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 #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 \ No newline at end of file diff --git a/interfaces/cj/include/i18n_normalizer_impl.h b/interfaces/cj/include/i18n_normalizer_impl.h new file mode 100644 index 00000000..23556779 --- /dev/null +++ b/interfaces/cj/include/i18n_normalizer_impl.h @@ -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 +#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 normalizer); + ~FfiI18nNormalizer() = default; + char* normalize(char* text); +private: + std::unique_ptr 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_ diff --git a/interfaces/cj/include/i18n_phone_number_format_ffi.h b/interfaces/cj/include/i18n_phone_number_format_ffi.h new file mode 100644 index 00000000..91982184 --- /dev/null +++ b/interfaces/cj/include/i18n_phone_number_format_ffi.h @@ -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 +#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 \ No newline at end of file diff --git a/interfaces/cj/include/i18n_phone_number_format_impl.h b/interfaces/cj/include/i18n_phone_number_format_impl.h new file mode 100644 index 00000000..dfde7e17 --- /dev/null +++ b/interfaces/cj/include/i18n_phone_number_format_impl.h @@ -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 +#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 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 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_ diff --git a/interfaces/cj/include/i18n_struct.h b/interfaces/cj/include/i18n_struct.h new file mode 100644 index 00000000..bf6b751d --- /dev/null +++ b/interfaces/cj/include/i18n_struct.h @@ -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 + +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_ diff --git a/interfaces/cj/include/i18n_system_ffi.h b/interfaces/cj/include/i18n_system_ffi.h new file mode 100644 index 00000000..4b798b7c --- /dev/null +++ b/interfaces/cj/include/i18n_system_ffi.h @@ -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 +#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 \ No newline at end of file diff --git a/interfaces/cj/include/i18n_timezone_ffi.h b/interfaces/cj/include/i18n_timezone_ffi.h new file mode 100644 index 00000000..ab86bef2 --- /dev/null +++ b/interfaces/cj/include/i18n_timezone_ffi.h @@ -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 +#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 \ No newline at end of file diff --git a/interfaces/cj/include/i18n_timezone_impl.h b/interfaces/cj/include/i18n_timezone_impl.h new file mode 100644 index 00000000..92784720 --- /dev/null +++ b/interfaces/cj/include/i18n_timezone_impl.h @@ -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 +#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 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 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_ diff --git a/interfaces/cj/include/i18n_transliterator_ffi.h b/interfaces/cj/include/i18n_transliterator_ffi.h new file mode 100644 index 00000000..85275fea --- /dev/null +++ b/interfaces/cj/include/i18n_transliterator_ffi.h @@ -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 +#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 \ No newline at end of file diff --git a/interfaces/cj/include/i18n_transliterator_impl.h b/interfaces/cj/include/i18n_transliterator_impl.h new file mode 100644 index 00000000..2fb87e8c --- /dev/null +++ b/interfaces/cj/include/i18n_transliterator_impl.h @@ -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 +#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 transliterator_); + ~FfiI18nTransliterator() = default; + char* transform(char* text); +private: + std::unique_ptr 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_ diff --git a/interfaces/cj/include/i18n_unicode_ffi.h b/interfaces/cj/include/i18n_unicode_ffi.h new file mode 100644 index 00000000..ed50418e --- /dev/null +++ b/interfaces/cj/include/i18n_unicode_ffi.h @@ -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 +#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 \ No newline at end of file diff --git a/interfaces/cj/include/i18n_util_ffi.h b/interfaces/cj/include/i18n_util_ffi.h new file mode 100644 index 00000000..120fdb56 --- /dev/null +++ b/interfaces/cj/include/i18n_util_ffi.h @@ -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 +#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_ diff --git a/interfaces/cj/src/i18n_breakIterator_ffi.cpp b/interfaces/cj/src/i18n_breakIterator_ffi.cpp new file mode 100644 index 00000000..d71fea4e --- /dev/null +++ b/interfaces/cj/src/i18n_breakIterator_ffi.cpp @@ -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(id); + instance->SetLineBreakText(text); +} + +char* FfiOHOSBreakIteratorGetLineBreakText(int64_t id) +{ + auto instance = FFIData::GetData(id); + return MallocCString(instance->GetLineBreakText()); +} + +int32_t FfiOHOSBreakIteratorCurrent(int64_t id) +{ + auto instance = FFIData::GetData(id); + return instance->current(); +} + +int32_t FfiOHOSBreakIteratorFirst(int64_t id) +{ + auto instance = FFIData::GetData(id); + return instance->first(); +} + +int32_t FfiOHOSBreakIteratorFollowing(int64_t id, int32_t offset) +{ + auto instance = FFIData::GetData(id); + return instance->following(offset); +} + +int32_t FfiOHOSBreakIteratorLast(int64_t id) +{ + auto instance = FFIData::GetData(id); + return instance->last(); +} + +int32_t FfiOHOSBreakIteratorNext(int64_t id, int32_t number) +{ + auto instance = FFIData::GetData(id); + return instance->next(number); +} + +int32_t FfiOHOSBreakIteratorPrevious(int64_t id) +{ + auto instance = FFIData::GetData(id); + return instance->previous(); +} + +bool FfiOHOSBreakIteratorIsBoundary(int64_t id, int32_t offset) +{ + auto instance = FFIData::GetData(id); + return instance->IsBoundary(offset); +} + +int64_t FfiOHOSGetLineInstance(const char* locale) +{ + std::string localeStr(locale); + auto instance = FFIData::Create(localeStr); + if (instance == nullptr) { + HILOG_ERROR_I18N("Create CBreakIterator fail"); + return -1; + } + return instance->GetID(); +} +} +} // namespace I18n +} // namespace Global +} // namespace OHOS diff --git a/interfaces/cj/src/i18n_breakIterator_impl.cpp b/interfaces/cj/src/i18n_breakIterator_impl.cpp new file mode 100644 index 00000000..4a14104f --- /dev/null +++ b/interfaces/cj/src/i18n_breakIterator_impl.cpp @@ -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 +#include "i18n_hilog.h" + +namespace OHOS { +namespace Global { +namespace I18n { +CBreakIterator::CBreakIterator(std::string localeTag) +{ + brkiter_ = std::make_unique(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 \ No newline at end of file diff --git a/interfaces/cj/src/i18n_calendar_ffi.cpp b/interfaces/cj/src/i18n_calendar_ffi.cpp new file mode 100644 index 00000000..12fed244 --- /dev/null +++ b/interfaces/cj/src/i18n_calendar_ffi.cpp @@ -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 +#include +#include +#include +#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 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 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 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(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(id); + instance->SetTime(time); +} + +void FfiOHOSCalendarSetDate(int64_t id, int32_t year, int32_t month, int32_t day) +{ + auto instance = FFIData::GetData(id); + instance->Set(year, month, day); +} + +void FfiOHOSCalendarSetOfDay(int64_t id, int32_t hour, int32_t minute, int32_t second) +{ + auto instance = FFIData::GetData(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(id); + instance->SetTimeZone(std::string(timeZone)); +} + +char* FfiOHOSCalendarGetTimeZone(int64_t id) +{ + auto instance = FFIData::GetData(id); + std::string res = instance->GetTimeZone(); + return MallocCString(res); +} + +void FfiOHOSCalendarSetFirstDayOfWeek(int64_t id, int32_t firstDayOfWeek) +{ + auto instance = FFIData::GetData(id); + instance->SetFirstDayOfWeek(firstDayOfWeek); +} + +int32_t FfiOHOSCalendarGetFirstDayOfWeek(int64_t id) +{ + auto instance = FFIData::GetData(id); + return instance->GetFirstDayOfWeek(); +} + +void FfiOHOSCalendarSetMinimalDaysInFirstWeek(int64_t id, int32_t minimalDays) +{ + auto instance = FFIData::GetData(id); + instance->SetMinimalDaysInFirstWeek(minimalDays); +} + +int32_t FfiOHOSCalendarGetMinimalDaysInFirstWeek(int64_t id) +{ + auto instance = FFIData::GetData(id); + return instance->GetMinimalDaysInFirstWeek(); +} + +int32_t FfiOHOSCalendarGet(int64_t id, char* field) +{ + auto instance = FFIData::GetData(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(id); + std::string res = instance->GetDisplayName(localeStr); + return MallocCString(res); +} + +bool FfiOHOSCalendarIsWeekend(int64_t id, CDate date) +{ + auto instance = FFIData::GetData(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(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(id); + return instance->GetTimeInMillis(); +} + +int32_t FfiOHOSCalendarCompareDays(int64_t id, CDate date) +{ + auto instance = FFIData::GetData(id); + return instance->CompareDays(date.icuUdate); +} +} + +} // namespace I18n +} // namespace Global +} // namespace OHOS diff --git a/interfaces/cj/src/i18n_calendar_impl.cpp b/interfaces/cj/src/i18n_calendar_impl.cpp new file mode 100644 index 00000000..5cfaf372 --- /dev/null +++ b/interfaces/cj/src/i18n_calendar_impl.cpp @@ -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(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 diff --git a/interfaces/cj/src/i18n_entity_ffi.cpp b/interfaces/cj/src/i18n_entity_ffi.cpp new file mode 100644 index 00000000..7be474ad --- /dev/null +++ b/interfaces/cj/src/i18n_entity_ffi.cpp @@ -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(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(id); + return instance->FindEntityInfo(std::string(text)); +} +} +} // namespace I18n +} // namespace Global +} // namespace OHOS diff --git a/interfaces/cj/src/i18n_entity_impl.cpp b/interfaces/cj/src/i18n_entity_impl.cpp new file mode 100644 index 00000000..a0de771d --- /dev/null +++ b/interfaces/cj/src/i18n_entity_impl.cpp @@ -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(localeTag); + if (entityRecognizer_ == nullptr) { + HILOG_ERROR_I18N("Create EntityRecognizer fail"); + } +} + +static int32_t EntityInfoItems2C(const std::vector& items, CEntityInfoItemArr &arr) +{ + int32_t size = static_cast(items.size()); + if (size > 0) { + arr.head = static_cast(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> entityInfo = entityRecognizer_->FindEntityInfo(text); + std::vector types = {"phone_number", "date"}; + std::vector 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 diff --git a/interfaces/cj/i18n_ffi.cpp b/interfaces/cj/src/i18n_ffi.cpp similarity index 61% rename from interfaces/cj/i18n_ffi.cpp rename to interfaces/cj/src/i18n_ffi.cpp index 9366111f..f927c5da 100644 --- a/interfaces/cj/i18n_ffi.cpp +++ b/interfaces/cj/src/i18n_ffi.cpp @@ -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 #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::copy(res, origin.c_str(), length); } -char* FfiOHOSGetAppPreferredLanguage() +CArrStr VectorStringToCArr(const std::vector& vectorString) { - std::string language = PreferredLanguage::GetFirstPreferredLanguage(); - char* res = MallocCString(language); - return res; + CArrStr strArray; + strArray.length = static_cast(vectorString.size()); + strArray.data = static_cast(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; } } -} -} -} \ No newline at end of file +} // namespace I18n +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/cj/src/i18n_holiday_ffi.cpp b/interfaces/cj/src/i18n_holiday_ffi.cpp new file mode 100644 index 00000000..eeb8aede --- /dev/null +++ b/interfaces/cj/src/i18n_holiday_ffi.cpp @@ -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(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(id); + if (date.isNull) { + return instance->isHoliday(); + } else { + return instance->isHoliday(date.year, date.month, date.day); + } +} + +static int32_t HolidayLocalNames2Cj(const std::vector& localNames, HolidayLocalNameArr &arr) +{ + int64_t size = static_cast(localNames.size()); + if (size > 0) { + arr.head = static_cast(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& items, HolidayInfoItemArr &arr) +{ + int64_t size = static_cast(items.size()); + if (size <= 0) { + arr.head = nullptr; + arr.size = 0; + return HOLIDAY_OPT_SUCCESS; + } + arr.head = static_cast(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(id); + std::vector 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 diff --git a/interfaces/cj/src/i18n_holiday_impl.cpp b/interfaces/cj/src/i18n_holiday_impl.cpp new file mode 100644 index 00000000..367a9d40 --- /dev/null +++ b/interfaces/cj/src/i18n_holiday_impl.cpp @@ -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 +#include +#include "i18n_hilog.h" + +namespace OHOS { +namespace Global { +namespace I18n { +CHolidayManager::CHolidayManager(char* icsPath) +{ + holidayManager_ = std::make_unique(icsPath); + if (holidayManager_ == nullptr) { + HILOG_ERROR_I18N("Create HolidayManager fail"); + } +} + +std::vector CHolidayManager::getHolidayInfoItemArray(int32_t year) +{ + std::vector itemList = holidayManager_->GetHolidayInfoItemArray(year); + return itemList; +} + +std::vector CHolidayManager::getHolidayInfoItemArray() +{ + std::vector 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 \ No newline at end of file diff --git a/interfaces/cj/src/i18n_index_util_ffi.cpp b/interfaces/cj/src/i18n_index_util_ffi.cpp new file mode 100644 index 00000000..5f04dd26 --- /dev/null +++ b/interfaces/cj/src/i18n_index_util_ffi.cpp @@ -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 +#include +#include +#include +#include +#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 + +namespace OHOS { +namespace Global { +namespace I18n { +using namespace OHOS::FFI; +extern "C" +{ + int64_t FfiI18nIndexUtilConstructor(char* locale) + { + std::unique_ptr indexUtil_ = std::make_unique(std::string(locale)); + if (indexUtil_ == nullptr) { + HILOG_ERROR_I18N("Create IndexUtil fail"); + return -1; + } + auto ffiIndexUtilInstance = FFIData::Create(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(remoteDataID); + ffiIndexUtilInstance->addLocale(std::string(locale)); + } + + char* FfiI18nIndexUtilGetIndex(int64_t remoteDataID, char* text) + { + auto ffiIndexUtilInstance = FFIData::GetData(remoteDataID); + return ffiIndexUtilInstance->getIndex(std::string(text)); + } + + CArrStr FfiI18nIndexUtilGetIndexList(int64_t remoteDataID) + { + auto ffiIndexUtilInstance = FFIData::GetData(remoteDataID); + return ffiIndexUtilInstance->getIndexList(); + } +} +} // namespace I18n +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/cj/src/i18n_index_util_impl.cpp b/interfaces/cj/src/i18n_index_util_impl.cpp new file mode 100644 index 00000000..04eae396 --- /dev/null +++ b/interfaces/cj/src/i18n_index_util_impl.cpp @@ -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_ = 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 \ No newline at end of file diff --git a/interfaces/cj/src/i18n_normalizer_ffi.cpp b/interfaces/cj/src/i18n_normalizer_ffi.cpp new file mode 100644 index 00000000..bd8cea4d --- /dev/null +++ b/interfaces/cj/src/i18n_normalizer_ffi.cpp @@ -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 +#include +#include +#include +#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 normalizer_ = std::make_unique(normalizerMode, errorCode); + if (errorCode != I18nErrorCode::SUCCESS || !normalizer_) { + HILOG_ERROR_I18N("Create I18nNormalizer fail, error code: %d", errorCode); + return -1; + } + auto ffiNormalizerInstance = FFIData::Create(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(remoteDataID); + return normalizer->normalize(text); + } +} +} // namespace I18n +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/cj/src/i18n_normalizer_impl.cpp b/interfaces/cj/src/i18n_normalizer_impl.cpp new file mode 100644 index 00000000..ac01ccf6 --- /dev/null +++ b/interfaces/cj/src/i18n_normalizer_impl.cpp @@ -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 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 \ No newline at end of file diff --git a/interfaces/cj/src/i18n_phone_number_format_ffi.cpp b/interfaces/cj/src/i18n_phone_number_format_ffi.cpp new file mode 100644 index 00000000..7dff4b02 --- /dev/null +++ b/interfaces/cj/src/i18n_phone_number_format_ffi.cpp @@ -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 +#include +#include +#include +#include +#include +#include "i18n_hilog.h" +#include "i18n_struct.h" +#include "i18n_phone_number_format_ffi.h" +#include "i18n_phone_number_format_impl.h" +#include + +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 options; + if (formatType != nullptr) { + options.insert(std::make_pair("type", std::string(formatType))); + } + std::unique_ptr phoneNumberFormatInstance + = PhoneNumberFormat::CreateInstance(country, options); + if (phoneNumberFormatInstance == nullptr) { + HILOG_ERROR_I18N("Create PhoneNumberFormat fail"); + return -1; + } + auto ffiI18nPhoneNumberFormatInstance + = FFIData::Create(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(remoteDataID); + return format->format(std::string(number)); + } + bool FfiI18nPhoneNumberFormatIsValidNumber(int64_t remoteDataID, char* number) + { + auto format = FFIData::GetData(remoteDataID); + return format->isValidNumber(std::string(number)); + } + char* FfiI18nPhoneNumberFormatGetLocationName(int64_t remoteDataID, char* number, char* locale) + { + auto format = FFIData::GetData(remoteDataID); + return format->getLocationNmae(std::string(number), std::string(locale)); + } +} +} // namespace I18n +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/cj/src/i18n_phone_number_format_impl.cpp b/interfaces/cj/src/i18n_phone_number_format_impl.cpp new file mode 100644 index 00000000..90d5751c --- /dev/null +++ b/interfaces/cj/src/i18n_phone_number_format_impl.cpp @@ -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_ = 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 \ No newline at end of file diff --git a/interfaces/cj/src/i18n_system_ffi.cpp b/interfaces/cj/src/i18n_system_ffi.cpp new file mode 100644 index 00000000..17579e8e --- /dev/null +++ b/interfaces/cj/src/i18n_system_ffi.cpp @@ -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 +#include +#include +#include +#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 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 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 \ No newline at end of file diff --git a/interfaces/cj/src/i18n_timezone_ffi.cpp b/interfaces/cj/src/i18n_timezone_ffi.cpp new file mode 100644 index 00000000..f3a075ce --- /dev/null +++ b/interfaces/cj/src/i18n_timezone_ffi.cpp @@ -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 +#include +#include +#include +#include +#include "i18n_hilog.h" +#include "i18n_ffi.h" +#include "i18n_struct.h" +#include "i18n_timezone_ffi.h" +#include "i18n_timezone_impl.h" +#include + +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 timezoneInstance = I18nTimeZone::CreateInstance(zoneId, isZoneId); + if (timezoneInstance == nullptr) { + HILOG_ERROR_I18N("Create I18nTimeZone fail"); + return -1; + } + auto ffiTimezoneInstance = FFIData::Create(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 cityIDSet = I18nTimeZone::GetAvailableZoneCityIDs(); + std::vector cityIDVec(cityIDSet.begin(), cityIDSet.end()); + return VectorStringToCArr(cityIDVec); + } + + CArrStr FfiI18nTimezoneGetAvailableIDs() + { + I18nErrorCode errorCode = I18nErrorCode::SUCCESS; + std::set timezoneIDSet = I18nTimeZone::GetAvailableIDs(errorCode); + if (errorCode != I18nErrorCode::SUCCESS) { + return { nullptr, 0 }; + } + std::vector timezoneIDVec(timezoneIDSet.begin(), timezoneIDSet.end()); + return VectorStringToCArr(timezoneIDVec); + } + + char* FfiI18nTimezoneGetDisplayName(int64_t remoteDataID, char* locale, bool isDST, int32_t parameterStatus) + { + auto timezone = FFIData::GetData(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(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(since_epoch); + cDate = (double)millis.count(); + } else { + cDate = date; + } + return timezone->getOffset(cDate); + } + + int32_t FfiI18nTimezoneGetRawOffset(int64_t remoteDataID) + { + auto timezone = FFIData::GetData(remoteDataID); + return timezone->getRawOffset(); + } + + char* FfiI18nTimezoneGetID(int64_t remoteDataID) + { + auto timezone = FFIData::GetData(remoteDataID); + return timezone->getID(); + } +} +} // namespace I18n +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/cj/src/i18n_timezone_impl.cpp b/interfaces/cj/src/i18n_timezone_impl.cpp new file mode 100644 index 00000000..16bffdfb --- /dev/null +++ b/interfaces/cj/src/i18n_timezone_impl.cpp @@ -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 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 diff --git a/interfaces/cj/src/i18n_transliterator_ffi.cpp b/interfaces/cj/src/i18n_transliterator_ffi.cpp new file mode 100644 index 00000000..23801a76 --- /dev/null +++ b/interfaces/cj/src/i18n_transliterator_ffi.cpp @@ -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 +#include +#include "i18n_hilog.h" +#include "i18n_ffi.h" +#include "i18n_transliterator_ffi.h" +#include "i18n_transliterator_impl.h" +#include + +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(std::unique_ptr(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 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(remoteDataId); + return transLiterator_->transform(text); + } +} +} // namespace I18n +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/cj/src/i18n_transliterator_impl.cpp b/interfaces/cj/src/i18n_transliterator_impl.cpp new file mode 100644 index 00000000..32ed2a3d --- /dev/null +++ b/interfaces/cj/src/i18n_transliterator_impl.cpp @@ -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 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 diff --git a/interfaces/cj/src/i18n_unicode_ffi.cpp b/interfaces/cj/src/i18n_unicode_ffi.cpp new file mode 100644 index 00000000..67723323 --- /dev/null +++ b/interfaces/cj/src/i18n_unicode_ffi.cpp @@ -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 +#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 \ No newline at end of file diff --git a/interfaces/cj/src/i18n_util_ffi.cpp b/interfaces/cj/src/i18n_util_ffi.cpp new file mode 100644 index 00000000..d393c59c --- /dev/null +++ b/interfaces/cj/src/i18n_util_ffi.cpp @@ -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 +#include +#include +#include +#include + +#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 convert2CppStringArray(const CArrStr& carrStr) +{ + std::vector 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 &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 localeTagList, + std::vector &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 localeTags; + std::map 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 numberFmt = nullptr; + numberFmt = std::make_unique(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 localeArr = convert2CppStringArray(localeList); + std::string localeStr(locale); + LocaleInfo *requestLocale = GetLocaleInfo(localeStr, errCode); + if (requestLocale == nullptr) { + return nullptr; + } + std::vector 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(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