Ticket #11123: add_squish_method_to_string.diff
| File add_squish_method_to_string.diff, 2.8 kB (added by jordi, 8 months ago) |
|---|
-
activesupport/test/core_ext/string_ext_test.rb
old new 168 168 assert !s.end_with?('el') 169 169 end 170 170 171 def test_string_squish 172 original = %{ A string with tabs(\t\t), newlines(\n\n), and 173 many spaces( ). } 174 175 expected = "A string with tabs( ), newlines( ), and many spaces( )." 176 177 # Make sure squish returns what we expect: 178 assert_equal original.squish, expected 179 180 # Make sure squish! returns what we expect: 181 assert_equal original.squish!, expected 182 183 # Make sure squish! changes the original to what we expect: 184 assert_equal original, expected 185 end 186 171 187 if RUBY_VERSION < '1.9' 172 188 def test_each_char_with_utf8_string_when_kcode_is_utf8 173 189 old_kcode, $KCODE = $KCODE, 'UTF8' -
activesupport/lib/active_support/core_ext/string.rb
old new 5 5 require 'active_support/core_ext/string/iterators' unless 'test'.respond_to?(:each_char) 6 6 require 'active_support/core_ext/string/unicode' 7 7 require 'active_support/core_ext/string/xchar' 8 require 'active_support/core_ext/string/filters' 8 9 9 10 class String #:nodoc: 10 11 include ActiveSupport::CoreExtensions::String::Access 11 12 include ActiveSupport::CoreExtensions::String::Conversions 13 include ActiveSupport::CoreExtensions::String::Filters 12 14 include ActiveSupport::CoreExtensions::String::Inflections 13 15 if RUBY_VERSION < '1.9' 14 16 include ActiveSupport::CoreExtensions::String::StartsEndsWith -
activesupport/lib/active_support/core_ext/string/filters.rb
old new 1 module ActiveSupport #:nodoc: 2 module CoreExtensions #:nodoc: 3 module String #:nodoc: 4 module Filters 5 # Returns the string, first removing all whitespace on both ends of 6 # the string, and then changing remaining consecutive whitespace 7 # groups into one space each. 8 # 9 # Examples: 10 # %{ Multi-line 11 # string }.squish # => "Multi-line string" 12 # " foo bar \n \t boo".squish # => "foo bar boo" 13 def squish 14 dup.squish! 15 end 16 17 # Performs a destructive squish. See String.squish. 18 def squish! 19 strip! 20 gsub!(/\s+/, ' ') 21 self 22 end 23 end 24 end 25 end 26 end