# File scanf.rb, line 305 def scanf(str,&b) return block_scanf(str,&b) if b return [] unless str.size > 0 start_position = pos matched_so_far = 0 result_buffer = [] source_buffer = "" final_result = [] fstr = Scanf::FormatString.new(str) loop do if eof final_result.concat(result_buffer) break end source_buffer << gets current_match = fstr.match(source_buffer) spec = fstr.last_spec_tried if fstr.last_match_tried if spec.mid_match? 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? result_buffer.replace(current_match) next end end final_result.concat(current_match) matched_so_far += source_buffer.size source_buffer.replace(fstr.string_left) matched_so_far -= source_buffer.size if fstr.last_spec soak_up_spaces break end fstr.prune end seek(start_position + matched_so_far, IO::SEEK_SET) rescue Errno::ESPIPE return final_result end