2007-01-22 14:43:50 +01:00
|
|
|
require 'strscan'
|
|
|
|
|
|
|
|
module ActiveSupport #:nodoc:
|
|
|
|
module CoreExtensions #:nodoc:
|
|
|
|
module String #:nodoc:
|
|
|
|
# Custom string iterators
|
|
|
|
module Iterators
|
2008-05-18 06:22:34 +02:00
|
|
|
def self.append_features(base)
|
|
|
|
super unless '1.9'.respond_to?(:each_char)
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
# Yields a single-character string for each character in the string.
|
|
|
|
# When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
|
|
|
|
def each_char
|
|
|
|
scanner, char = StringScanner.new(self), /./mu
|
|
|
|
loop { yield(scanner.scan(char) || break) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|