regex.e find_all -- another problem
- Posted by jessedavis Mar 26, 2010
- 1022 views
It must be because it's Friday! After fixing the problem of find_all() returning a sequence instead of an atom for null results I foolishly went back to the app coding only to discover that even when find_all finds a pattern and returns the sequence containing the location it has an extra level in the returned sequence. It really makes recovering the found sequence a pain.
when find_all returns a sequence it should be:
{{1,3},{5,7},...} --> a sequence of pairs
what it really returns is:
{{{1,3},{5,7},....}} -----> notice the extra braces??
A brute force & ignorance solution is given below: the changes are the first 6 lines following the while sequence(re..... statement and the addition of integer i which is set to zero EACH time the routine is called!
public function find_all(regex re, sequence haystack, integer from=1, object options=DEFAULT) if sequence(options) then options = or_all(options) end if object result sequence results = {} integer i i = 0 while sequence(result) with entry do if i = 0 then results = result i += 1 else results = append(results, result) end if from = max(result) + 1 if from > length(haystack) then exit end if entry result = find(re, haystack, from, options) end while if length(results) then return results else return -1 end if end function
Regards, jd