Sha256: a25ad501a1b1bcfd616b2f7cc9910fa8f53d5372e11f2619af82537329e32d6b

Contents?: true

Size: 1.92 KB

Versions: 18

Compression:

Stored size: 1.92 KB

Contents

#
# Limited StringIO if no core lib is available
#
begin
require 'stringio'
rescue LoadError
    # StringIO based on code by MoonWolf
    class StringIO
        def initialize(string="")
            @string=string
            @pos=0
            @eof=(string.size==0)
        end
        def pos
            @pos
        end    
        def eof
            @eof
        end
        alias eof? eof
        def readline(rs=$/)
            if @eof
                raise EOFError
            else
                if p = @string[@pos..-1]=~rs
                    line = @string[@pos,p+1]
                else
                    line = @string[@pos..-1]
                end
                @pos+=line.size
                @eof =true if @pos==@string.size
                $_ = line
            end
        end
        def rewind
            seek(0,0)
        end
        def seek(offset,whence)
            case whence
            when 0
                @pos=offset
            when 1
                @pos+=offset
            when 2
                @pos=@string.size+offset
            end
            @eof=(@pos>=@string.size)
            0
        end
    end

	#
	# Class method for creating streams
	#
	def YAML.make_stream( io )
        if String === io
            io = StringIO.new( io )
        elsif not IO === io
            raise YAML::Error, "YAML stream must be an IO or String object."
        end
        if YAML::unicode
            def io.readline
                YAML.utf_to_internal( readline( @ln_sep ), @utf_encoding )
            end
            def io.check_unicode
                @utf_encoding = YAML.sniff_encoding( read( 4 ) )
                @ln_sep = YAML.enc_separator( @utf_encoding )
                seek( -4, IO::SEEK_CUR )
            end
		    def io.utf_encoding
		    	@utf_encoding
		    end
            io.check_unicode
        else
            def io.utf_encoding
                :None
            end
        end
        io
	end

end

Version data entries

18 entries across 18 versions & 4 rubygems

Version Path
rubysl-yaml-1.1.0 lib/yaml/stringio.rb
rubysl-yaml-1.0.1 lib/yaml/stringio.rb
ruby_on_ruby-0.0.1 vendor/javascripts/emscripted-ruby/lib/yaml/stringio.rb
shoesgem-0.1514.0 shoes/ruby/lib/yaml/stringio.rb
shoesgem-0.1480.0 shoes/ruby/lib/yaml/stringio.rb
shoesgem-0.1469.0 shoes/ruby/lib/yaml/stringio.rb
shoesgem-0.1430.0 shoes/ruby/lib/yaml/stringio.rb
shoesgem-0.1429.0 shoes/ruby/lib/yaml/stringio.rb
shoesgem-0.1428.0 shoes/ruby/lib/yaml/stringio.rb
shoesgem-0.1426.0 shoes/ruby/lib/yaml/stringio.rb
shoesgem-0.1424.0 shoes/ruby/lib/yaml/stringio.rb
mkrf-0.1.1 test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb
mkrf-0.2.1 test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb
mkrf-0.1.0 test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb
mkrf-0.1.2 test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb
mkrf-0.2.0 test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb
mkrf-0.2.2 test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb
mkrf-0.2.3 test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb