Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e926f38f
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e926f38f
编写于
7月 24, 2009
作者:
M
martin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6639458: Improvements to Surrogate.java
Summary: Optimize Surrogate.java Reviewed-by: sherman
上级
621f22a7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
48 deletion
+44
-48
src/share/classes/sun/nio/cs/Surrogate.java
src/share/classes/sun/nio/cs/Surrogate.java
+44
-48
未找到文件。
src/share/classes/sun/nio/cs/Surrogate.java
浏览文件 @
e926f38f
...
...
@@ -30,7 +30,6 @@ import java.nio.charset.CoderResult;
import
java.nio.charset.MalformedInputException
;
import
java.nio.charset.UnmappableCharacterException
;
/**
* Utility class for dealing with surrogates.
*
...
...
@@ -41,19 +40,15 @@ public class Surrogate {
private
Surrogate
()
{
}
// UTF-16 surrogate-character ranges
//
public
static
final
char
MIN_HIGH
=
'\
uD800
'
;
public
static
final
char
MAX_HIGH
=
'\
uDBFF
'
;
public
static
final
char
MIN_LOW
=
'\
uDC00
'
;
public
static
final
char
MAX_LOW
=
'\
uDFFF
'
;
public
static
final
char
MIN
=
MIN_HIGH
;
public
static
final
char
MAX
=
MAX_LOW
;
// Range of UCS-4 values that need surrogates in UTF-16
//
public
static
final
int
UCS4_MIN
=
0x10000
;
public
static
final
int
UCS4_MAX
=
(
1
<<
20
)
+
UCS4_MIN
-
1
;
// TODO: Deprecate/remove the following redundant definitions
public
static
final
char
MIN_HIGH
=
Character
.
MIN_HIGH_SURROGATE
;
public
static
final
char
MAX_HIGH
=
Character
.
MAX_HIGH_SURROGATE
;
public
static
final
char
MIN_LOW
=
Character
.
MIN_LOW_SURROGATE
;
public
static
final
char
MAX_LOW
=
Character
.
MAX_LOW_SURROGATE
;
public
static
final
char
MIN
=
Character
.
MIN_SURROGATE
;
public
static
final
char
MAX
=
Character
.
MAX_SURROGATE
;
public
static
final
int
UCS4_MIN
=
Character
.
MIN_SUPPLEMENTARY_CODE_POINT
;
public
static
final
int
UCS4_MAX
=
Character
.
MAX_CODE_POINT
;
/**
* Tells whether or not the given UTF-16 value is a high surrogate.
...
...
@@ -76,36 +71,46 @@ public class Surrogate {
return
(
MIN
<=
c
)
&&
(
c
<=
MAX
);
}
/**
* Tells whether or not the given UCS-4 character is in the Basic
* Multilingual Plane, and can be represented using a single char.
*/
public
static
boolean
isBMP
(
int
uc
)
{
return
(
int
)
(
char
)
uc
==
uc
;
}
/**
* Tells whether or not the given UCS-4 character must be represented as a
* surrogate pair in UTF-16.
*/
public
static
boolean
neededFor
(
int
uc
)
{
return
(
uc
>=
UCS4_MIN
)
&&
(
uc
<=
UCS4_MAX
);
return
Character
.
isSupplementaryCodePoint
(
uc
);
}
/**
* Returns the high UTF-16 surrogate for the given UCS-4 character.
*/
public
static
char
high
(
int
uc
)
{
assert
neededFor
(
uc
);
return
(
char
)(
0xd800
|
(((
uc
-
UCS4_MIN
)
>>
10
)
&
0x3ff
));
assert
Character
.
isSupplementaryCodePoint
(
uc
);
return
(
char
)((
uc
>>
10
)
+
(
Character
.
MIN_HIGH_SURROGATE
-
(
Character
.
MIN_SUPPLEMENTARY_CODE_POINT
>>
10
)));
}
/**
* Returns the low UTF-16 surrogate for the given UCS-4 character.
*/
public
static
char
low
(
int
uc
)
{
assert
neededFor
(
uc
);
return
(
char
)(
0xdc00
|
((
uc
-
UCS4_MIN
)
&
0x3ff
)
);
assert
Character
.
isSupplementaryCodePoint
(
uc
);
return
(
char
)(
(
uc
&
0x3ff
)
+
Character
.
MIN_LOW_SURROGATE
);
}
/**
* Converts the given surrogate pair into a 32-bit UCS-4 character.
*/
public
static
int
toUCS4
(
char
c
,
char
d
)
{
assert
isHigh
(
c
)
&&
isLow
(
d
);
return
(((
c
&
0x3ff
)
<<
10
)
|
(
d
&
0x3ff
))
+
0x10000
;
assert
Character
.
isHighSurrogate
(
c
)
&&
Character
.
isLowSurrogate
(
d
);
return
Character
.
toCodePoint
(
c
,
d
)
;
}
/**
...
...
@@ -178,14 +183,14 @@ public class Surrogate {
* object
*/
public
int
parse
(
char
c
,
CharBuffer
in
)
{
if
(
Surrogate
.
isHigh
(
c
))
{
if
(
Character
.
isHighSurrogate
(
c
))
{
if
(!
in
.
hasRemaining
())
{
error
=
CoderResult
.
UNDERFLOW
;
return
-
1
;
}
char
d
=
in
.
get
();
if
(
Surrogate
.
isLow
(
d
))
{
character
=
toUCS4
(
c
,
d
);
if
(
Character
.
isLowSurrogate
(
d
))
{
character
=
Character
.
toCodePoint
(
c
,
d
);
isPair
=
true
;
error
=
null
;
return
character
;
...
...
@@ -193,7 +198,7 @@ public class Surrogate {
error
=
CoderResult
.
malformedForLength
(
1
);
return
-
1
;
}
if
(
Surrogate
.
isLow
(
c
))
{
if
(
Character
.
isLowSurrogate
(
c
))
{
error
=
CoderResult
.
malformedForLength
(
1
);
return
-
1
;
}
...
...
@@ -220,14 +225,14 @@ public class Surrogate {
*/
public
int
parse
(
char
c
,
char
[]
ia
,
int
ip
,
int
il
)
{
assert
(
ia
[
ip
]
==
c
);
if
(
Surrogate
.
isHigh
(
c
))
{
if
(
Character
.
isHighSurrogate
(
c
))
{
if
(
il
-
ip
<
2
)
{
error
=
CoderResult
.
UNDERFLOW
;
return
-
1
;
}
char
d
=
ia
[
ip
+
1
];
if
(
Surrogate
.
isLow
(
d
))
{
character
=
toUCS4
(
c
,
d
);
if
(
Character
.
isLowSurrogate
(
d
))
{
character
=
Character
.
toCodePoint
(
c
,
d
);
isPair
=
true
;
error
=
null
;
return
character
;
...
...
@@ -235,7 +240,7 @@ public class Surrogate {
error
=
CoderResult
.
malformedForLength
(
1
);
return
-
1
;
}
if
(
Surrogate
.
isLow
(
c
))
{
if
(
Character
.
isLowSurrogate
(
c
))
{
error
=
CoderResult
.
malformedForLength
(
1
);
return
-
1
;
}
...
...
@@ -282,7 +287,7 @@ public class Surrogate {
* error() will return a descriptive result object
*/
public
int
generate
(
int
uc
,
int
len
,
CharBuffer
dst
)
{
if
(
uc
<=
0xffff
)
{
if
(
Surrogate
.
isBMP
(
uc
)
)
{
if
(
Surrogate
.
is
(
uc
))
{
error
=
CoderResult
.
malformedForLength
(
len
);
return
-
1
;
...
...
@@ -294,12 +299,7 @@ public class Surrogate {
dst
.
put
((
char
)
uc
);
error
=
null
;
return
1
;
}
if
(
uc
<
Surrogate
.
UCS4_MIN
)
{
error
=
CoderResult
.
malformedForLength
(
len
);
return
-
1
;
}
if
(
uc
<=
Surrogate
.
UCS4_MAX
)
{
}
else
if
(
Character
.
isSupplementaryCodePoint
(
uc
))
{
if
(
dst
.
remaining
()
<
2
)
{
error
=
CoderResult
.
OVERFLOW
;
return
-
1
;
...
...
@@ -308,9 +308,10 @@ public class Surrogate {
dst
.
put
(
Surrogate
.
low
(
uc
));
error
=
null
;
return
2
;
}
else
{
error
=
CoderResult
.
unmappableForLength
(
len
);
return
-
1
;
}
error
=
CoderResult
.
unmappableForLength
(
len
);
return
-
1
;
}
/**
...
...
@@ -330,7 +331,7 @@ public class Surrogate {
* error() will return a descriptive result object
*/
public
int
generate
(
int
uc
,
int
len
,
char
[]
da
,
int
dp
,
int
dl
)
{
if
(
uc
<=
0xffff
)
{
if
(
Surrogate
.
isBMP
(
uc
)
)
{
if
(
Surrogate
.
is
(
uc
))
{
error
=
CoderResult
.
malformedForLength
(
len
);
return
-
1
;
...
...
@@ -342,12 +343,7 @@ public class Surrogate {
da
[
dp
]
=
(
char
)
uc
;
error
=
null
;
return
1
;
}
if
(
uc
<
Surrogate
.
UCS4_MIN
)
{
error
=
CoderResult
.
malformedForLength
(
len
);
return
-
1
;
}
if
(
uc
<=
Surrogate
.
UCS4_MAX
)
{
}
else
if
(
Character
.
isSupplementaryCodePoint
(
uc
))
{
if
(
dl
-
dp
<
2
)
{
error
=
CoderResult
.
OVERFLOW
;
return
-
1
;
...
...
@@ -356,11 +352,11 @@ public class Surrogate {
da
[
dp
+
1
]
=
Surrogate
.
low
(
uc
);
error
=
null
;
return
2
;
}
else
{
error
=
CoderResult
.
unmappableForLength
(
len
);
return
-
1
;
}
error
=
CoderResult
.
unmappableForLength
(
len
);
return
-
1
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录