Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8878

Show
Ignore:
Timestamp:
02/16/08 00:02:30 (2 years ago)
Author:
nzkoz
Message:

Add String#squish and String#squish! to remove consecutive chunks of whitespace. Closes #11123 [jordi, Henrik N]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r8877 r8878  
    11*SVN* 
     2 
     3* Add String#squish and String#squish! to remove consecutive chunks of whitespace.  #11123 [jordi, Henrik N] 
    24 
    35* Serialize BigDecimals as Floats when using to_yaml. #8746 [ernesto.jimenez] 
  • trunk/activesupport/lib/active_support/core_ext/string.rb

    r8397 r8878  
    66require 'active_support/core_ext/string/unicode' 
    77require 'active_support/core_ext/string/xchar' 
     8require 'active_support/core_ext/string/filters' 
    89 
    910class String #:nodoc: 
    1011  include ActiveSupport::CoreExtensions::String::Access 
    1112  include ActiveSupport::CoreExtensions::String::Conversions 
     13  include ActiveSupport::CoreExtensions::String::Filters 
    1214  include ActiveSupport::CoreExtensions::String::Inflections 
    1315  if RUBY_VERSION < '1.9' 
  • trunk/activesupport/test/core_ext/string_ext_test.rb

    r8789 r8878  
    169169  end 
    170170 
     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    # But doesn't modify the original string: 
     180    assert_not_equal original, expected 
     181 
     182    # Make sure squish! returns what we expect: 
     183    assert_equal original.squish!, expected 
     184    # And changes the original string: 
     185    assert_equal original, expected 
     186  end 
     187 
    171188  if RUBY_VERSION < '1.9' 
    172189    def test_each_char_with_utf8_string_when_kcode_is_utf8