Class | Scanf::FormatString |
In: |
lib/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 lib/scanf.rb, line 514 514: def initialize(str) 515: @specs = [] 516: @i = 1 517: s = str.to_s 518: return unless /\S/.match(s) 519: @space = true if /\s\z/.match(s) 520: @specs.replace s.scan(REGEX).map {|spec| FormatSpecifier.new(spec) } 521: end
# File lib/scanf.rb, line 539 539: def match(str) 540: accum = [] 541: @string_left = str 542: @matched_count = 0 543: 544: @specs.each_with_index do |spec,@i| 545: @last_spec_tried = spec 546: @last_match_tried = spec.match(@string_left) 547: break unless @last_match_tried 548: @matched_count += 1 549: 550: accum << spec.conversion 551: 552: @string_left = @last_match_tried.post_match 553: break if @string_left.empty? 554: end 555: return accum.compact 556: end