mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Multibyte: String#slice supports regexp argument. Closes #9646.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7910 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
660a696a3f
commit
656a20a4d3
3 changed files with 9 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Multibyte: String#slice supports regexp argument. #9646 [yob]
|
||||
|
||||
* object.duplicable? returns true if object.dup is safe. False for nil, true, false, symbols, and numbers; true otherwise. #9333 [sur]
|
||||
|
||||
* Time, Date and DateTime #advance accept :weeks option. #9866 [Geoff Buesing]
|
||||
|
|
|
@ -255,6 +255,8 @@ module ActiveSupport::Multibyte::Handlers #:nodoc:
|
|||
elsif args[0].kind_of? Range
|
||||
cps = u_unpack(str).slice(*args)
|
||||
cps.nil? ? nil : cps.pack('U*')
|
||||
elsif args[0].kind_of? Regexp
|
||||
str.slice(*args)
|
||||
elsif args.size == 1 && args[0].kind_of?(Numeric)
|
||||
u_unpack(str)[args[0]]
|
||||
else
|
||||
|
|
|
@ -160,6 +160,11 @@ module UTF8HandlingTest
|
|||
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 "ffi бла", @handler.slice(@string, /ffi бла/u), "Slicing on Regexps should be supported"
|
||||
assert_equal "ffi бла", @handler.slice(@string, /ffi \w\wа/u), "Slicing on Regexps should be supported"
|
||||
assert_equal nil, @handler.slice(@string, /unknown/u), "Slicing on Regexps with no match should return nil"
|
||||
assert_equal "ffi бла", @handler.slice(@string, /(ffi бла)/u,1), "Slicing on Regexps with a match group should be supported"
|
||||
assert_equal nil, @handler.slice(@string, /(ffi)/u,2), "Slicing with a Regexp and asking for an invalid match group should return nil"
|
||||
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) }
|
||||
assert_raise(TypeError, "With 2 args, should raise TypeError for non-Numeric or Regexp first argument") { @handler.slice(@string, 2..3, 1) }
|
||||
|
|
Loading…
Reference in a new issue