Change all calls to String#chars to String#mb_chars.

This commit is contained in:
Manfred Stienstra 2008-09-21 17:23:37 +02:00
parent 0211722088
commit 520c3f33c3
2 changed files with 15 additions and 15 deletions

View File

@ -11,7 +11,7 @@ module ActiveSupport #:nodoc:
# "hello".at(4) # => "o" # "hello".at(4) # => "o"
# "hello".at(10) # => nil # "hello".at(10) # => nil
def at(position) def at(position)
chars[position, 1].to_s mb_chars[position, 1].to_s
end end
# Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character). # Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character).
@ -21,7 +21,7 @@ module ActiveSupport #:nodoc:
# "hello".from(2) # => "llo" # "hello".from(2) # => "llo"
# "hello".from(10) # => nil # "hello".from(10) # => nil
def from(position) def from(position)
chars[position..-1].to_s mb_chars[position..-1].to_s
end end
# Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character). # Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character).
@ -31,7 +31,7 @@ module ActiveSupport #:nodoc:
# "hello".to(2) # => "hel" # "hello".to(2) # => "hel"
# "hello".to(10) # => "hello" # "hello".to(10) # => "hello"
def to(position) def to(position)
chars[0..position].to_s mb_chars[0..position].to_s
end end
# Returns the first character of the string or the first +limit+ characters. # Returns the first character of the string or the first +limit+ characters.
@ -41,7 +41,7 @@ module ActiveSupport #:nodoc:
# "hello".first(2) # => "he" # "hello".first(2) # => "he"
# "hello".first(10) # => "hello" # "hello".first(10) # => "hello"
def first(limit = 1) def first(limit = 1)
chars[0..(limit - 1)].to_s mb_chars[0..(limit - 1)].to_s
end end
# Returns the last character of the string or the last +limit+ characters. # Returns the last character of the string or the last +limit+ characters.
@ -51,7 +51,7 @@ module ActiveSupport #:nodoc:
# "hello".last(2) # => "lo" # "hello".last(2) # => "lo"
# "hello".last(10) # => "hello" # "hello".last(10) # => "hello"
def last(limit = 1) def last(limit = 1)
(chars[(-limit)..-1] || self).to_s (mb_chars[(-limit)..-1] || self).to_s
end end
end end
else else

View File

@ -9,12 +9,12 @@ module ActiveSupport #:nodoc:
# String methods are proxied through the Chars object, and can be accessed through the +mb_chars+ method. Methods # String methods are proxied through the Chars object, and can be accessed through the +mb_chars+ method. Methods
# which would normally return a String object now return a Chars object so methods can be chained. # which would normally return a String object now return a Chars object so methods can be chained.
# #
# "The Perfect String ".chars.downcase.strip.normalize #=> "the perfect string" # "The Perfect String ".mb_chars.downcase.strip.normalize #=> "the perfect string"
# #
# Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made. # Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made.
# If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them. # If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them.
# #
# bad.explicit_checking_method "T".chars.downcase.to_s # bad.explicit_checking_method "T".mb_chars.downcase.to_s
# #
# The default Chars implementation assumes that the encoding of the string is UTF-8, if you want to handle different # The default Chars implementation assumes that the encoding of the string is UTF-8, if you want to handle different
# encodings you can write your own multibyte string handler and configure it through # encodings you can write your own multibyte string handler and configure it through
@ -213,12 +213,12 @@ module ActiveSupport #:nodoc:
# Example: # Example:
# #
# s = "Müller" # s = "Müller"
# s.chars[2] = "e" # Replace character with offset 2 # s.mb_chars[2] = "e" # Replace character with offset 2
# s # s
# #=> "Müeler" # #=> "Müeler"
# #
# s = "Müller" # s = "Müller"
# s.chars[1, 2] = "ö" # Replace 2 characters at character offset 1 # s.mb_chars[1, 2] = "ö" # Replace 2 characters at character offset 1
# s # s
# #=> "Möler" # #=> "Möler"
def []=(*args) def []=(*args)
@ -253,10 +253,10 @@ module ActiveSupport #:nodoc:
# #
# Example: # Example:
# #
# "¾ cup".chars.rjust(8).to_s # "¾ cup".mb_chars.rjust(8).to_s
# #=> " ¾ cup" # #=> " ¾ cup"
# #
# "¾ cup".chars.rjust(8, " ").to_s # Use non-breaking whitespace # "¾ cup".mb_chars.rjust(8, " ").to_s # Use non-breaking whitespace
# #=> "   ¾ cup" # #=> "   ¾ cup"
def rjust(integer, padstr=' ') def rjust(integer, padstr=' ')
justify(integer, :right, padstr) justify(integer, :right, padstr)
@ -266,10 +266,10 @@ module ActiveSupport #:nodoc:
# #
# Example: # Example:
# #
# "¾ cup".chars.rjust(8).to_s # "¾ cup".mb_chars.rjust(8).to_s
# #=> "¾ cup " # #=> "¾ cup "
# #
# "¾ cup".chars.rjust(8, " ").to_s # Use non-breaking whitespace # "¾ cup".mb_chars.rjust(8, " ").to_s # Use non-breaking whitespace
# #=> "¾ cup   " # #=> "¾ cup   "
def ljust(integer, padstr=' ') def ljust(integer, padstr=' ')
justify(integer, :left, padstr) justify(integer, :left, padstr)
@ -279,10 +279,10 @@ module ActiveSupport #:nodoc:
# #
# Example: # Example:
# #
# "¾ cup".chars.center(8).to_s # "¾ cup".mb_chars.center(8).to_s
# #=> " ¾ cup " # #=> " ¾ cup "
# #
# "¾ cup".chars.center(8, " ").to_s # Use non-breaking whitespace # "¾ cup".mb_chars.center(8, " ").to_s # Use non-breaking whitespace
# #=> " ¾ cup  " # #=> " ¾ cup  "
def center(integer, padstr=' ') def center(integer, padstr=' ')
justify(integer, :center, padstr) justify(integer, :center, padstr)