Class | Scanf::FormatSpecifier::FormatString |
In: |
scanf.rb
|
Parent: | Object |
SPECIFIERS | = | 'diuXxofeEgsc' |
REGEX | = | / # possible space, followed by... (?:\s* # percent sign, followed by... % # another percent sign, or... (?:%| # optional assignment suppression flag \*? # optional maximum field width \d* # named character class, ... (?:\[\[:\w+:\]\]| # traditional character class, or... \[[^\]]*\]| # specifier letter. [#{SPECIFIERS}])))| # or miscellaneous characters [^%\s]+/ix |
last_match_tried | [R] | |
last_spec_tried | [R] | |
matched_count | [R] | |
space | [R] | |
string_left | [R] |
# File scanf.rb, line 514 def initialize(str) @specs = [] @i = 1 s = str.to_s return unless /\S/.match(s) @space = true if /\s\z/.match(s) @specs.replace s.scan(REGEX).map {|spec| FormatSpecifier.new(spec) } end
# File scanf.rb, line 539 def match(str) accum = [] @string_left = str @matched_count = 0 @specs.each_with_index do |spec,@i| @last_spec_tried = spec @last_match_tried = spec.match(@string_left) break unless @last_match_tried @matched_count += 1 accum << spec.conversion @string_left = @last_match_tried.post_match break if @string_left.empty? end return accum.compact end