Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
51648a6f
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,发现更多精彩内容 >>
提交
51648a6f
编写于
1月 05, 2012
作者:
N
Norman Clarke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove multibyte utils
This is neither a public API, nor used internally, so let's remove it.
上级
9ea34ad3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
1 addition
and
140 deletion
+1
-140
activesupport/lib/active_support/multibyte.rb
activesupport/lib/active_support/multibyte.rb
+1
-20
activesupport/lib/active_support/multibyte/utils.rb
activesupport/lib/active_support/multibyte/utils.rb
+0
-27
activesupport/test/multibyte_utils_test.rb
activesupport/test/multibyte_utils_test.rb
+0
-93
未找到文件。
activesupport/lib/active_support/multibyte.rb
浏览文件 @
51648a6f
...
...
@@ -21,24 +21,5 @@ def self.proxy_class=(klass)
def
self
.
proxy_class
@proxy_class
||=
ActiveSupport
::
Multibyte
::
Chars
end
# Regular expressions that describe valid byte sequences for a character
VALID_CHARACTER
=
{
# Borrowed from the Kconv library by Shinji KONO - (also as seen on the W3C site)
'UTF-8'
=>
/\A(?:
[\x00-\x7f] |
[\xc2-\xdf] [\x80-\xbf] |
\xe0 [\xa0-\xbf] [\x80-\xbf] |
[\xe1-\xef] [\x80-\xbf] [\x80-\xbf] |
\xf0 [\x90-\xbf] [\x80-\xbf] [\x80-\xbf] |
[\xf1-\xf3] [\x80-\xbf] [\x80-\xbf] [\x80-\xbf] |
\xf4 [\x80-\x8f] [\x80-\xbf] [\x80-\xbf])\z /xn
,
# Quick check for valid Shift-JIS characters, disregards the odd-even pairing
'Shift_JIS'
=>
/\A(?:
[\x00-\x7e\xa1-\xdf] |
[\x81-\x9f\xe0-\xef] [\x40-\x7e\x80-\x9e\x9f-\xfc])\z /xn
}
end
end
require
'active_support/multibyte/utils'
\ No newline at end of file
end
\ No newline at end of file
activesupport/lib/active_support/multibyte/utils.rb
已删除
100644 → 0
浏览文件 @
9ea34ad3
# encoding: utf-8
module
ActiveSupport
#:nodoc:
module
Multibyte
#:nodoc:
# Returns a regular expression that matches valid characters in the current encoding
def
self
.
valid_character
VALID_CHARACTER
[
Encoding
.
default_external
.
to_s
]
end
# Verifies the encoding of a string
def
self
.
verify
(
string
)
string
.
valid_encoding?
end
# Verifies the encoding of the string and raises an exception when it's not valid
def
self
.
verify!
(
string
)
raise
EncodingError
.
new
(
"Found characters with invalid encoding"
)
unless
verify
(
string
)
end
# Removes all invalid characters from the string.
#
# Note: this method is a no-op in Ruby 1.9
def
self
.
clean
(
string
)
string
end
end
end
activesupport/test/multibyte_utils_test.rb
已删除
100644 → 0
浏览文件 @
9ea34ad3
# encoding: utf-8
require
'abstract_unit'
require
'multibyte_test_helpers'
class
MultibyteUtilsTest
<
ActiveSupport
::
TestCase
include
MultibyteTestHelpers
test
"valid_character returns an expression for the current encoding"
do
with_encoding
(
'None'
)
do
assert_nil
ActiveSupport
::
Multibyte
.
valid_character
end
with_encoding
(
'UTF8'
)
do
assert_equal
ActiveSupport
::
Multibyte
::
VALID_CHARACTER
[
'UTF-8'
],
ActiveSupport
::
Multibyte
.
valid_character
end
with_encoding
(
'SJIS'
)
do
assert_equal
ActiveSupport
::
Multibyte
::
VALID_CHARACTER
[
'Shift_JIS'
],
ActiveSupport
::
Multibyte
.
valid_character
end
end
test
"verify verifies ASCII strings are properly encoded"
do
with_encoding
(
'None'
)
do
examples
.
each
do
|
example
|
assert
ActiveSupport
::
Multibyte
.
verify
(
example
)
end
end
end
test
"verify verifies UTF-8 strings are properly encoded"
do
with_encoding
(
'UTF8'
)
do
assert
ActiveSupport
::
Multibyte
.
verify
(
example
(
'valid UTF-8'
))
assert
!
ActiveSupport
::
Multibyte
.
verify
(
example
(
'invalid UTF-8'
))
end
end
test
"verify verifies Shift-JIS strings are properly encoded"
do
with_encoding
(
'SJIS'
)
do
assert
ActiveSupport
::
Multibyte
.
verify
(
example
(
'valid Shift-JIS'
))
assert
!
ActiveSupport
::
Multibyte
.
verify
(
example
(
'invalid Shift-JIS'
))
end
end
test
"verify! raises an exception when it finds an invalid character"
do
with_encoding
(
'UTF8'
)
do
assert_raises
(
ActiveSupport
::
Multibyte
::
EncodingError
)
do
ActiveSupport
::
Multibyte
.
verify!
(
example
(
'invalid UTF-8'
))
end
end
end
test
"verify! doesn't raise an exception when the encoding is valid"
do
with_encoding
(
'UTF8'
)
do
assert_nothing_raised
do
ActiveSupport
::
Multibyte
.
verify!
(
example
(
'valid UTF-8'
))
end
end
end
test
"clean is a no-op"
do
with_encoding
(
'UTF8'
)
do
assert_equal
example
(
'invalid Shift-JIS'
),
ActiveSupport
::
Multibyte
.
clean
(
example
(
'invalid Shift-JIS'
))
end
end
private
STRINGS
=
{
'valid ASCII'
=>
[
65
,
83
,
67
,
73
,
73
].
pack
(
'C*'
),
'invalid ASCII'
=>
[
128
].
pack
(
'C*'
),
'valid UTF-8'
=>
[
227
,
129
,
147
,
227
,
129
,
171
,
227
,
129
,
161
,
227
,
130
,
143
].
pack
(
'C*'
),
'invalid UTF-8'
=>
[
184
,
158
,
8
,
136
,
165
].
pack
(
'C*'
),
'valid Shift-JIS'
=>
[
131
,
122
,
129
,
91
,
131
,
128
].
pack
(
'C*'
),
'invalid Shift-JIS'
=>
[
184
,
158
,
8
,
0
,
255
,
136
,
165
].
pack
(
'C*'
)
}
def
example
(
key
)
STRINGS
[
key
].
force_encoding
(
Encoding
.
default_external
)
end
def
examples
STRINGS
.
values
.
map
{
|
s
|
s
.
force_encoding
(
Encoding
.
default_external
)
}
end
KCODE_TO_ENCODING
=
Hash
.
new
(
Encoding
::
BINARY
).
update
(
'UTF8'
=>
Encoding
::
UTF_8
,
'SJIS'
=>
Encoding
::
Shift_JIS
)
def
with_encoding
(
enc
)
before
=
Encoding
.
default_external
silence_warnings
{
Encoding
.
default_external
=
KCODE_TO_ENCODING
[
enc
]
}
yield
silence_warnings
{
Encoding
.
default_external
=
before
}
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录