Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Global I18n Standard
提交
555f250d
G
Global I18n Standard
项目概览
OpenHarmony
/
Global I18n Standard
大约 1 年 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Global I18n Standard
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
555f250d
编写于
3月 12, 2022
作者:
S
sunyaozu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update from master branch
Signed-off-by:
N
sunyaozu
<
sunyaozu@huawei.com
>
上级
4446f02c
变更
43
展开全部
隐藏空白更改
内联
并排
Showing
43 changed file
with
829 addition
and
382 deletion
+829
-382
frameworks/intl/BUILD.gn
frameworks/intl/BUILD.gn
+2
-1
frameworks/intl/etc/forbidden_languages.xml
frameworks/intl/etc/forbidden_languages.xml
+1
-1
frameworks/intl/etc/forbidden_regions.xml
frameworks/intl/etc/forbidden_regions.xml
+1
-1
frameworks/intl/etc/supported_regions.xml
frameworks/intl/etc/supported_regions.xml
+1
-2
frameworks/intl/etc/white_languages.xml
frameworks/intl/etc/white_languages.xml
+1
-1
frameworks/intl/include/character.h
frameworks/intl/include/character.h
+4
-4
frameworks/intl/include/collator.h
frameworks/intl/include/collator.h
+15
-9
frameworks/intl/include/date_time_format.h
frameworks/intl/include/date_time_format.h
+3
-1
frameworks/intl/include/i18n_timezone.h
frameworks/intl/include/i18n_timezone.h
+42
-0
frameworks/intl/include/index_util.h
frameworks/intl/include/index_util.h
+4
-4
frameworks/intl/include/locale_config.h
frameworks/intl/include/locale_config.h
+4
-4
frameworks/intl/include/phone_number_format.h
frameworks/intl/include/phone_number_format.h
+5
-6
frameworks/intl/include/plural_rules.h
frameworks/intl/include/plural_rules.h
+7
-8
frameworks/intl/include/relative_time_format.h
frameworks/intl/include/relative_time_format.h
+1
-1
frameworks/intl/src/character.cpp
frameworks/intl/src/character.cpp
+4
-4
frameworks/intl/src/collator.cpp
frameworks/intl/src/collator.cpp
+18
-21
frameworks/intl/src/date_time_format.cpp
frameworks/intl/src/date_time_format.cpp
+49
-42
frameworks/intl/src/i18n_calendar.cpp
frameworks/intl/src/i18n_calendar.cpp
+7
-6
frameworks/intl/src/i18n_timezone.cpp
frameworks/intl/src/i18n_timezone.cpp
+98
-0
frameworks/intl/src/index_util.cpp
frameworks/intl/src/index_util.cpp
+4
-4
frameworks/intl/src/locale_config.cpp
frameworks/intl/src/locale_config.cpp
+25
-23
frameworks/intl/src/locale_info.cpp
frameworks/intl/src/locale_info.cpp
+6
-4
frameworks/intl/src/locale_util.cpp
frameworks/intl/src/locale_util.cpp
+4
-4
frameworks/intl/src/measure_data.cpp
frameworks/intl/src/measure_data.cpp
+15
-15
frameworks/intl/src/number_format.cpp
frameworks/intl/src/number_format.cpp
+7
-6
frameworks/intl/src/phone_number_format.cpp
frameworks/intl/src/phone_number_format.cpp
+4
-4
frameworks/intl/src/plural_rules.cpp
frameworks/intl/src/plural_rules.cpp
+8
-8
frameworks/intl/src/preferred_language.cpp
frameworks/intl/src/preferred_language.cpp
+9
-26
frameworks/intl/src/relative_time_format.cpp
frameworks/intl/src/relative_time_format.cpp
+8
-7
frameworks/intl/test/BUILD.gn
frameworks/intl/test/BUILD.gn
+1
-1
frameworks/intl/test/unittest/intl_test.cpp
frameworks/intl/test/unittest/intl_test.cpp
+15
-15
frameworks/intl/test/unittest/locale_config_test.cpp
frameworks/intl/test/unittest/locale_config_test.cpp
+5
-5
frameworks/zone/BUILD.gn
frameworks/zone/BUILD.gn
+1
-1
frameworks/zone/src/zone_util.cpp
frameworks/zone/src/zone_util.cpp
+9
-9
frameworks/zone/test/unittest/zone_util_test.cpp
frameworks/zone/test/unittest/zone_util_test.cpp
+1
-1
interfaces/js/kits/BUILD.gn
interfaces/js/kits/BUILD.gn
+1
-1
interfaces/js/kits/include/i18n_addon.h
interfaces/js/kits/include/i18n_addon.h
+16
-5
interfaces/js/kits/include/intl_addon.h
interfaces/js/kits/include/intl_addon.h
+6
-6
interfaces/js/kits/src/i18n_addon.cpp
interfaces/js/kits/src/i18n_addon.cpp
+359
-69
interfaces/js/kits/src/intl_addon.cpp
interfaces/js/kits/src/intl_addon.cpp
+46
-40
interfaces/native/innerkits/i18n/include/locale_util.h
interfaces/native/innerkits/i18n/include/locale_util.h
+4
-4
interfaces/native/innerkits/preferred_language/include/preferred_language.h
...innerkits/preferred_language/include/preferred_language.h
+4
-4
interfaces/native/innerkits/zone/include/zone_util.h
interfaces/native/innerkits/zone/include/zone_util.h
+4
-4
未找到文件。
frameworks/intl/BUILD.gn
浏览文件 @
555f250d
# Copyright (c) 2021 Huawei Device Co., Ltd.
# 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
...
...
@@ -74,6 +74,7 @@ ohos_shared_library("intl_util") {
"src/date_time_format.cpp",
"src/i18n_break_iterator.cpp",
"src/i18n_calendar.cpp",
"src/i18n_timezone.cpp",
"src/index_util.cpp",
"src/locale_config.cpp",
"src/locale_info.cpp",
...
...
frameworks/intl/etc/forbidden_languages.xml
浏览文件 @
555f250d
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
<!-- 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
...
...
frameworks/intl/etc/forbidden_regions.xml
浏览文件 @
555f250d
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
<!-- 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
...
...
frameworks/intl/etc/supported_regions.xml
浏览文件 @
555f250d
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
<!-- 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
...
...
@@ -251,7 +251,6 @@
<item>
YE
</item>
<item>
YT
</item>
<item>
ZA
</item>
<item>
ZG
</item>
<item>
ZM
</item>
<item>
ZW
</item>
</supported_regions>
frameworks/intl/etc/white_languages.xml
浏览文件 @
555f250d
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
<!-- 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
...
...
frameworks/intl/include/character.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -30,7 +30,7 @@ bool IsLetter(const std::string &character);
bool
IsLowerCase
(
const
std
::
string
&
character
);
bool
IsUpperCase
(
const
std
::
string
&
character
);
std
::
string
GetType
(
const
std
::
string
&
character
);
}
}
}
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
#endif
frameworks/intl/include/collator.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -28,11 +28,18 @@
namespace
OHOS
{
namespace
Global
{
namespace
I18n
{
typedef
enum
CompareResult
{
INVALID
=
-
2
,
SMALLER
,
EQUAL
,
GREATER
,
}
CompareResult
;
class
Collator
{
public:
Collator
(
std
::
vector
<
std
::
string
>
&
localeTags
,
std
::
map
<
std
::
string
,
std
::
string
>
&
options
);
~
Collator
();
int32_
t
Compare
(
const
std
::
string
&
first
,
const
std
::
string
&
second
);
CompareResul
t
Compare
(
const
std
::
string
&
first
,
const
std
::
string
&
second
);
void
ResolvedOptions
(
std
::
map
<
std
::
string
,
std
::
string
>
&
options
);
private:
...
...
@@ -45,9 +52,9 @@ private:
std
::
string
caseFirst
;
std
::
string
collation
;
std
::
unique_ptr
<
LocaleInfo
>
localeInfo
;
std
::
unique_ptr
<
LocaleInfo
>
localeInfo
=
nullptr
;
icu
::
Locale
locale
;
icu
::
Collator
*
collatorPtr
;
icu
::
Collator
*
collatorPtr
=
nullptr
;
std
::
set
<
std
::
string
>
GetValidLocales
();
std
::
string
ParseOption
(
std
::
map
<
std
::
string
,
std
::
string
>
&
options
,
const
std
::
string
&
key
);
...
...
@@ -61,8 +68,7 @@ private:
void
SetIgnorePunctuation
(
UErrorCode
&
status
);
bool
InitCollator
();
};
}
}
}
#endif // GLOBAL_I18N_STANDARD_COLLATOR_H
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
#endif
frameworks/intl/include/date_time_format.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -116,6 +116,8 @@ private:
static
bool
icuInitialized
;
static
bool
Init
();
static
std
::
map
<
std
::
string
,
icu
::
DateFormat
::
EStyle
>
dateTimeStyle
;
void
InitWithLocale
(
const
std
::
string
&
curLocale
,
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
);
void
InitWithDefaultLocale
(
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
);
void
ParseConfigsPartOne
(
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
);
void
ParseConfigsPartTwo
(
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
);
void
AddOptions
(
std
::
string
option
,
char16_t
optionChar
);
...
...
frameworks/intl/include/i18n_timezone.h
0 → 100644
浏览文件 @
555f250d
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except", "in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_GLOBAL_I18N_TIMEZONE_H
#define OHOS_GLOBAL_I18N_TIMEZONE_H
#include <string>
#include "unicode/timezone.h"
namespace
OHOS
{
namespace
Global
{
namespace
I18n
{
class
I18nTimeZone
{
public:
I18nTimeZone
(
std
::
string
zoneID
);
~
I18nTimeZone
();
int32_t
GetOffset
(
double
date
);
int32_t
GetRawOffset
();
std
::
string
GetID
();
std
::
string
GetDisplayName
();
std
::
string
GetDisplayName
(
bool
isDST
);
std
::
string
GetDisplayName
(
std
::
string
localeStr
);
std
::
string
GetDisplayName
(
std
::
string
localeStr
,
bool
isDST
);
private:
icu
::
TimeZone
*
timezone
;
};
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
#endif
\ No newline at end of file
frameworks/intl/include/index_util.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -33,7 +33,7 @@ public:
private:
std
::
unique_ptr
<
icu
::
AlphabeticIndex
>
index
;
};
}
}
}
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
#endif
frameworks/intl/include/locale_config.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -97,7 +97,7 @@ private:
static
bool
listsInitialized
;
static
bool
InitializeLists
();
};
}
// I18n
}
// Global
}
// OHOS
}
//
namespace
I18n
}
//
namespace
Global
}
//
namespace
OHOS
#endif
frameworks/intl/include/phone_number_format.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -37,8 +37,7 @@ private:
std
::
string
country
;
PhoneNumberUtil
::
PhoneNumberFormat
phoneNumberFormat
;
};
}
}
}
#endif // OHOS_GLOBAL_I18N_PHONE_NUMBER_FORMAT_H
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
#endif
frameworks/intl/include/plural_rules.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -37,9 +37,9 @@ public:
private:
std
::
string
localeStr
;
std
::
unique_ptr
<
LocaleInfo
>
localeInfo
;
std
::
unique_ptr
<
LocaleInfo
>
localeInfo
=
nullptr
;
icu
::
Locale
locale
;
icu
::
PluralRules
*
pluralRules
;
icu
::
PluralRules
*
pluralRules
=
nullptr
;
icu
::
number
::
LocalizedNumberFormatter
numberFormatter
;
std
::
string
localeMatcher
;
...
...
@@ -56,8 +56,7 @@ private:
void
InitPluralRules
(
std
::
vector
<
std
::
string
>
&
localeTags
,
std
::
map
<
std
::
string
,
std
::
string
>
&
options
);
void
InitNumberFormatter
();
};
}
}
}
#endif // GLOBAL_I18N_STANDARD_PLURAL_RULES_H
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
#endif
frameworks/intl/include/relative_time_format.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
frameworks/intl/src/character.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -129,6 +129,6 @@ std::string GetType(const std::string &character)
int8_t
category
=
u_charType
(
char32
);
return
categoryMap
[
UCharCategory
(
category
)];
}
}
}
}
\ No newline at end of file
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
\ No newline at end of file
frameworks/intl/src/collator.cpp
浏览文件 @
555f250d
//
// Created by s00619675 on 2021/10/25.
//
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -70,7 +66,7 @@ Collator::Collator(std::vector<std::string> &localeTags, std::map<std::string, s
ParseAllOptions
(
options
);
UErrorCode
status
=
UErrorCode
::
U_ZERO_ERROR
;
if
(
localeTags
.
size
()
==
0
)
{
if
(
!
localeTags
.
size
()
)
{
localeTags
.
push_back
(
LocaleConfig
::
GetSystemLocale
());
}
for
(
size_t
i
=
0
;
i
<
localeTags
.
size
();
i
++
)
{
...
...
@@ -98,7 +94,7 @@ bool Collator::IsValidCollation(std::string &collation, UErrorCode &status)
int
length
;
const
char
*
validCollations
=
enumeration
->
next
(
&
length
,
status
);
while
(
validCollations
!=
nullptr
)
{
if
(
strcmp
(
validCollations
,
currentCollation
)
==
0
)
{
if
(
!
strcmp
(
validCollations
,
currentCollation
)
)
{
return
true
;
}
validCollations
=
enumeration
->
next
(
&
length
,
status
);
...
...
@@ -142,7 +138,7 @@ void Collator::SetUsage(UErrorCode &status)
void
Collator
::
SetNumeric
(
UErrorCode
&
status
)
{
if
(
collatorPtr
==
nullp
tr
)
{
if
(
!
collatorP
tr
)
{
return
;
}
if
(
numeric
==
""
)
{
...
...
@@ -162,7 +158,7 @@ void Collator::SetNumeric(UErrorCode &status)
void
Collator
::
SetCaseFirst
(
UErrorCode
&
status
)
{
if
(
collatorPtr
==
nullp
tr
)
{
if
(
!
collatorP
tr
)
{
return
;
}
if
(
caseFirst
==
""
)
{
...
...
@@ -185,7 +181,7 @@ void Collator::SetCaseFirst(UErrorCode &status)
void
Collator
::
SetSensitivity
(
UErrorCode
&
status
)
{
if
(
collatorPtr
==
nullp
tr
)
{
if
(
!
collatorP
tr
)
{
return
;
}
if
(
sensitivity
==
"base"
)
{
...
...
@@ -203,7 +199,7 @@ void Collator::SetSensitivity(UErrorCode &status)
void
Collator
::
SetIgnorePunctuation
(
UErrorCode
&
status
)
{
if
(
collatorPtr
==
nullp
tr
)
{
if
(
!
collatorP
tr
)
{
return
;
}
if
(
ignorePunctuation
==
"true"
)
{
...
...
@@ -223,7 +219,7 @@ bool Collator::InitCollator()
SetSensitivity
(
status
);
SetIgnorePunctuation
(
status
);
if
(
collatorPtr
==
nullp
tr
)
{
if
(
!
collatorP
tr
)
{
return
false
;
}
return
true
;
...
...
@@ -237,24 +233,25 @@ Collator::~Collator()
}
}
int32_
t
Collator
::
Compare
(
const
std
::
string
&
first
,
const
std
::
string
&
second
)
CompareResul
t
Collator
::
Compare
(
const
std
::
string
&
first
,
const
std
::
string
&
second
)
{
if
(
collatorPtr
==
nullp
tr
)
{
return
-
2
;
if
(
!
collatorP
tr
)
{
return
CompareResult
::
INVALID
;
}
icu
::
Collator
::
EComparisonResult
result
=
collatorPtr
->
compare
(
icu
::
UnicodeString
(
first
.
data
(),
first
.
length
()),
icu
::
UnicodeString
(
second
.
data
(),
second
.
length
()));
if
(
result
==
icu
::
Collator
::
EComparisonResult
::
LESS
)
{
return
-
1
;
return
CompareResult
::
SMALLER
;
}
else
if
(
result
==
icu
::
Collator
::
EComparisonResult
::
EQUAL
)
{
return
0
;
return
CompareResult
::
EQUAL
;
}
else
{
return
1
;
return
CompareResult
::
GREATER
;
}
}
void
Collator
::
ResolvedOptions
(
std
::
map
<
std
::
string
,
std
::
string
>
&
options
)
{
options
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
"localeMatcher"
,
localeMatcher
));
options
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
"locale"
,
localeStr
));
options
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
"usage"
,
usage
));
options
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
"sensitivity"
,
sensitivity
));
...
...
@@ -263,6 +260,6 @@ void Collator::ResolvedOptions(std::map<std::string, std::string> &options)
options
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
"caseFirst"
,
caseFirst
));
options
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
"collation"
,
collation
));
}
}
}
}
\ No newline at end of file
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
frameworks/intl/src/date_time_format.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -35,27 +35,16 @@ std::map<std::string, DateFormat::EStyle> DateTimeFormat::dateTimeStyle = {
DateTimeFormat
::
DateTimeFormat
(
const
std
::
vector
<
std
::
string
>
&
localeTags
,
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
auto
builder
=
std
::
make_unique
<
LocaleBuilder
>
();
std
::
unique_ptr
<
icu
::
LocaleBuilder
>
builder
=
nullptr
;
builder
=
std
::
make_unique
<
LocaleBuilder
>
();
ParseConfigsPartOne
(
configs
);
ParseConfigsPartTwo
(
configs
);
for
(
size_t
i
=
0
;
i
<
localeTags
.
size
();
i
++
)
{
std
::
string
curLocale
=
localeTags
[
i
];
locale
=
Locale
::
forLanguageTag
(
StringPiece
(
curLocale
),
status
);
if
(
LocaleInfo
::
allValidLocales
.
count
(
locale
.
getLanguage
())
>
0
)
{
localeInfo
=
new
LocaleInfo
(
curLocale
,
configs
);
locale
=
localeInfo
->
GetLocale
();
localeTag
=
localeInfo
->
GetBaseName
();
if
(
hourCycle
.
empty
())
{
hourCycle
=
localeInfo
->
GetHourCycle
();
}
ComputeHourCycleChars
();
ComputeSkeleton
();
if
(
configs
.
size
()
==
0
)
{
InitDateFormatWithoutConfigs
(
status
);
}
else
{
InitDateFormat
(
status
);
}
if
(
dateFormat
==
nullptr
)
{
InitWithLocale
(
curLocale
,
configs
);
if
(
!
dateFormat
)
{
delete
localeInfo
;
localeInfo
=
nullptr
;
continue
;
...
...
@@ -63,23 +52,9 @@ DateTimeFormat::DateTimeFormat(const std::vector<std::string> &localeTags, std::
break
;
}
}
if
(
localeInfo
==
nullptr
||
dateFormat
==
nullptr
)
{
if
(
localeInfo
!=
nullptr
)
{
delete
localeInfo
;
}
localeInfo
=
new
LocaleInfo
(
LocaleConfig
::
GetSystemLocale
(),
configs
);
locale
=
localeInfo
->
GetLocale
();
localeTag
=
locale
.
getBaseName
();
std
::
replace
(
localeTag
.
begin
(),
localeTag
.
end
(),
'_'
,
'-'
);
if
(
dateFormat
!=
nullptr
)
{
delete
dateFormat
;
}
dateFormat
=
DateFormat
::
createInstance
();
}
if
(
dateIntvFormat
==
nullptr
)
{
dateIntvFormat
=
DateIntervalFormat
::
createInstance
(
pattern
,
status
);
if
(
!
localeInfo
||
!
dateFormat
)
{
InitWithDefaultLocale
(
configs
);
}
calendar
=
Calendar
::
createInstance
(
locale
,
status
);
}
DateTimeFormat
::~
DateTimeFormat
()
...
...
@@ -102,6 +77,44 @@ DateTimeFormat::~DateTimeFormat()
}
}
void
DateTimeFormat
::
InitWithLocale
(
const
std
::
string
&
curLocale
,
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
localeInfo
=
new
LocaleInfo
(
curLocale
,
configs
);
locale
=
localeInfo
->
GetLocale
();
localeTag
=
localeInfo
->
GetBaseName
();
if
(
hourCycle
.
empty
())
{
hourCycle
=
localeInfo
->
GetHourCycle
();
}
if
(
hour12
.
empty
()
&&
hourCycle
.
empty
())
{
bool
is24HourClock
=
LocaleConfig
::
Is24HourClock
();
if
(
is24HourClock
)
{
hour12
=
"false"
;
}
}
ComputeHourCycleChars
();
ComputeSkeleton
();
if
(
!
configs
.
size
())
{
InitDateFormatWithoutConfigs
(
status
);
}
else
{
InitDateFormat
(
status
);
}
calendar
=
Calendar
::
createInstance
(
locale
,
status
);
}
void
DateTimeFormat
::
InitWithDefaultLocale
(
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
)
{
if
(
localeInfo
!=
nullptr
)
{
delete
localeInfo
;
localeInfo
=
nullptr
;
}
if
(
dateFormat
!=
nullptr
)
{
delete
dateFormat
;
dateFormat
=
nullptr
;
}
InitWithLocale
(
LocaleConfig
::
GetSystemLocale
(),
configs
);
}
void
DateTimeFormat
::
InitDateFormatWithoutConfigs
(
UErrorCode
&
status
)
{
dateFormat
=
DateFormat
::
createDateInstance
(
DateFormat
::
SHORT
,
locale
);
...
...
@@ -182,14 +195,14 @@ void DateTimeFormat::removeAmPmChar()
if
((
i
+
1
)
<
patternString
.
length
()
&&
patternString
[
i
+
1
]
==
't'
)
{
continue
;
}
if
(
i
==
0
)
{
if
(
!
i
)
{
amPmCharStartIdx
=
i
;
}
else
{
amPmCharStartIdx
=
i
-
1
;
while
(
amPmCharStartIdx
>
0
&&
patternString
[
amPmCharStartIdx
]
==
' '
)
{
amPmCharStartIdx
-=
1
;
}
if
(
amPmCharStartIdx
!=
0
||
patternString
[
amPmCharStartIdx
]
!=
' '
)
{
if
(
amPmCharStartIdx
||
patternString
[
amPmCharStartIdx
]
!=
' '
)
{
amPmCharStartIdx
+=
1
;
}
}
...
...
@@ -200,8 +213,8 @@ void DateTimeFormat::removeAmPmChar()
break
;
}
size_t
length
=
amPmCharEndIdx
-
amPmCharStartIdx
;
if
(
length
!=
0
)
{
if
(
amPmCharStartIdx
==
0
||
amPmCharEndIdx
==
patternString
.
length
())
{
if
(
length
)
{
if
(
!
amPmCharStartIdx
||
amPmCharEndIdx
==
patternString
.
length
())
{
patternString
=
patternString
.
replace
(
amPmCharStartIdx
,
length
,
""
);
}
else
{
patternString
=
patternString
.
replace
(
amPmCharStartIdx
,
length
,
" "
);
...
...
@@ -283,12 +296,6 @@ void DateTimeFormat::ParseConfigsPartTwo(std::map<std::string, std::string> &con
if
(
configs
.
count
(
"hour12"
)
>
0
)
{
hour12
=
configs
[
"hour12"
];
}
if
(
hour12
.
empty
()
&&
hourCycle
.
empty
())
{
bool
is24HourClock
=
LocaleConfig
::
Is24HourClock
();
if
(
is24HourClock
)
{
hour12
=
"false"
;
}
}
if
(
configs
.
count
(
"weekday"
)
>
0
)
{
weekday
=
configs
[
"weekday"
];
}
...
...
frameworks/intl/src/i18n_calendar.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -24,6 +24,7 @@
#include "islamcal.h"
#include "japancal.h"
#include "persncal.h"
#include "securec.h"
#include "ureslocs.h"
#include "ulocimp.h"
#include "uresimp.h"
...
...
@@ -142,7 +143,7 @@ void I18nCalendar::SetTimeZone(std::string id)
{
icu
::
UnicodeString
zone
=
icu
::
UnicodeString
::
fromUTF8
(
id
);
icu
::
TimeZone
*
timezone
=
icu
::
TimeZone
::
createTimeZone
(
zone
);
if
(
timezone
==
nullptr
)
{
if
(
!
timezone
)
{
return
;
}
if
(
calendar_
!=
nullptr
)
{
...
...
@@ -154,7 +155,7 @@ void I18nCalendar::SetTimeZone(std::string id)
std
::
string
I18nCalendar
::
GetTimeZone
(
void
)
{
std
::
string
ret
;
if
(
calendar_
!=
nullptr
)
{
if
(
calendar_
)
{
icu
::
UnicodeString
unistr
;
calendar_
->
getTimeZone
().
getDisplayName
(
unistr
);
unistr
.
toUTF8String
<
std
::
string
>
(
ret
);
...
...
@@ -243,11 +244,11 @@ std::string I18nCalendar::GetDisplayName(std::string &displayLocale)
icu
::
UnicodeString
unistr
;
int32_t
destCapacity
=
50
;
UChar
*
buffer
=
unistr
.
getBuffer
(
destCapacity
);
if
(
buffer
==
0
||
calendar_
==
nullptr
)
{
if
(
buffer
==
0
||
!
calendar_
)
{
return
""
;
}
const
char
*
type
=
calendar_
->
getType
();
if
(
type
==
nullptr
)
{
if
(
!
type
)
{
return
""
;
}
int32_t
length
;
...
...
@@ -258,7 +259,7 @@ std::string I18nCalendar::GetDisplayName(std::string &displayLocale)
if
(
status
==
U_ZERO_ERROR
)
{
len
=
(
length
<
destCapacity
)
?
length
:
destCapacity
;
if
((
len
>
0
)
&&
(
str
!=
nullptr
))
{
u_memcpy
(
buffer
,
str
,
len
);
memcpy_s
((
void
*
)
buffer
,
(
size_t
)
destCapacity
,
(
void
*
)
str
,
(
size_t
)
len
);
}
}
else
{
return
""
;
...
...
frameworks/intl/src/i18n_timezone.cpp
0 → 100644
浏览文件 @
555f250d
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "locale_config.h"
#include "unicode/locid.h"
#include "unicode/unistr.h"
#include "i18n_timezone.h"
namespace
OHOS
{
namespace
Global
{
namespace
I18n
{
I18nTimeZone
::
I18nTimeZone
(
std
::
string
zoneID
)
{
if
(
zoneID
.
empty
())
{
timezone
=
icu
::
TimeZone
::
createDefault
();
}
else
{
icu
::
UnicodeString
unicodeZoneID
(
zoneID
.
data
(),
zoneID
.
length
());
timezone
=
icu
::
TimeZone
::
createTimeZone
(
unicodeZoneID
);
}
}
I18nTimeZone
::~
I18nTimeZone
()
{
if
(
timezone
!=
nullptr
)
{
delete
timezone
;
timezone
=
nullptr
;
}
}
int32_t
I18nTimeZone
::
GetOffset
(
double
date
)
{
int32_t
rawOffset
=
0
;
int32_t
dstOffset
=
0
;
bool
local
=
false
;
UErrorCode
status
=
U_ZERO_ERROR
;
timezone
->
getOffset
(
date
,
(
UBool
)
local
,
rawOffset
,
dstOffset
,
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
return
0
;
}
return
rawOffset
+
dstOffset
;
}
int32_t
I18nTimeZone
::
GetRawOffset
()
{
return
timezone
->
getRawOffset
();
}
std
::
string
I18nTimeZone
::
GetID
()
{
icu
::
UnicodeString
zoneID
;
timezone
->
getID
(
zoneID
);
std
::
string
result
;
zoneID
.
toUTF8String
(
result
);
return
result
;
}
std
::
string
I18nTimeZone
::
GetDisplayName
()
{
std
::
string
localeStr
=
LocaleConfig
::
GetSystemLocale
();
return
GetDisplayName
(
localeStr
,
false
);
}
std
::
string
I18nTimeZone
::
GetDisplayName
(
bool
isDST
)
{
std
::
string
localeStr
=
LocaleConfig
::
GetSystemLocale
();
return
GetDisplayName
(
localeStr
,
isDST
);
}
std
::
string
I18nTimeZone
::
GetDisplayName
(
std
::
string
localeStr
)
{
return
GetDisplayName
(
localeStr
,
false
);
}
std
::
string
I18nTimeZone
::
GetDisplayName
(
std
::
string
localeStr
,
bool
isDST
)
{
icu
::
TimeZone
::
EDisplayType
style
=
icu
::
TimeZone
::
EDisplayType
::
LONG_GENERIC
;
icu
::
Locale
locale
(
localeStr
.
data
());
icu
::
UnicodeString
name
;
timezone
->
getDisplayName
((
UBool
)
isDST
,
style
,
locale
,
name
);
std
::
string
result
;
name
.
toUTF8String
(
result
);
return
result
;
}
}
}
}
\ No newline at end of file
frameworks/intl/src/index_util.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -77,6 +77,6 @@ std::string IndexUtil::GetIndex(const std::string &String)
label
.
toUTF8String
(
result
);
return
result
;
}
}
}
}
\ No newline at end of file
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
\ No newline at end of file
frameworks/intl/src/locale_config.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -170,14 +170,14 @@ string Adjust(const string &origin)
{
for
(
auto
iter
=
g_languageMap
.
begin
();
iter
!=
g_languageMap
.
end
();
++
iter
)
{
string
key
=
iter
->
first
;
if
(
origin
.
compare
(
0
,
key
.
length
(),
key
)
==
0
)
{
if
(
!
origin
.
compare
(
0
,
key
.
length
(),
key
)
)
{
return
iter
->
second
;
}
}
return
origin
;
}
int32
_t
GetDialectName
(
const
char
*
localeName
,
char
*
name
,
size_t
nameCapacity
,
UErrorCode
&
status
)
size
_t
GetDialectName
(
const
char
*
localeName
,
char
*
name
,
size_t
nameCapacity
,
UErrorCode
&
status
)
{
icu
::
Locale
locale
=
icu
::
Locale
::
forLanguageTag
(
localeName
,
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
...
...
@@ -207,28 +207,29 @@ int32_t GetDialectName(const char *localeName, char *name, size_t nameCapacity,
return
temp
.
size
();
}
int32_t
GetDisplayName
(
const
char
*
locale
,
const
char
*
displayLocale
,
UChar
*
dest
,
int32
_t
destCapacity
,
int32_t
GetDisplayName
(
const
char
*
locale
,
const
char
*
displayLocale
,
UChar
*
dest
,
size
_t
destCapacity
,
UErrorCode
&
status
)
{
if
(
status
!=
U_ZERO_ERROR
)
{
return
0
;
}
if
((
destCapacity
<
0
)
||
(
destCapacity
>
0
&&
dest
==
nullptr
))
{
if
((
destCapacity
<
0
)
||
(
destCapacity
>
0
&&
!
dest
))
{
status
=
U_ILLEGAL_ARGUMENT_ERROR
;
return
0
;
}
char
localeBuffer
[
ULOC_FULLNAME_CAPACITY
];
int32
_t
length
=
GetDialectName
(
locale
,
localeBuffer
,
sizeof
(
localeBuffer
),
status
);
if
(
status
!=
U_ZERO_ERROR
||
length
==
0
)
{
size
_t
length
=
GetDialectName
(
locale
,
localeBuffer
,
sizeof
(
localeBuffer
),
status
);
if
(
status
!=
U_ZERO_ERROR
||
!
length
)
{
status
=
U_ILLEGAL_ARGUMENT_ERROR
;
return
0
;
}
int32_t
length2
=
static_cast
<
int32_t
>
(
length
);
const
UChar
*
str
=
uloc_getTableStringWithFallback
(
U_ICUDATA_LANG
,
displayLocale
,
"Languages"
,
nullptr
,
localeBuffer
,
&
length
,
&
status
);
nullptr
,
localeBuffer
,
&
length
2
,
&
status
);
if
(
status
<=
U_ZERO_ERROR
)
{
int32
_t
len
=
(
length
<
destCapacity
)
?
length
:
destCapacity
;
size
_t
len
=
(
length
<
destCapacity
)
?
length
:
destCapacity
;
if
((
len
>
0
)
&&
(
str
!=
nullptr
))
{
u_memcpy
(
dest
,
str
,
len
);
memcpy_s
((
void
*
)
dest
,
destCapacity
,
(
void
*
)
str
,
len
);
}
}
else
{
status
=
U_USING_DEFAULT_WARNING
;
...
...
@@ -239,13 +240,14 @@ int32_t GetDisplayName(const char *locale, const char *displayLocale, UChar *des
void
GetDisplayLanguageImpl
(
const
char
*
locale
,
const
char
*
displayLocale
,
icu
::
UnicodeString
&
result
)
{
UChar
*
buffer
=
result
.
getBuffer
(
50
);
// size 50 is enough to hold language name
if
(
buffer
==
0
)
{
size_t
destCapacity
=
50
;
// size 50 is enough to hold language name
UChar
*
buffer
=
result
.
getBuffer
((
int32_t
)
destCapacity
);
if
(
!
buffer
)
{
result
.
truncate
(
0
);
return
;
}
UErrorCode
status
=
U_ZERO_ERROR
;
int32_t
length
=
GetDisplayName
(
locale
,
displayLocale
,
buffer
,
result
.
getCapacity
()
,
status
);
int32_t
length
=
GetDisplayName
(
locale
,
displayLocale
,
buffer
,
destCapacity
,
status
);
result
.
releaseBuffer
(
U_SUCCESS
(
status
)
?
length
:
0
);
}
...
...
@@ -253,14 +255,14 @@ string GetDisplayLanguageInner(const string &language, const string &displayLoca
{
icu
::
UnicodeString
unistr
;
// 0 is the start position of language, 2 is the length of zh and fa
if
(
language
.
compare
(
0
,
2
,
"zh"
)
==
0
||
language
.
compare
(
0
,
2
,
"fa"
)
==
0
)
{
if
(
!
language
.
compare
(
0
,
2
,
"zh"
)
||
!
language
.
compare
(
0
,
2
,
"fa"
)
)
{
UErrorCode
error
=
U_ZERO_ERROR
;
icu
::
Locale
disLocale
=
icu
::
Locale
::
forLanguageTag
(
displayLocale
,
error
);
if
(
error
!=
U_ZERO_ERROR
)
{
return
language
;
}
const
char
*
name
=
disLocale
.
getName
();
if
(
name
==
nullptr
)
{
if
(
!
name
)
{
return
language
;
}
GetDisplayLanguageImpl
(
language
.
c_str
(),
name
,
unistr
);
...
...
@@ -431,7 +433,7 @@ bool LocaleConfig::IsValidRegion(const string ®ion)
bool
LocaleConfig
::
IsValidTag
(
const
string
&
tag
)
{
if
(
tag
.
size
()
==
0
)
{
if
(
!
tag
.
size
()
)
{
return
false
;
}
vector
<
string
>
splits
;
...
...
@@ -554,15 +556,15 @@ void LocaleConfig::GetCountriesFromSim(vector<string> &simCountries)
void
LocaleConfig
::
GetListFromFile
(
const
char
*
path
,
const
char
*
resourceName
,
unordered_set
<
string
>
&
ret
)
{
xmlKeepBlanksDefault
(
0
);
if
(
path
==
nullptr
)
{
if
(
!
path
)
{
return
;
}
xmlDocPtr
doc
=
xmlParseFile
(
path
);
if
(
doc
==
nullptr
)
{
if
(
!
doc
)
{
return
;
}
xmlNodePtr
cur
=
xmlDocGetRootElement
(
doc
);
if
(
cur
==
nullptr
||
(
xmlStrcmp
(
cur
->
name
,
reinterpret_cast
<
const
xmlChar
*>
(
resourceName
)))
!=
0
)
{
if
(
!
cur
||
xmlStrcmp
(
cur
->
name
,
reinterpret_cast
<
const
xmlChar
*>
(
resourceName
))
)
{
xmlFreeDoc
(
doc
);
return
;
}
...
...
@@ -850,7 +852,7 @@ bool LocaleConfig::Is24HourClock()
if
(
code
<=
0
)
{
return
false
;
}
if
(
strcmp
(
value
,
"true"
)
==
0
)
{
if
(
!
strcmp
(
value
,
"true"
)
)
{
return
true
;
}
return
false
;
...
...
@@ -866,6 +868,6 @@ bool LocaleConfig::Set24HourClock(bool option)
}
return
SetParameter
(
HOUR_KEY
,
optionStr
.
data
())
==
0
;
}
}
// I18n
}
// Global
}
// OHOS
}
//
namespace
I18n
}
//
namespace
Global
}
//
namespace
OHOS
frameworks/intl/src/locale_info.cpp
浏览文件 @
555f250d
...
...
@@ -43,7 +43,8 @@ LocaleInfo::LocaleInfo(std::string localeTag)
UErrorCode
status
=
U_ZERO_ERROR
;
configs
=
{};
ComputeFinalLocaleTag
(
localeTag
);
auto
builder
=
std
::
make_unique
<
LocaleBuilder
>
();
std
::
unique_ptr
<
icu
::
LocaleBuilder
>
builder
=
nullptr
;
builder
=
std
::
make_unique
<
LocaleBuilder
>
();
Locale
locale
=
builder
->
setLanguageTag
(
StringPiece
(
localeTag
)).
build
(
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
std
::
string
defaultLocaleTag
=
LocaleConfig
::
GetSystemLocale
();
...
...
@@ -69,7 +70,8 @@ LocaleInfo::LocaleInfo(const std::string &localeTag, std::map<std::string, std::
{
UErrorCode
status
=
U_ZERO_ERROR
;
configs
=
configMap
;
auto
builder
=
std
::
make_unique
<
LocaleBuilder
>
();
std
::
unique_ptr
<
icu
::
LocaleBuilder
>
builder
=
nullptr
;
builder
=
std
::
make_unique
<
LocaleBuilder
>
();
if
(
localeTag
!=
""
)
{
ComputeFinalLocaleTag
(
localeTag
);
locale
=
builder
->
setLanguageTag
(
StringPiece
(
finalLocaleTag
)).
build
(
status
);
...
...
@@ -258,7 +260,7 @@ std::string LocaleInfo::Maximize()
if
(
finalLocaleTag
.
find
(
"-u-"
)
!=
std
::
string
::
npos
)
{
restConfigs
=
finalLocaleTag
.
substr
(
finalLocaleTag
.
find
(
"-u-"
));
}
std
::
string
curBaseName
=
(
curLocale
.
getBaseName
()
==
nullptr
)
?
""
:
curLocale
.
getBaseName
();
std
::
string
curBaseName
=
(
!
curLocale
.
getBaseName
()
)
?
""
:
curLocale
.
getBaseName
();
std
::
replace
(
curBaseName
.
begin
(),
curBaseName
.
end
(),
'_'
,
'-'
);
std
::
string
localeTag
=
curBaseName
+
restConfigs
;
return
localeTag
;
...
...
@@ -276,7 +278,7 @@ std::string LocaleInfo::Minimize()
if
(
finalLocaleTag
.
find
(
"-u-"
)
!=
std
::
string
::
npos
)
{
restConfigs
=
finalLocaleTag
.
substr
(
finalLocaleTag
.
find
(
"-u-"
));
}
std
::
string
curBaseName
=
(
curLocale
.
getBaseName
()
==
nullptr
)
?
""
:
curLocale
.
getBaseName
();
std
::
string
curBaseName
=
(
!
curLocale
.
getBaseName
()
)
?
""
:
curLocale
.
getBaseName
();
std
::
replace
(
curBaseName
.
begin
(),
curBaseName
.
end
(),
'_'
,
'-'
);
std
::
string
localeTag
=
curBaseName
+
restConfigs
;
return
localeTag
;
...
...
frameworks/intl/src/locale_util.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -22,6 +22,6 @@ bool LocaleUtil::IsRTL(const std::string &locale)
icu
::
Locale
curLocale
(
locale
.
c_str
());
return
curLocale
.
isRightToLeft
();
}
}
// I18n
}
// Global
}
// OHOS
\ No newline at end of file
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
\ No newline at end of file
frameworks/intl/src/measure_data.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -415,7 +415,7 @@ void GetRestPreferredUnit(const string ®ion, const string &usage, vector<stri
break
;
}
}
if
(
units
.
size
()
==
0
)
{
if
(
!
units
.
size
()
)
{
GetFallbackPreferredUnit
(
region
,
usage
,
units
);
}
}
...
...
@@ -466,7 +466,7 @@ void GetPreferredUnit(const string ®ion, const string &usage, vector<string>
break
;
}
}
if
(
units
.
size
()
==
0
)
{
if
(
!
units
.
size
()
)
{
GetRestPreferredUnit
(
region
,
usage
,
units
);
}
}
...
...
@@ -488,7 +488,7 @@ void ComputeFactorValue(const string &unit, const string &measSys, vector<double
double
ComputeSIPrefixValue
(
const
string
&
unit
)
{
for
(
auto
&
prefixValue
:
PREFIX_VALUE
)
{
if
(
unit
.
rfind
(
prefixValue
.
first
,
0
)
==
0
)
{
if
(
!
unit
.
rfind
(
prefixValue
.
first
,
0
)
)
{
return
prefixValue
.
second
;
}
}
...
...
@@ -498,7 +498,7 @@ double ComputeSIPrefixValue(const string &unit)
void
ComputePowerValue
(
const
string
&
unit
,
const
string
&
measSys
,
vector
<
double
>
&
factors
)
{
for
(
auto
&
powerValue
:
POWER_VALUE
)
{
if
(
unit
.
rfind
(
powerValue
.
first
,
0
)
==
0
)
{
if
(
!
unit
.
rfind
(
powerValue
.
first
,
0
)
)
{
string
baseUnit
=
unit
.
substr
(
powerValue
.
first
.
length
());
double
value
=
ComputeSIPrefixValue
(
baseUnit
);
double
compare
=
0.0
;
...
...
@@ -518,12 +518,12 @@ int ComputeValue(const string &unit, const string &measSys, vector<double> &fact
if
(
baseValues
.
size
()
==
BASE_VALUE_SIZE
)
{
vector
<
double
>
numerator
=
{
1.0
,
0.0
};
int
status
=
ComputeValue
(
baseValues
[
0
],
measSys
,
numerator
);
if
(
status
==
0
)
{
if
(
!
status
)
{
return
0
;
}
vector
<
double
>
denominator
=
{
1.0
,
0.0
};
status
=
ComputeValue
(
baseValues
[
1
],
measSys
,
denominator
);
if
(
status
==
0
)
{
if
(
!
status
)
{
return
0
;
}
factors
[
0
]
=
numerator
[
0
]
/
denominator
[
0
];
...
...
@@ -557,23 +557,23 @@ int Convert(double &value, const string &fromUnit, const string &fromMeasSys, co
UErrorCode
icuStatus
=
U_ZERO_ERROR
;
icu
::
MeasureUnit
::
getAvailable
(
unitArray
,
MAX_UNIT_NUM
,
icuStatus
);
for
(
icu
::
MeasureUnit
curUnit
:
unitArray
)
{
if
(
strcmp
(
curUnit
.
getSubtype
(),
fromUnit
.
c_str
())
==
0
)
{
if
(
!
strcmp
(
curUnit
.
getSubtype
(),
fromUnit
.
c_str
())
)
{
fromUnitType
=
curUnit
.
getType
();
}
if
(
strcmp
(
curUnit
.
getSubtype
(),
toUnit
.
c_str
())
==
0
)
{
if
(
!
strcmp
(
curUnit
.
getSubtype
(),
toUnit
.
c_str
())
)
{
toUnitType
=
curUnit
.
getType
();
}
}
if
(
fromUnitType
.
empty
()
||
toUnitType
.
empty
()
||
strcmp
(
fromUnitType
.
c_str
(),
toUnitType
.
c_str
())
!=
0
)
{
if
(
fromUnitType
.
empty
()
||
toUnitType
.
empty
()
||
strcmp
(
fromUnitType
.
c_str
(),
toUnitType
.
c_str
()))
{
return
0
;
}
int
status
=
ComputeValue
(
fromUnit
,
fromMeasSys
,
fromFactors
);
if
(
status
==
0
)
{
if
(
!
status
)
{
return
0
;
}
vector
<
double
>
toFactors
=
{
0.0
,
0.0
};
status
=
ComputeValue
(
toUnit
,
toMeasSys
,
toFactors
);
if
(
status
==
0
)
{
if
(
!
status
)
{
return
0
;
}
if
(
fromFactors
.
size
()
==
FACTOR_SIZE
)
{
...
...
@@ -585,6 +585,6 @@ int Convert(double &value, const string &fromUnit, const string &fromMeasSys, co
value
=
result
;
return
1
;
}
}
// I18n
}
// Global
}
// OHOS
\ No newline at end of file
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
\ No newline at end of file
frameworks/intl/src/number_format.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -59,7 +59,8 @@ std::unordered_map<UMeasurementSystem, std::string> NumberFormat::measurementSys
NumberFormat
::
NumberFormat
(
const
std
::
vector
<
std
::
string
>
&
localeTags
,
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
auto
builder
=
std
::
make_unique
<
icu
::
LocaleBuilder
>
();
std
::
unique_ptr
<
icu
::
LocaleBuilder
>
builder
=
nullptr
;
builder
=
std
::
make_unique
<
icu
::
LocaleBuilder
>
();
ParseConfigs
(
configs
);
for
(
size_t
i
=
0
;
i
<
localeTags
.
size
();
i
++
)
{
std
::
string
curLocale
=
localeTags
[
i
];
...
...
@@ -73,7 +74,7 @@ NumberFormat::NumberFormat(const std::vector<std::string> &localeTags, std::map<
break
;
}
}
if
(
localeInfo
==
nullptr
)
{
if
(
!
localeInfo
)
{
localeInfo
=
new
LocaleInfo
(
LocaleConfig
::
GetSystemLocale
(),
configs
);
locale
=
localeInfo
->
GetLocale
();
localeBaseName
=
localeInfo
->
GetBaseName
();
...
...
@@ -106,7 +107,7 @@ void NumberFormat::InitProperties()
}
if
(
!
styleString
.
empty
()
&&
styleString
==
"unit"
)
{
for
(
icu
::
MeasureUnit
curUnit
:
unitArray
)
{
if
(
strcmp
(
curUnit
.
getSubtype
(),
unit
.
c_str
())
==
0
)
{
if
(
!
strcmp
(
curUnit
.
getSubtype
(),
unit
.
c_str
())
)
{
numberFormat
=
numberFormat
.
unit
(
curUnit
);
unitType
=
curUnit
.
getType
();
}
...
...
@@ -255,7 +256,7 @@ std::string NumberFormat::Format(double number)
double
num
=
number
;
for
(
size_t
i
=
0
;
i
<
preferredUnits
.
size
();
i
++
)
{
int
status
=
Convert
(
num
,
unit
,
unitMeasSys
,
preferredUnits
[
i
],
unitMeasSys
);
if
(
status
==
0
)
{
if
(
!
status
)
{
continue
;
}
if
(
num
>=
1
)
{
...
...
@@ -274,7 +275,7 @@ std::string NumberFormat::Format(double number)
}
if
(
!
preferredUnit
.
empty
())
{
for
(
icu
::
MeasureUnit
curUnit
:
unitArray
)
{
if
(
strcmp
(
curUnit
.
getSubtype
(),
preferredUnit
.
c_str
())
==
0
)
{
if
(
!
strcmp
(
curUnit
.
getSubtype
(),
preferredUnit
.
c_str
())
)
{
numberFormat
=
numberFormat
.
unit
(
curUnit
);
}
}
...
...
frameworks/intl/src/phone_number_format.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -72,6 +72,6 @@ std::string PhoneNumberFormat::format(const std::string &number) const
util
->
Format
(
phoneNumber
,
phoneNumberFormat
,
&
formatted_number
);
return
formatted_number
;
}
}
}
}
\ No newline at end of file
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
\ No newline at end of file
frameworks/intl/src/plural_rules.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -81,7 +81,7 @@ void PluralRules::InitPluralRules(std::vector<std::string> &localeTags,
{
UPluralType
uPluralType
=
(
type
==
"cardinal"
)
?
UPLURAL_TYPE_CARDINAL
:
UPLURAL_TYPE_ORDINAL
;
UErrorCode
status
=
UErrorCode
::
U_ZERO_ERROR
;
if
(
localeTags
.
size
()
==
0
)
{
if
(
!
localeTags
.
size
()
)
{
localeTags
.
push_back
(
LocaleConfig
::
GetSystemLocale
());
}
for
(
size_t
i
=
0
;
i
<
localeTags
.
size
();
i
++
)
{
...
...
@@ -92,12 +92,12 @@ void PluralRules::InitPluralRules(std::vector<std::string> &localeTags,
locale
=
localeInfo
->
GetLocale
();
localeStr
=
localeInfo
->
GetBaseName
();
pluralRules
=
icu
::
PluralRules
::
forLocale
(
locale
,
uPluralType
,
status
);
if
(
status
!=
UErrorCode
::
U_ZERO_ERROR
||
pluralRules
==
nullptr
)
{
if
(
status
!=
UErrorCode
::
U_ZERO_ERROR
||
!
pluralRules
)
{
continue
;
}
}
}
if
(
status
!=
UErrorCode
::
U_ZERO_ERROR
||
pluralRules
==
nullptr
)
{
if
(
status
!=
UErrorCode
::
U_ZERO_ERROR
||
!
pluralRules
)
{
HiLog
::
Error
(
LABEL
,
"PluralRules object created failed"
);
return
;
}
...
...
@@ -131,7 +131,7 @@ PluralRules::PluralRules(std::vector<std::string> &localeTags, std::map<std::str
PluralRules
::~
PluralRules
()
{
if
(
pluralRules
==
nullptr
)
{
if
(
!
pluralRules
)
{
delete
pluralRules
;
pluralRules
=
nullptr
;
}
...
...
@@ -150,6 +150,6 @@ std::string PluralRules::Select(double number)
unicodeString
.
toUTF8String
(
result
);
return
result
;
}
}
}
}
\ No newline at end of file
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
\ No newline at end of file
frameworks/intl/src/preferred_language.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -48,7 +48,7 @@ bool PreferredLanguage::AddPreferredLanguageExist(std::vector<std::string> &pref
}
}
preferredLanguageList
[
index
]
=
language
;
if
(
languageIdx
==
0
||
index
==
0
)
{
if
(
!
languageIdx
||
!
index
)
{
bool
status
=
LocaleConfig
::
SetSystemLanguage
(
preferredLanguageList
[
0
]);
if
(
!
status
)
{
return
false
;
...
...
@@ -61,7 +61,7 @@ bool PreferredLanguage::AddPreferredLanguageNonExist(std::vector<std::string> &p
const
std
::
string
&
language
)
{
preferredLanguageList
.
insert
(
preferredLanguageList
.
begin
()
+
index
,
language
);
if
(
index
==
0
)
{
if
(
!
index
)
{
bool
status
=
LocaleConfig
::
SetSystemLanguage
(
preferredLanguageList
[
0
]);
if
(
!
status
)
{
return
false
;
...
...
@@ -131,7 +131,7 @@ bool PreferredLanguage::RemovePreferredLanguage(int index)
std
::
vector
<
std
::
string
>::
iterator
it
=
preferredLanguageList
.
begin
();
preferredLanguageList
.
erase
(
it
+
idx
);
bool
status
=
false
;
if
(
idx
==
0
)
{
if
(
!
idx
)
{
status
=
LocaleConfig
::
SetSystemLanguage
(
preferredLanguageList
[
0
]);
if
(
!
status
)
{
return
false
;
...
...
@@ -154,7 +154,7 @@ std::vector<std::string> PreferredLanguage::GetPreferredLanguageList()
std
::
string
systemLanguage
=
LocaleConfig
::
GetSystemLanguage
();
std
::
vector
<
std
::
string
>
list
;
Split
(
preferredLanguageValue
,
";"
,
list
);
if
(
list
.
size
()
==
0
)
{
if
(
!
list
.
size
()
)
{
if
(
systemLanguage
!=
""
)
{
list
.
push_back
(
systemLanguage
);
}
...
...
@@ -248,23 +248,6 @@ bool PreferredLanguage::IsMatched(const std::string& preferred, const std::strin
std
::
string
PreferredLanguage
::
GetFirstPreferredLanguage
()
{
std
::
vector
<
std
::
string
>
preferredLanguageList
=
GetPreferredLanguageList
();
std
::
set
<
std
::
string
>
resources
=
GetResources
();
int
minmumMatchedIdx
=
-
1
;
for
(
size_t
i
=
0
;
i
<
preferredLanguageList
.
size
();
i
++
)
{
for
(
std
::
set
<
std
::
string
>::
iterator
it
=
resources
.
begin
();
it
!=
resources
.
end
();
++
it
)
{
std
::
string
preferredLanguage
=
preferredLanguageList
[
i
];
if
(
preferredLanguage
==
"en-Qaag"
)
{
preferredLanguage
=
"en-Latn"
;
}
if
(
IsMatched
(
preferredLanguage
,
*
it
))
{
minmumMatchedIdx
=
(
int
)
i
;
break
;
}
}
}
if
(
minmumMatchedIdx
!=
-
1
)
{
return
preferredLanguageList
[
minmumMatchedIdx
];
}
return
preferredLanguageList
[
0
];
}
...
...
@@ -296,7 +279,7 @@ bool PreferredLanguage::IsValidLanguage(const std::string &language)
bool
PreferredLanguage
::
IsValidTag
(
const
std
::
string
&
tag
)
{
if
(
tag
.
size
()
==
0
)
{
if
(
!
tag
.
size
()
)
{
return
false
;
}
std
::
vector
<
std
::
string
>
splits
;
...
...
@@ -320,6 +303,6 @@ void PreferredLanguage::Split(const std::string &src, const std::string &sep, st
dest
.
push_back
(
src
.
substr
(
begin
));
}
}
}
}
}
\ No newline at end of file
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
\ No newline at end of file
frameworks/intl/src/relative_time_format.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -50,7 +50,8 @@ RelativeTimeFormat::RelativeTimeFormat(const std::vector<std::string> &localeTag
std
::
map
<
std
::
string
,
std
::
string
>
&
configs
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
auto
builder
=
std
::
make_unique
<
icu
::
LocaleBuilder
>
();
std
::
unique_ptr
<
icu
::
LocaleBuilder
>
builder
=
nullptr
;
builder
=
std
::
make_unique
<
icu
::
LocaleBuilder
>
();
ParseConfigs
(
configs
);
for
(
size_t
i
=
0
;
i
<
localeTags
.
size
();
i
++
)
{
std
::
string
curLocale
=
localeTags
[
i
];
...
...
@@ -64,7 +65,7 @@ RelativeTimeFormat::RelativeTimeFormat(const std::vector<std::string> &localeTag
break
;
}
}
if
(
localeInfo
==
nullptr
||
relativeTimeFormat
==
nullptr
)
{
if
(
!
localeInfo
||
!
relativeTimeFormat
)
{
localeInfo
=
std
::
make_unique
<
LocaleInfo
>
(
LocaleConfig
::
GetSystemLocale
(),
configs
);
locale
=
localeInfo
->
GetLocale
();
localeBaseName
=
localeInfo
->
GetBaseName
();
...
...
@@ -96,13 +97,13 @@ void RelativeTimeFormat::ParseConfigs(std::map<std::string, std::string> &config
std
::
string
RelativeTimeFormat
::
Format
(
double
number
,
const
std
::
string
&
unit
)
{
if
(
relativeUnits
.
count
(
unit
)
==
0
)
{
if
(
!
relativeUnits
.
count
(
unit
)
)
{
return
""
;
}
UErrorCode
status
=
U_ZERO_ERROR
;
icu
::
UnicodeString
formattedTime
;
std
::
string
result
;
if
(
strcmp
(
numeric
.
c_str
(),
"always"
)
==
0
)
{
if
(
!
strcmp
(
numeric
.
c_str
(),
"always"
)
)
{
formattedTime
=
relativeTimeFormat
->
formatNumericToValue
(
number
,
relativeUnits
[
unit
],
status
).
toString
(
status
);
}
else
{
formattedTime
=
relativeTimeFormat
->
formatToValue
(
number
,
relativeUnits
[
unit
],
status
).
toString
(
status
);
...
...
@@ -142,13 +143,13 @@ void RelativeTimeFormat::ProcessIntegerField(const std::map<size_t, size_t> &ind
void
RelativeTimeFormat
::
FormatToParts
(
double
number
,
const
std
::
string
&
unit
,
std
::
vector
<
std
::
vector
<
std
::
string
>>
&
timeVector
)
{
if
(
relativeUnits
.
count
(
unit
)
==
0
)
{
if
(
!
relativeUnits
.
count
(
unit
)
)
{
return
;
}
UErrorCode
status
=
U_ZERO_ERROR
;
std
::
string
result
;
icu
::
FormattedRelativeDateTime
fmtRelativeTime
;
if
(
numeric
.
empty
()
||
strcmp
(
numeric
.
c_str
(),
"always"
)
==
0
)
{
if
(
numeric
.
empty
()
||
!
strcmp
(
numeric
.
c_str
(),
"always"
)
)
{
fmtRelativeTime
=
relativeTimeFormat
->
formatNumericToValue
(
number
,
relativeUnits
[
unit
],
status
);
}
else
{
fmtRelativeTime
=
relativeTimeFormat
->
formatToValue
(
number
,
relativeUnits
[
unit
],
status
);
...
...
frameworks/intl/test/BUILD.gn
浏览文件 @
555f250d
# Copyright (c) 2021 Huawei Device Co., Ltd.
# 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
...
...
frameworks/intl/test/unittest/intl_test.cpp
浏览文件 @
555f250d
...
...
@@ -67,7 +67,7 @@ HWTEST_F(IntlTest, IntlFuncTest001, TestSize.Level1)
{
"weekday"
,
"long"
},
{
"era"
,
"short"
}
};
DateTimeFormat
*
dateFormat
=
new
(
std
::
nothrow
)
DateTimeFormat
(
locales
,
options
);
if
(
dateFormat
==
nullptr
)
{
if
(
!
dateFormat
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -98,7 +98,7 @@ HWTEST_F(IntlTest, IntlFuncTest002, TestSize.Level0)
{
"numeric"
,
"true"
},
{
"numberingSystem"
,
"jpan"
}
};
LocaleInfo
*
loc
=
new
(
std
::
nothrow
)
LocaleInfo
(
locale
,
options
);
if
(
loc
==
nullptr
)
{
if
(
!
loc
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -125,7 +125,7 @@ HWTEST_F(IntlTest, IntlFuncTest003, TestSize.Level1)
{
string
locale
=
"en-GB"
;
LocaleInfo
*
loc
=
new
(
std
::
nothrow
)
LocaleInfo
(
locale
);
if
(
loc
==
nullptr
)
{
if
(
!
loc
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -156,7 +156,7 @@ HWTEST_F(IntlTest, IntlFuncTest004, TestSize.Level1)
map
<
string
,
string
>
options
=
{
{
"dateStyle"
,
dateStyle
},
{
"timeStyle"
,
timeStyle
}
};
DateTimeFormat
*
dateFormat
=
new
(
std
::
nothrow
)
DateTimeFormat
(
locales
,
options
);
if
(
dateFormat
==
nullptr
)
{
if
(
!
dateFormat
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -185,7 +185,7 @@ HWTEST_F(IntlTest, IntlFuncTest006, TestSize.Level1)
{
"day"
,
"numeric"
},
{
"weekday"
,
"long"
}
};
DateTimeFormat
*
dateFormat
=
new
(
std
::
nothrow
)
DateTimeFormat
(
locales
,
options
);
if
(
dateFormat
==
nullptr
)
{
if
(
!
dateFormat
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -223,7 +223,7 @@ HWTEST_F(IntlTest, IntlFuncTest005, TestSize.Level1)
{
"currencySign"
,
"accounting"
},
{
"signDisplay"
,
"always"
}
};
NumberFormat
*
numFmt
=
new
(
std
::
nothrow
)
NumberFormat
(
locales
,
options
);
if
(
numFmt
==
nullptr
)
{
if
(
!
numFmt
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -256,7 +256,7 @@ HWTEST_F(IntlTest, IntlFuncTest007, TestSize.Level1)
{
"unit"
,
"meter"
},
{
"unitDisplay"
,
"long"
}
};
NumberFormat
*
numFmt
=
new
(
std
::
nothrow
)
NumberFormat
(
locales
,
options
);
if
(
numFmt
==
nullptr
)
{
if
(
!
numFmt
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -284,7 +284,7 @@ HWTEST_F(IntlTest, IntlFuncTest008, TestSize.Level1)
{
"minimumIntegerDigits"
,
minimumIntegerDigits
},
{
"maximumFractionDigits"
,
maximumFractionDigits
}
};
NumberFormat
*
numFmt
=
new
(
std
::
nothrow
)
NumberFormat
(
locales
,
options
);
if
(
numFmt
==
nullptr
)
{
if
(
!
numFmt
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -312,7 +312,7 @@ HWTEST_F(IntlTest, IntlFuncTest009, TestSize.Level1)
{
"minimumIntegerDigits"
,
minimumIntegerDigits
},
{
"maximumFractionDigits"
,
maximumFractionDigits
}
};
NumberFormat
*
numFmt
=
new
(
std
::
nothrow
)
NumberFormat
(
locales
,
options
);
if
(
numFmt
==
nullptr
)
{
if
(
!
numFmt
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -337,7 +337,7 @@ HWTEST_F(IntlTest, IntlFuncTest010, TestSize.Level1)
map
<
string
,
string
>
options
=
{
{
"style"
,
style
},
{
"notation"
,
"scientific"
}
};
NumberFormat
*
numFmt
=
new
(
std
::
nothrow
)
NumberFormat
(
locales
,
options
);
if
(
numFmt
==
nullptr
)
{
if
(
!
numFmt
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -363,7 +363,7 @@ HWTEST_F(IntlTest, IntlFuncTest011, TestSize.Level1)
{
"notation"
,
"compact"
},
{
"compactDisplay"
,
"long"
}
};
NumberFormat
*
numFmt
=
new
(
std
::
nothrow
)
NumberFormat
(
locales
,
options
);
if
(
numFmt
==
nullptr
)
{
if
(
!
numFmt
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -386,7 +386,7 @@ HWTEST_F(IntlTest, IntlFuncTest0012, TestSize.Level1)
locales
.
push_back
(
locale
);
std
::
string
expects
=
"4/14/21"
;
DateTimeFormat
*
dateFormat
=
new
(
std
::
nothrow
)
DateTimeFormat
(
locales
,
options
);
if
(
dateFormat
==
nullptr
)
{
if
(
!
dateFormat
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -409,7 +409,7 @@ HWTEST_F(IntlTest, IntlFuncTest0013, TestSize.Level1)
map
<
string
,
string
>
options
=
{};
std
::
string
expects
=
"123,456.789"
;
NumberFormat
*
numFmt
=
new
(
std
::
nothrow
)
NumberFormat
(
locales
,
options
);
if
(
numFmt
==
nullptr
)
{
if
(
!
numFmt
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -432,7 +432,7 @@ HWTEST_F(IntlTest, IntlFuncTest0014, TestSize.Level1)
locales
.
push_back
(
locale
);
map
<
string
,
string
>
options
=
{
{
"timeZone"
,
"America/Los_Angeles"
},
{
"timeZoneName"
,
"long"
}
};
DateTimeFormat
*
dateFormat
=
new
(
std
::
nothrow
)
DateTimeFormat
(
locales
,
options
);
if
(
dateFormat
==
nullptr
)
{
if
(
!
dateFormat
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
@@ -455,7 +455,7 @@ HWTEST_F(IntlTest, IntlFuncTest0015, TestSize.Level1)
locales
.
push_back
(
locale
);
map
<
string
,
string
>
options
=
{
{
"timeZone"
,
"America/Los_Angeles"
},
{
"timeZoneName"
,
"long"
}
};
DateTimeFormat
*
dateFormat
=
new
(
std
::
nothrow
)
DateTimeFormat
(
locales
,
options
);
if
(
dateFormat
==
nullptr
)
{
if
(
!
dateFormat
)
{
EXPECT_TRUE
(
false
);
return
;
}
...
...
frameworks/intl/test/unittest/locale_config_test.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -51,7 +51,7 @@ void LocaleConfigTest::TearDown(void)
HWTEST_F
(
LocaleConfigTest
,
LocaleConfigFuncTest001
,
TestSize
.
Level1
)
{
int
ret
=
SetParameter
(
"hm.sys.language"
,
""
);
if
(
ret
==
0
)
{
if
(
!
ret
)
{
EXPECT_EQ
(
LocaleConfig
::
GetSystemLanguage
(),
"zh-Hans"
);
}
}
...
...
@@ -64,7 +64,7 @@ HWTEST_F(LocaleConfigTest, LocaleConfigFuncTest001, TestSize.Level1)
HWTEST_F
(
LocaleConfigTest
,
LocaleConfigFuncTest002
,
TestSize
.
Level1
)
{
int
ret
=
SetParameter
(
"hm.sys.locale"
,
""
);
if
(
ret
==
0
)
{
if
(
!
ret
)
{
EXPECT_EQ
(
LocaleConfig
::
GetSystemRegion
(),
"CN"
);
}
}
...
...
@@ -77,7 +77,7 @@ HWTEST_F(LocaleConfigTest, LocaleConfigFuncTest002, TestSize.Level1)
HWTEST_F
(
LocaleConfigTest
,
LocaleConfigFuncTest003
,
TestSize
.
Level1
)
{
int
ret
=
SetParameter
(
"hm.sys.locale"
,
""
);
if
(
ret
==
0
)
{
if
(
!
ret
)
{
EXPECT_EQ
(
LocaleConfig
::
GetSystemLocale
(),
"zh-Hans-CN"
);
}
}
...
...
@@ -132,7 +132,7 @@ HWTEST_F(LocaleConfigTest, LocaleConfigFuncTest007, TestSize.Level1)
{
vector
<
string
>
countries
;
LocaleConfig
::
GetSystemCountries
(
countries
);
unsigned
int
size
=
24
1
;
unsigned
int
size
=
24
0
;
EXPECT_EQ
(
countries
.
size
(),
size
);
}
...
...
frameworks/zone/BUILD.gn
浏览文件 @
555f250d
# Copyright (c) 2021 Huawei Device Co., Ltd.
# 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
...
...
frameworks/zone/src/zone_util.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -82,11 +82,11 @@ string ZoneUtil::GetDefaultZone(const string &country)
string
ZoneUtil
::
GetDefaultZone
(
const
int32_t
number
)
{
string
*
region_code
=
new
(
nothrow
)
string
();
if
(
region_code
==
nullptr
)
{
if
(
!
region_code
)
{
return
""
;
}
phone_util
.
GetRegionCodeForCountryCode
(
number
,
region_code
);
if
(
region_code
==
nullptr
)
{
if
(
!
region_code
)
{
return
""
;
}
string
ret
=
GetDefaultZone
(
*
region_code
);
...
...
@@ -114,11 +114,11 @@ string ZoneUtil::GetDefaultZone(const string country, const int32_t offset)
string
ZoneUtil
::
GetDefaultZone
(
const
int32_t
number
,
const
int32_t
offset
)
{
string
*
region_code
=
new
(
nothrow
)
string
();
if
(
region_code
==
nullptr
)
{
if
(
!
region_code
)
{
return
""
;
}
phone_util
.
GetRegionCodeForCountryCode
(
number
,
region_code
);
if
(
region_code
==
nullptr
)
{
if
(
!
region_code
)
{
return
""
;
}
string
ret
=
GetDefaultZone
(
*
region_code
,
offset
);
...
...
@@ -157,7 +157,7 @@ void ZoneUtil::GetString(StringEnumeration *strEnum, string& ret)
{
UErrorCode
status
=
U_ZERO_ERROR
;
UnicodeString
uniString
;
if
(
strEnum
==
nullptr
)
{
if
(
!
strEnum
)
{
return
;
}
int32_t
count
=
strEnum
->
count
(
status
);
...
...
@@ -165,7 +165,7 @@ void ZoneUtil::GetString(StringEnumeration *strEnum, string& ret)
return
;
}
const
UnicodeString
*
uniStr
=
strEnum
->
snext
(
status
);
if
((
status
!=
U_ZERO_ERROR
)
||
(
uniStr
==
nullp
tr
))
{
if
((
status
!=
U_ZERO_ERROR
)
||
(
!
uniS
tr
))
{
return
;
}
UnicodeString
canonicalUnistring
;
...
...
@@ -179,7 +179,7 @@ void ZoneUtil::GetString(StringEnumeration *strEnum, string& ret)
void
ZoneUtil
::
GetList
(
StringEnumeration
*
strEnum
,
vector
<
string
>
&
retVec
)
{
if
(
strEnum
==
nullptr
)
{
if
(
!
strEnum
)
{
return
;
}
UErrorCode
status
=
U_ZERO_ERROR
;
...
...
@@ -189,7 +189,7 @@ void ZoneUtil::GetList(StringEnumeration *strEnum, vector<string> &retVec)
}
while
(
count
>
0
)
{
const
UnicodeString
*
uniStr
=
strEnum
->
snext
(
status
);
if
((
uniStr
==
nullp
tr
)
||
(
status
!=
U_ZERO_ERROR
))
{
if
((
!
uniS
tr
)
||
(
status
!=
U_ZERO_ERROR
))
{
retVec
.
clear
();
break
;
}
...
...
frameworks/zone/test/unittest/zone_util_test.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
interfaces/js/kits/BUILD.gn
浏览文件 @
555f250d
# Copyright (c) 2021 Huawei Device Co., Ltd.
# 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
...
...
interfaces/js/kits/include/i18n_addon.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -20,6 +20,7 @@
#include "napi/native_api.h"
#include "i18n_break_iterator.h"
#include "i18n_calendar.h"
#include "i18n_timezone.h"
#include "index_util.h"
#include "napi/native_node_api.h"
#include "locale_config.h"
...
...
@@ -73,6 +74,8 @@ public:
static
napi_value
RemovePreferredLanguage
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
GetPreferredLanguageList
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
GetFirstPreferredLanguage
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
InitI18nTimeZone
(
napi_env
env
,
napi_value
exports
);
static
napi_value
GetI18nTimeZone
(
napi_env
env
,
napi_callback_info
info
);
private:
static
void
CreateInitProperties
(
napi_property_descriptor
*
properties
);
...
...
@@ -122,12 +125,20 @@ private:
static
napi_value
CreateUtilObject
(
napi_env
env
);
static
napi_value
CreateCharacterObject
(
napi_env
env
);
static
napi_value
I18nTimeZoneConstructor
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
GetID
(
napi_env
env
,
napi_callback_info
info
);
static
int32_t
GetParameter
(
napi_env
env
,
napi_value
*
argv
,
std
::
string
&
localeStr
,
bool
&
isDST
);
static
napi_value
GetTimeZoneDisplayName
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
GetOffset
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
GetRawOffset
(
napi_env
env
,
napi_callback_info
info
);
napi_env
env_
;
napi_ref
wrapper_
;
std
::
unique_ptr
<
PhoneNumberFormat
>
phonenumberfmt_
;
std
::
unique_ptr
<
I18nCalendar
>
calendar_
;
std
::
unique_ptr
<
I18nBreakIterator
>
brkiter_
;
std
::
unique_ptr
<
IndexUtil
>
indexUtil_
;
std
::
unique_ptr
<
PhoneNumberFormat
>
phonenumberfmt_
=
nullptr
;
std
::
unique_ptr
<
I18nCalendar
>
calendar_
=
nullptr
;
std
::
unique_ptr
<
I18nBreakIterator
>
brkiter_
=
nullptr
;
std
::
unique_ptr
<
IndexUtil
>
indexUtil_
=
nullptr
;
std
::
unique_ptr
<
I18nTimeZone
>
timezone_
=
nullptr
;
};
}
// namespace I18n
}
// namespace Global
...
...
interfaces/js/kits/include/intl_addon.h
浏览文件 @
555f250d
...
...
@@ -122,12 +122,12 @@ private:
napi_env
env_
;
napi_ref
wrapper_
;
std
::
unique_ptr
<
LocaleInfo
>
locale_
;
std
::
unique_ptr
<
DateTimeFormat
>
datefmt_
;
std
::
unique_ptr
<
NumberFormat
>
numberfmt_
;
std
::
unique_ptr
<
RelativeTimeFormat
>
relativetimefmt_
;
std
::
unique_ptr
<
Collator
>
collator_
;
std
::
unique_ptr
<
PluralRules
>
pluralrules_
;
std
::
unique_ptr
<
LocaleInfo
>
locale_
=
nullptr
;
std
::
unique_ptr
<
DateTimeFormat
>
datefmt_
=
nullptr
;
std
::
unique_ptr
<
NumberFormat
>
numberfmt_
=
nullptr
;
std
::
unique_ptr
<
RelativeTimeFormat
>
relativetimefmt_
=
nullptr
;
std
::
unique_ptr
<
Collator
>
collator_
=
nullptr
;
std
::
unique_ptr
<
PluralRules
>
pluralrules_
=
nullptr
;
};
}
// namespace I18n
}
// namespace Global
...
...
interfaces/js/kits/src/i18n_addon.cpp
浏览文件 @
555f250d
此差异已折叠。
点击以展开。
interfaces/js/kits/src/intl_addon.cpp
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -37,7 +37,7 @@ IntlAddon::~IntlAddon()
void
IntlAddon
::
Destructor
(
napi_env
env
,
void
*
nativeObject
,
void
*
hint
)
{
if
(
nativeObject
==
nullptr
)
{
if
(
!
nativeObject
)
{
return
;
}
reinterpret_cast
<
IntlAddon
*>
(
nativeObject
)
->~
IntlAddon
();
...
...
@@ -76,7 +76,7 @@ napi_value IntlAddon::InitLocale(napi_env env, napi_value exports)
return
nullptr
;
}
g_constructor
=
new
(
std
::
nothrow
)
napi_ref
;
if
(
g_constructor
==
nullpt
r
)
{
if
(
!
g_constructo
r
)
{
HiLog
::
Error
(
LABEL
,
"Failed to create ref at init"
);
return
nullptr
;
}
...
...
@@ -311,8 +311,9 @@ napi_value IntlAddon::LocaleConstructor(napi_env env, napi_callback_info info)
GetBoolOptionValue
(
env
,
argv
[
1
],
"numeric"
,
map
);
GetOptionValue
(
env
,
argv
[
1
],
"caseFirst"
,
map
);
}
std
::
unique_ptr
<
IntlAddon
>
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
obj
==
nullptr
)
{
std
::
unique_ptr
<
IntlAddon
>
obj
=
nullptr
;
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
!
obj
)
{
HiLog
::
Error
(
LABEL
,
"Create IntlAddon failed"
);
return
nullptr
;
}
...
...
@@ -394,8 +395,9 @@ napi_value IntlAddon::DateTimeFormatConstructor(napi_env env, napi_callback_info
GetDateOptionValues
(
env
,
argv
[
1
],
map
);
}
std
::
unique_ptr
<
IntlAddon
>
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
obj
==
nullptr
)
{
std
::
unique_ptr
<
IntlAddon
>
obj
=
nullptr
;
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
!
obj
)
{
HiLog
::
Error
(
LABEL
,
"Create IntlAddon failed"
);
return
nullptr
;
}
...
...
@@ -464,8 +466,9 @@ napi_value IntlAddon::RelativeTimeFormatConstructor(napi_env env, napi_callback_
GetRelativeTimeOptionValues
(
env
,
argv
[
1
],
map
);
}
std
::
unique_ptr
<
IntlAddon
>
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
obj
==
nullptr
)
{
std
::
unique_ptr
<
IntlAddon
>
obj
=
nullptr
;
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
!
obj
)
{
HiLog
::
Error
(
LABEL
,
"Create IntlAddon failed"
);
return
nullptr
;
}
...
...
@@ -513,7 +516,7 @@ napi_value IntlAddon::FormatDateTime(napi_env env, napi_callback_info info)
}
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
datefmt_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
datefmt_
)
{
HiLog
::
Error
(
LABEL
,
"Get DateTimeFormat object failed"
);
return
nullptr
;
}
...
...
@@ -555,7 +558,7 @@ napi_value IntlAddon::FormatDateTimeRange(napi_env env, napi_callback_info info)
}
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
datefmt_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
datefmt_
)
{
HiLog
::
Error
(
LABEL
,
"Get DateTimeFormat object failed"
);
return
nullptr
;
}
...
...
@@ -626,8 +629,9 @@ napi_value IntlAddon::NumberFormatConstructor(napi_env env, napi_callback_info i
GetNumberOptionValues
(
env
,
argv
[
1
],
map
);
}
std
::
unique_ptr
<
IntlAddon
>
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
obj
==
nullptr
)
{
std
::
unique_ptr
<
IntlAddon
>
obj
=
nullptr
;
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
!
obj
)
{
HiLog
::
Error
(
LABEL
,
"Create IntlAddon failed"
);
return
nullptr
;
}
...
...
@@ -811,7 +815,7 @@ napi_value IntlAddon::GetLanguage(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -836,7 +840,7 @@ napi_value IntlAddon::GetScript(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -861,7 +865,7 @@ napi_value IntlAddon::GetRegion(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -886,7 +890,7 @@ napi_value IntlAddon::GetBaseName(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -911,7 +915,7 @@ napi_value IntlAddon::GetCalendar(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -936,7 +940,7 @@ napi_value IntlAddon::GetCollation(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -961,7 +965,7 @@ napi_value IntlAddon::GetHourCycle(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -986,7 +990,7 @@ napi_value IntlAddon::GetNumberingSystem(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -1011,7 +1015,7 @@ napi_value IntlAddon::GetNumeric(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -1036,7 +1040,7 @@ napi_value IntlAddon::GetCaseFirst(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -1060,7 +1064,7 @@ napi_value IntlAddon::ToString(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -1085,7 +1089,7 @@ napi_value IntlAddon::Maximize(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -1122,7 +1126,7 @@ napi_value IntlAddon::Minimize(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
locale_
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
...
...
@@ -1206,7 +1210,7 @@ napi_value IntlAddon::GetRelativeTimeResolvedOptions(napi_env env, napi_callback
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
relativetimefmt_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
relativetimefmt_
)
{
HiLog
::
Error
(
LABEL
,
"Get RelativeTimeFormat object failed"
);
return
nullptr
;
}
...
...
@@ -1231,7 +1235,7 @@ napi_value IntlAddon::GetDateTimeResolvedOptions(napi_env env, napi_callback_inf
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
datefmt_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
datefmt_
)
{
HiLog
::
Error
(
LABEL
,
"Get DateTimeFormat object failed"
);
return
nullptr
;
}
...
...
@@ -1272,7 +1276,7 @@ napi_value IntlAddon::GetNumberResolvedOptions(napi_env env, napi_callback_info
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
numberfmt_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
numberfmt_
)
{
HiLog
::
Error
(
LABEL
,
"Get NumberFormat object failed"
);
return
nullptr
;
}
...
...
@@ -1313,7 +1317,7 @@ napi_value IntlAddon::FormatNumber(napi_env env, napi_callback_info info)
napi_get_value_double
(
env
,
argv
[
0
],
&
number
);
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
numberfmt_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
numberfmt_
)
{
HiLog
::
Error
(
LABEL
,
"Get NumberFormat object failed"
);
return
nullptr
;
}
...
...
@@ -1508,8 +1512,9 @@ napi_value IntlAddon::CollatorConstructor(napi_env env, napi_callback_info info)
GetCollatorOptionValue
(
env
,
argv
[
1
],
map
);
}
std
::
unique_ptr
<
IntlAddon
>
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
obj
==
nullptr
)
{
std
::
unique_ptr
<
IntlAddon
>
obj
=
nullptr
;
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
!
obj
)
{
HiLog
::
Error
(
LABEL
,
"Create IntlAddon failed"
);
return
nullptr
;
}
...
...
@@ -1586,7 +1591,7 @@ napi_value IntlAddon::FormatRelativeTime(napi_env env, napi_callback_info info)
}
IntlAddon
*
obj
=
nullptr
;
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
relativetimefmt_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
relativetimefmt_
)
{
HiLog
::
Error
(
LABEL
,
"Get RelativeTimeFormat object failed"
);
return
nullptr
;
}
...
...
@@ -1659,7 +1664,7 @@ napi_value IntlAddon::FormatToParts(napi_env env, napi_callback_info info)
}
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
relativetimefmt_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
relativetimefmt_
)
{
HiLog
::
Error
(
LABEL
,
"Get RelativeTimeFormat object failed"
);
return
nullptr
;
}
...
...
@@ -1695,12 +1700,12 @@ napi_value IntlAddon::CompareString(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
collator_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
collator_
)
{
HiLog
::
Error
(
LABEL
,
"Get Collator object failed"
);
return
nullptr
;
}
int32_
t
compareResult
=
obj
->
collator_
->
Compare
(
first
.
data
(),
second
.
data
());
CompareResul
t
compareResult
=
obj
->
collator_
->
Compare
(
first
.
data
(),
second
.
data
());
napi_value
result
=
nullptr
;
status
=
napi_create_int32
(
env
,
compareResult
,
&
result
);
if
(
status
!=
napi_ok
)
{
...
...
@@ -1721,7 +1726,7 @@ napi_value IntlAddon::GetCollatorResolvedOptions(napi_env env, napi_callback_inf
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
collator_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
collator_
)
{
HiLog
::
Error
(
LABEL
,
"Get Collator object failed"
);
return
nullptr
;
}
...
...
@@ -1887,8 +1892,9 @@ napi_value IntlAddon::PluralRulesConstructor(napi_env env, napi_callback_info in
if
(
argv
[
1
]
!=
nullptr
)
{
GetPluralRulesOptionValues
(
env
,
argv
[
1
],
map
);
}
std
::
unique_ptr
<
IntlAddon
>
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
obj
==
nullptr
)
{
std
::
unique_ptr
<
IntlAddon
>
obj
=
nullptr
;
obj
=
std
::
make_unique
<
IntlAddon
>
();
if
(
!
obj
)
{
HiLog
::
Error
(
LABEL
,
"Create IntlAddon failed"
);
return
nullptr
;
}
...
...
@@ -1944,7 +1950,7 @@ napi_value IntlAddon::Select(napi_env env, napi_callback_info info)
IntlAddon
*
obj
=
nullptr
;
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
pluralrules_
==
nullptr
)
{
if
(
status
!=
napi_ok
||
!
obj
||
!
obj
->
pluralrules_
)
{
HiLog
::
Error
(
LABEL
,
"Get PluralRules object failed"
);
return
nullptr
;
}
...
...
interfaces/native/innerkits/i18n/include/locale_util.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -25,7 +25,7 @@ class LocaleUtil {
public:
static
bool
IsRTL
(
const
std
::
string
&
locale
);
}
}
// I18n
}
// Global
}
// OHOS
}
//
namespace
I18n
}
//
namespace
Global
}
//
namespace
OHOS
#endif
interfaces/native/innerkits/preferred_language/include/preferred_language.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -47,7 +47,7 @@ private:
static
constexpr
int
CONFIG_LEN
=
128
;
static
constexpr
uint32_t
LANGUAGE_LEN
=
2
;
};
}
}
}
}
// namespace I18n
}
// namespace Global
}
// namespace OHOS
#endif
\ No newline at end of file
interfaces/native/innerkits/zone/include/zone_util.h
浏览文件 @
555f250d
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
...
...
@@ -101,7 +101,7 @@ private:
static
void
GetString
(
icu
::
StringEnumeration
*
strEnum
,
std
::
string
&
ret
);
static
bool
Init
();
};
}
// I18n
}
// Global
}
// OHOS
}
//
namespace
I18n
}
//
namespace
Global
}
//
namespace
OHOS
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录