aboutsummaryrefslogtreecommitdiffstats
path: root/lib/scanf.rb
diff options
context:
space:
mode:
authordblack <dblack@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-03-02 15:59:30 +0000
committerdblack <dblack@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-03-02 15:59:30 +0000
commit24aac11a56933f55149ead00b2dfab18f4facf16 (patch)
treed82fcd3149131b35d6954dbd91b5d92c26eca335 /lib/scanf.rb
parent760691ca01f6785fa7c63a0a51dca04b82a2fc37 (diff)
downloadruby-24aac11a56933f55149ead00b2dfab18f4facf16.tar.gz
* soak_up_spaces only ungetc's non-space last character
* IO#block_scanf now returns partial last iteration array if format string matches partly git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/scanf.rb')
-rw-r--r--lib/scanf.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/scanf.rb b/lib/scanf.rb
index 1662d08e6c..aeff61c115 100644
--- a/lib/scanf.rb
+++ b/lib/scanf.rb
@@ -587,6 +587,7 @@ class IO
# no: continue [this state could be analyzed further]
#
#
+
def scanf(str,&b)
return block_scanf(str,&b) if b
return [] unless str.size > 0
@@ -606,6 +607,7 @@ class IO
end
source_buffer << gets
+
current_match = fstr.match(source_buffer)
spec = fstr.last_spec_tried
@@ -632,7 +634,6 @@ class IO
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
@@ -647,15 +648,18 @@ class IO
until eof ||! c || /\S/.match(c.chr)
c = getc
end
- ungetc(c) if c
+ ungetc(c) if (c && /\S/.match(c.chr))
end
def block_scanf(str)
final = []
+# Sub-ideal, since another FS gets created in scanf.
+# But used here to determine the number of specifiers.
+ fstr = Scanf::FormatString.new(str)
begin
current = scanf(str)
final.push(yield(current)) unless current.empty?
- end until current.empty? || eof
+ end until eof || current.size < fstr.spec_count
return final
end
end