This project is archived and is in readonly mode.
Make AS::Multibyte::Chars#slice! behave more like String#slice!
Reported by George Ogata | October 21st, 2008 @ 01:07 AM | in 2.x
Currently, doing a slice! on a Multibyte::Chars modifies the string to become equal to the return value:
>> s = 'こんにちは'.mb_chars
=> #<ActiveSupport::Multibyte::Chars:0x24c4ddc @wrapped_string="こんにちは">
>> s.slice!(2..3)
=> #<ActiveSupport::Multibyte::Chars:0x24c4ddc @wrapped_string="にち">
>> s
=> #<ActiveSupport::Multibyte::Chars:0x24c4ddc @wrapped_string="にち">
As opposed to String#slice!, which removes the slice from the string:
>> s = 'abcde'
=> "abcde"
>> s.slice!(2..3)
=> "cd"
>> s
=> "abe"
This patch does what's needed:
>> s = 'こんにちは'.mb_chars
=> #<ActiveSupport::Multibyte::Chars:0x24cc960 @wrapped_string="こんにちは">
>> s.slice!(2..3)
=> #<ActiveSupport::Multibyte::Chars:0x24caf84 @wrapped_string="にち">
>> s
=> #<ActiveSupport::Multibyte::Chars:0x24cc960 @wrapped_string="こんは">
Comments and changes to this ticket
-
Manfred Stienstra December 30th, 2008 @ 12:24 PM
- Assigned user set to Manfred Stienstra
-
Manfred Stienstra December 30th, 2008 @ 01:28 PM
Patch looks great, thanks. I've modified it slightly to put more information in the commit message.
-
George Ogata January 2nd, 2009 @ 02:31 PM
Cool, thanks. Does this mean it'll be merged in?
There are a few other methods that differ from String. Specifically, some of those bang methods should return nil if no modification occurred. I can patch those too if this gets the green light.
George.
-
Manfred Stienstra January 2nd, 2009 @ 02:55 PM
Let's hope so (: Unfortunately I can't push to the main repository myself, but I will make sure someone commits it.
I was thinking about getting the String specs from RubySpec and using those in the Multibyte tests to make sure it works as much like String as possible.
-
Pratik March 7th, 2009 @ 08:27 PM
- Assigned user changed from Manfred Stienstra to Pratik
Hey Manfred,
Is this ready to be committed ?
Thanks.
-
Repository March 7th, 2009 @ 10:41 PM
- State changed from new to resolved
(from [74387884819e8b6e16c3f67388610b8d1192cb4d]) Make Chars#slice! behave more like String#slice! [#1243 state:resolved]
- Chars#slice! now returns the slice instead of itself
- Chars#slice! now removes the slice from itself
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 1243 Make AS::Multibyte::Chars#slice! behave more like String#slice! (from [74387884819e8b6e16c3f67388610b8d1192cb4d]) Make Ch...