mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make String#chars slicing behaviour consistent with String. Closes #6387 [Manfred Stienstra]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5286 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
7870494673
commit
cb927c8774
3 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Make String#chars slicing behaviour consistent with String. Closes #6387 [Manfred Stienstra]
|
||||
|
||||
* Pull in latest multibye patch. Closes #6346 [Manfred Stienstra]
|
||||
|
||||
* Add ActiveSupport::Multibyte. Provides String#chars which lets you deal with strings as a sequence of chars, not of bytes. Closes #6242 [Julian Tarkhanov, Manfred Stienstra, Thijs van der Vossen & Jan Behrens]
|
||||
|
|
|
@ -162,10 +162,10 @@ module ActiveSupport::Multibyte::Handlers
|
|||
elsif args[0].kind_of? Range
|
||||
cps = u_unpack(str).slice(*args)
|
||||
cps.nil? ? nil : cps.pack('U*')
|
||||
elsif args[0].kind_of? Numeric
|
||||
elsif args.size == 1 && args[0].kind_of?(Numeric)
|
||||
u_unpack(str)[args[0]]
|
||||
else
|
||||
str.slice(*args)
|
||||
u_unpack(str).slice(*args).pack('U*')
|
||||
end
|
||||
end
|
||||
alias_method :[], :slice
|
||||
|
@ -434,4 +434,4 @@ module ActiveSupport::Multibyte::Handlers
|
|||
UCD = UnicodeDatabase.new
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -157,6 +157,8 @@ module UTF8HandlingTest
|
|||
assert_equal nil, @handler.slice('', -1..1), "Broken range should return nil"
|
||||
assert_equal '', @handler.slice('', 0..10), "Empty string should not break things"
|
||||
assert_equal "d Блå ffi", @handler.slice(@string, 3..9), "Unicode characters have to be returned"
|
||||
assert_equal "d Блå ffi", @handler.slice(@string, 3, 7), "Unicode characters have to be returned"
|
||||
assert_equal "A", @handler.slice(@string, 0, 1), "Slicing from an offset should return characters"
|
||||
assert_equal " Блå ffi ", @handler.slice(@string, 4..10), "Unicode characters have to be returned"
|
||||
assert_equal "", @handler.slice(@string, 7..6), "Range is empty, should return an empty string"
|
||||
assert_raise(ActiveSupport::Multibyte::Handlers::EncodingError) { @handler.slice(@bytestring, 2..3) }
|
||||
|
@ -266,4 +268,4 @@ class UTF8HandlingTestPure < Test::Unit::TestCase
|
|||
common_setup
|
||||
@handler = ::ActiveSupport::Multibyte::Handlers::UTF8Handler
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue