Re: Not terminating loop possible with RX_PCRE_REGULAR_EXPRESSION.replace_all

Berend de Boer <[email protected]> Tue, 09 Jun 2009 15:37:04 +0200
Newsgroups gmane.comp.lang.eiffel.gobo.general
Message-ID <[email protected]>
>>>>> "Berend" == Berend de Boer <[email protected]> writes:

    Berend> What happens is that the start position is 1, and the end
    Berend> position is 0. has_matched is always true. I'm not sure
    Berend> how to solve this. This was what I have now:

My previous solution didn't work that well. Here another attempt:

			new_end, previous_end: INTEGER
		do
			old_subject_start := subject_start
			from until not has_matched loop
				STRING_.append_substring_to_string (a_string, subject, subject_start, captured_start_position (0) - 1)
				append_replacement_to_string (a_string, a_replacement)
				previous_end := captured_end_position (0)
				match_substring (subject, previous_end + 1, subject_end)
				new_end := captured_end_position (0)
				if previous_end = new_end then
					-- Get out of loop, we're matching the same thing,
					-- i.e. we're not making any progress.
					match_count := 0
				end
			end

So if the captured_end_position doesn't move, we quite the loop.

-- 
All the best,

Berend de Boer


------------------------------------

To Post a message, send it to:   [email protected]
To Unsubscribe, send a blank message to: [email protected]! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/gobo-eiffel/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/gobo-eiffel/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/