lib/bychar.rb in bychar-2.0.0 vs lib/bychar.rb in bychar-3.0.0
- old
+ new
@@ -4,24 +4,38 @@
require File.dirname(__FILE__) + "/impls/reader_iobuf"
require File.dirname(__FILE__) + "/impls/reader_strbuf"
require File.dirname(__FILE__) + "/impls/reader_bare"
module Bychar
- VERSION = '2.0.0'
+ VERSION = '3.0.0'
DEFAULT_BUFFER_SIZE = 512 * 1024
- # Gets raised when you have exhausted the underlying IO
- class EOF < EOFError #:nodoc: all
+ # The basic wrapper that you get from wrap()
+ class Wrapper
+ def initialize(io_to_wrap)
+ @io = io_to_wrap
+ end
+
+ def read_one_char
+ @io.read_one_char
+ end
+
+ def each_char
+ while char = read_one_char do
+ yield char
+ end
+ end
end
- # Returns a reader object that responds to read_one_char!
- # and raises an EOF if the IO is depleted
+ # Returns a reader object that responds to read_one_char
+ # and can be passed on to the actual parsers
def self.wrap(io)
- if RUBY_PLATFORM == 'java'
+ reader = if RUBY_PLATFORM == 'java'
ReaderIOBuf.new(io)
elsif RUBY_VERSION < '1.9'
ReaderBare.new(io)
else
ReaderStrbuf.new(io)
end
+ Wrapper.new(reader)
end
end
\ No newline at end of file