Skip to content

Commit

Permalink
Partial fix so STDIN#scanf works with new STDIN#pos behavior
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
dblack committed Mar 1, 2004
1 parent 933fb96 commit b0c3888
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/scanf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ def count_space?

def initialize(str)
@spec_string = str

h = '[A-Fa-f0-9]'

@re_string, @handler =
Expand Down Expand Up @@ -523,7 +522,7 @@ def initialize(str)
end

def to_s
@spec_string
@specs.join('')
end

def prune(n=matched_count)
Expand Down Expand Up @@ -592,7 +591,7 @@ def scanf(str,&b)
return block_scanf(str,&b) if b
return [] unless str.size > 0

start_position = pos
start_position = pos rescue 0
matched_so_far = 0
source_buffer = ""
result_buffer = []
Expand All @@ -601,7 +600,7 @@ def scanf(str,&b)
fstr = Scanf::FormatString.new(str)

loop do
if eof
if eof || (tty? &&! fstr.match(source_buffer))
final_result.concat(result_buffer)
break
end
Expand All @@ -616,6 +615,7 @@ def scanf(str,&b)
result_buffer.replace(current_match)
next
end

elsif (fstr.matched_count == fstr.spec_count - 1)
if /\A\s*\z/.match(fstr.string_left)
break if spec.count_space?
Expand All @@ -632,10 +632,10 @@ def scanf(str,&b)
break if fstr.last_spec
fstr.prune
end

seek(start_position + matched_so_far, IO::SEEK_SET) rescue Errno::ESPIPE
soak_up_spaces if fstr.last_spec && fstr.space

return final_result
end

Expand Down

0 comments on commit b0c3888

Please sign in to comment.