Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
da3a228a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
da3a228a
编写于
11月 02, 2009
作者:
M
Manfred Stienstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make ActiveSupport::Chars#limit run on Ruby 1.9.
上级
62a02289
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
29 deletion
+32
-29
activesupport/lib/active_support/multibyte/chars.rb
activesupport/lib/active_support/multibyte/chars.rb
+5
-0
activesupport/test/multibyte_chars_test.rb
activesupport/test/multibyte_chars_test.rb
+27
-29
未找到文件。
activesupport/lib/active_support/multibyte/chars.rb
浏览文件 @
da3a228a
...
...
@@ -665,6 +665,11 @@ def tidy_bytes(string)
def
translate_offset
(
byte_offset
)
#:nodoc:
return
nil
if
byte_offset
.
nil?
return
0
if
@wrapped_string
==
''
if
@wrapped_string
.
respond_to?
(
:force_encoding
)
@wrapped_string
=
@wrapped_string
.
dup
.
force_encoding
(
Encoding
::
ASCII_8BIT
)
end
begin
@wrapped_string
[
0
...
byte_offset
].
unpack
(
'U*'
).
length
rescue
ArgumentError
=>
e
...
...
activesupport/test/multibyte_chars_test.rb
浏览文件 @
da3a228a
...
...
@@ -100,15 +100,14 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
def
setup
@chars
=
UNICODE_STRING
.
dup
.
mb_chars
# NEWLINE, SPACE, EM SPACE
@whitespace
=
"
\n
#{
[
32
,
8195
].
pack
(
'U*'
)
}
"
# Ruby 1.9 doesn't recognize EM SPACE as whitespace!
if
@whitespace
.
respond_to?
(
:force_encoding
)
@whitespace
.
slice!
(
2
)
@whitespace
.
force_encoding
(
Encoding
::
UTF_8
)
if
RUBY_VERSION
<
'1.9'
# Multibyte support all kinds of whitespace (ie. NEWLINE, SPACE, EM SPACE)
@whitespace
=
"
\n\t
#{
[
32
,
8195
].
pack
(
'U*'
)
}
"
else
# Ruby 1.9 only supports basic whitespace
@whitespace
=
"
\n\t
"
.
force_encoding
(
Encoding
::
UTF_8
)
end
@byte_order_mark
=
[
65279
].
pack
(
'U'
)
end
...
...
@@ -497,28 +496,27 @@ def test_capitalize_should_be_unicode_aware
end
def
test_limit_should_not_break_on_blank_strings
chars
=
''
.
mb_chars
assert_equal
''
,
chars
.
limit
(
0
)
assert_equal
''
,
chars
.
limit
(
1
)
example
=
chars
(
''
)
assert_equal
example
,
example
.
limit
(
0
)
assert_equal
example
,
example
.
limit
(
1
)
end
def
test_limit_should_work_on_a_multibyte_string
chars
=
UNICODE_STRING
.
mb_chars
example
=
chars
(
UNICODE_STRING
)
bytesize
=
UNICODE_STRING
.
respond_to?
(
:bytesize
)
?
UNICODE_STRING
.
bytesize
:
UNICODE_STRING
.
size
assert_equal
UNICODE_STRING
,
chars
.
limit
(
UNICODE_STRING
.
length
)
assert_equal
''
,
chars
.
limit
(
0
)
assert_equal
''
,
chars
.
limit
(
1
)
assert_equal
'こ'
,
chars
.
limit
(
3
)
assert_equal
'こに'
,
chars
.
limit
(
6
)
assert_equal
'こに'
,
chars
.
limit
(
8
)
assert_equal
'こにち'
,
chars
.
limit
(
9
)
assert_equal
'こにちわ'
,
chars
.
limit
(
50
)
assert_equal
UNICODE_STRING
,
example
.
limit
(
bytesize
)
assert_equal
''
,
example
.
limit
(
0
)
assert_equal
''
,
example
.
limit
(
1
)
assert_equal
'こ'
,
example
.
limit
(
3
)
assert_equal
'こに'
,
example
.
limit
(
6
)
assert_equal
'こに'
,
example
.
limit
(
8
)
assert_equal
'こにち'
,
example
.
limit
(
9
)
assert_equal
'こにちわ'
,
example
.
limit
(
50
)
end
def
test_limit_should_work_on_an_ascii_string
ascii
=
ASCII_STRING
.
mb_chars
ascii
=
chars
(
ASCII_STRING
)
assert_equal
ASCII_STRING
,
ascii
.
limit
(
ASCII_STRING
.
length
)
assert_equal
''
,
ascii
.
limit
(
0
)
assert_equal
'o'
,
ascii
.
limit
(
1
)
...
...
@@ -528,12 +526,12 @@ def test_limit_should_work_on_an_ascii_string
end
def
test_limit_should_keep_under_the_specified_byte_limit
chars
=
UNICODE_STRING
.
mb_chars
example
=
chars
(
UNICODE_STRING
)
(
1
..
UNICODE_STRING
.
length
).
each
do
|
limit
|
assert
chars
.
limit
(
limit
).
to_s
.
length
<=
limit
assert
example
.
limit
(
limit
).
to_s
.
length
<=
limit
end
end
def
test_composition_exclusion_is_set_up_properly
# Normalization of DEVANAGARI LETTER QA breaks when composition exclusion isn't used correctly
qa
=
[
0x915
,
0x93c
].
pack
(
'U*'
)
...
...
@@ -647,9 +645,9 @@ def string_from_classes(classes)
class
MultibyteInternalsTest
<
ActiveSupport
::
TestCase
include
MultibyteTestHelpers
test
"Chars translates a character offset to a byte offset"
do
chars
=
"Puisque c'était son erreur, il m'a aidé"
.
mb_chars
example
=
chars
(
"Puisque c'était son erreur, il m'a aidé"
)
[
[
0
,
0
],
[
3
,
3
],
...
...
@@ -657,7 +655,7 @@ class MultibyteInternalsTest < ActiveSupport::TestCase
[
14
,
13
],
[
41
,
39
]
].
each
do
|
byte_offset
,
character_offset
|
assert_equal
character_offset
,
chars
.
send
(
:translate_offset
,
byte_offset
),
assert_equal
character_offset
,
example
.
send
(
:translate_offset
,
byte_offset
),
"Expected byte offset
#{
byte_offset
}
to translate to
#{
character_offset
}
"
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录