Sha256: 3570a733226239a05eb3d41f2909567c0ea7f94865b0588f497baa0b0e5c660e

Contents?: true

Size: 808 Bytes

Versions: 26

Compression:

Stored size: 808 Bytes

Contents

unless ARGF.respond_to? :each_char
  require 'backports/tools'
  require 'enumerator'

  class << ARGF
    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

    Backports.alias_method self, :chars, :each_char
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
scout_realtime-1.0.5 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-1.0.4 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-1.0.3 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-1.0.3.pre lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-1.0.2 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-1.0.1 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-1.0.0 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-0.5.5 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-0.5.5.pre lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-0.5.4 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
backports-3.6.0 lib/backports/1.8.7/argf/each_char.rb
backports-3.5.0 lib/backports/1.8.7/argf/each_char.rb
backports-3.4.1 lib/backports/1.8.7/argf/each_char.rb
scout_realtime-0.5.3 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-0.5.2 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
scout_realtime-0.5.1 lib/vendor/backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb
backports-3.4.0 lib/backports/1.8.7/argf/each_char.rb
backports-3.3.5 lib/backports/1.8.7/argf/each_char.rb
backports-3.3.4 lib/backports/1.8.7/argf/each_char.rb
backports-3.3.3 lib/backports/1.8.7/argf/each_char.rb