Sha256: 1d31b5e7e890a3f7cefd137a75699c569a31320272138bdc3de6ab86bf7cacda

Contents?: true

Size: 1.08 KB

Versions: 20

Compression:

Stored size: 1.08 KB

Contents

class IO
  if RUBY_VERSION < '1.8.7'
    Backports.make_block_optional self, :each, :each_line, :each_byte, :force => true
    class << self
      Backports.make_block_optional self, :foreach, :force => true
    end
  end

  def each_char
    return to_enum(:each_char) unless block_given?
    if $KCODE == "UTF-8"
      lookup = 7.downto(4)
      while c = read(1) do
        n = c[0]
        leftmost_zero_bit = lookup.find{|i| n[i].zero? }
        case leftmost_zero_bit
        when 7 # ASCII
          yield c
        when 6 # UTF 8 complementary characters
          next # Encoding error, ignore
        else
          more = read(6-leftmost_zero_bit)
          break unless more
          yield c+more
        end
      end
    else
      while s = read(1)
        yield s
      end
    end

    self
  end unless method_defined? :each_char

  Backports.alias_method self, :bytes, :each_byte
  Backports.alias_method self, :chars, :each_char
  Backports.alias_method self, :lines, :each_line

  Backports.alias_method self, :getbyte, :getc 
  Backports.alias_method self, :readbyte, :readchar
end
  

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
backports-3.0.3 lib/backports/1.8.7/io.rb
backports-3.0.2 lib/backports/1.8.7/io.rb
backports-3.0.1 lib/backports/1.8.7/io.rb
backports-3.0.0 lib/backports/1.8.7/io.rb
backports-2.8.2 lib/backports/1.8.7/io.rb
backports-2.8.1 lib/backports/1.8.7/io.rb
backports-2.8.0 lib/backports/1.8.7/io.rb
backports-2.7.1 lib/backports/1.8.7/io.rb
backports-2.7.0 lib/backports/1.8.7/io.rb
backports-2.6.7 lib/backports/1.8.7/io.rb
backports-2.6.6 lib/backports/1.8.7/io.rb
backports-2.6.5 lib/backports/1.8.7/io.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/backports-2.6.4/lib/backports/1.8.7/io.rb
backports-2.6.4 lib/backports/1.8.7/io.rb
backports-2.6.3 lib/backports/1.8.7/io.rb
backports-2.6.2 lib/backports/1.8.7/io.rb
backports-2.6.1 lib/backports/1.8.7/io.rb
backports-2.6.0 lib/backports/1.8.7/io.rb
backports-2.5.3 lib/backports/1.8.7/io.rb
backports-2.5.2 lib/backports/1.8.7/io.rb