lib/facet/matchdata/matchtree.rb in facets-0.7.2 vs lib/facet/matchdata/matchtree.rb in facets-0.9.0
- old
+ new
@@ -1,29 +2 @@
-class MatchData
- # An alternate to #to_a which returns the matches in
- # order corresponding with the regular expression.
- #
- # require 'facet/matchdata/matchtree'
- #
- # md = /(bb)(cc(dd))(ee)/.match "XXaabbccddeeffXX"
- # md.to_a #=> ["XXaabbccddeeffXX", "bb", "ccdd", "dd", "ee"]
- # md.matches #=> ["XXaa", [["bb"], ["cc", ["dd"]], "ee"], "ffXX"]
- #
- def matchtree(index=0)
- ret=[]
- b, e=self.begin(index), self.end(index)
- while (index+=1)<=length
- if index==length || (bi=self.begin(index))>=e
- # we are finished, if something is left, then add it
- ret << string[b, e-b] if e>b
- break
- else
- if bi>=b
- ret << string[b, bi-b] if bi>b
- ret << matchtree(index)
- b=self.end(index)
- end
- end
- end
- return ret
- end
-end
+require 'nano/matchdata/matchtree.rb'
\ No newline at end of file