Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
30bf8a7c
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
30bf8a7c
编写于
2月 19, 2016
作者:
R
Raph Levien
提交者:
Android (Google) Code Review
2月 19, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge "Suppress linebreaks in emoji ZWJ sequences" into nyc-dev
上级
ea408fc1
d3f45892
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
1 deletion
+52
-1
libs/minikin/WordBreaker.cpp
libs/minikin/WordBreaker.cpp
+28
-1
tests/WordBreakerTests.cpp
tests/WordBreakerTests.cpp
+24
-0
未找到文件。
libs/minikin/WordBreaker.cpp
浏览文件 @
30bf8a7c
...
...
@@ -25,6 +25,7 @@
namespace
android
{
const
uint32_t
CHAR_SOFT_HYPHEN
=
0x00AD
;
const
uint16_t
CHAR_ZWJ
=
0x200D
;
void
WordBreaker
::
setLocale
(
const
icu
::
Locale
&
locale
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
...
...
@@ -62,6 +63,32 @@ enum ScanState {
SAW_COLON_SLASH_SLASH
,
};
/**
* Determine whether a line break at position i within the buffer buf is valid. This
* represents customization beyond the ICU behavior, because plain ICU provides some
* line break opportunities that we don't want.
**/
static
bool
isBreakValid
(
uint16_t
codeUnit
,
const
uint16_t
*
buf
,
size_t
bufEnd
,
size_t
i
)
{
if
(
codeUnit
==
CHAR_SOFT_HYPHEN
)
{
return
false
;
}
if
(
codeUnit
==
CHAR_ZWJ
)
{
// Possible emoji ZWJ sequence
uint32_t
next_codepoint
;
U16_NEXT
(
buf
,
i
,
bufEnd
,
next_codepoint
);
if
(
next_codepoint
==
0x2764
||
// HEAVY BLACK HEART
next_codepoint
==
0x1F466
||
// BOY
next_codepoint
==
0x1F467
||
// GIRL
next_codepoint
==
0x1F468
||
// MAN
next_codepoint
==
0x1F469
||
// WOMAN
next_codepoint
==
0x1F48B
||
// KISS MARK
next_codepoint
==
0x1F5E8
)
{
// LEFT SPEECH BUBBLE
return
false
;
}
}
return
true
;
}
// Chicago Manual of Style recommends breaking after these characters in URLs and email addresses
static
bool
breakAfter
(
uint16_t
c
)
{
return
c
==
':'
||
c
==
'='
||
c
==
'&'
;
...
...
@@ -149,7 +176,7 @@ ssize_t WordBreaker::next() {
result
=
mBreakIterator
->
next
();
}
}
while
(
result
!=
icu
::
BreakIterator
::
DONE
&&
(
size_t
)
result
!=
mTextSize
&&
mText
[
result
-
1
]
==
CHAR_SOFT_HYPHEN
);
&&
!
isBreakValid
(
mText
[
result
-
1
],
mText
,
mTextSize
,
result
)
);
mCurrent
=
(
ssize_t
)
result
;
return
mCurrent
;
}
...
...
tests/WordBreakerTests.cpp
浏览文件 @
30bf8a7c
...
...
@@ -67,6 +67,30 @@ TEST_F(WordBreakerTest, softHyphen) {
EXPECT_EQ
(
0
,
breaker
.
breakBadness
());
}
TEST_F
(
WordBreakerTest
,
zwjEmojiSequences
)
{
uint16_t
buf
[]
=
{
// man + zwj + heart + zwj + man
0xD83D
,
0xDC68
,
0x200D
,
0x2764
,
0x200D
,
0xD83D
,
0xDC68
,
// woman + zwj + heart + zwj + woman
0xD83D
,
0xDC69
,
0x200D
,
0x2764
,
0x200D
,
0xD83D
,
0xDC8B
,
0x200D
,
0xD83D
,
0xDC69
,
// eye + zwj + left speech bubble
0xD83D
,
0xDC41
,
0x200D
,
0xD83D
,
0xDDE8
,
};
WordBreaker
breaker
;
breaker
.
setLocale
(
icu
::
Locale
::
getEnglish
());
breaker
.
setText
(
buf
,
NELEM
(
buf
));
EXPECT_EQ
(
0
,
breaker
.
current
());
EXPECT_EQ
(
7
,
breaker
.
next
());
// after man + zwj + heart + zwj + man
EXPECT_EQ
(
0
,
breaker
.
wordStart
());
EXPECT_EQ
(
7
,
breaker
.
wordEnd
());
EXPECT_EQ
(
17
,
breaker
.
next
());
// after woman + zwj + heart + zwj + woman
EXPECT_EQ
(
7
,
breaker
.
wordStart
());
EXPECT_EQ
(
17
,
breaker
.
wordEnd
());
EXPECT_EQ
((
ssize_t
)
NELEM
(
buf
),
breaker
.
next
());
// end
EXPECT_EQ
(
17
,
breaker
.
wordStart
());
EXPECT_EQ
(
22
,
breaker
.
wordEnd
());
}
TEST_F
(
WordBreakerTest
,
punct
)
{
uint16_t
buf
[]
=
{
0x00A1
,
0x00A1
,
'h'
,
'e'
,
'l'
,
'l'
,
'o'
,
','
,
' '
,
'w'
,
'o'
,
'r'
,
'l'
,
'd'
,
'!'
,
'!'
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录