From: Eric B. <er...@be...> - 2007-11-10 14:15:49
|
Colin Paul Adams wrote: >>>>>> "Colin" == Colin Paul Adams <co...@co...> writes: > > Colin> I don't know if that is the correct result to return, but I > Colin> can't think of any other at the moment. > > Colin> That wasn't sufficient, as the postcondition all_matched > Colin> doesn't hold. I will have to dig deeper. What about: replace_all (a_replacement: STRING): STRING is -- Substring of `subject' between `subject_start' and `subject_end' -- where the whole matched string has been repeatedly replaced by -- `a_replacement'; All occurrences of \n\ in `a_replacement' will -- have been replaced by the corresponding n-th captured substrings -- if any require is_matching: is_matching a_replacement_not_void: a_replacement /= Void same_type: ANY_.same_types (a_replacement, subject) do Result := STRING_.new_empty_string (subject, subject_end - subject_start + 1) append_replace_all_to_string (Result, a_replacement) ensure all_matched: not has_matched replace_not_void: Result /= Void same_type: ANY_.same_types (Result, subject) end I think that we really need to allocate a string with a capacity of 'subject_end - subject_start + 1' (and not just 'subject_end - subject_start'). -- Eric Bezault mailto:er...@go... http://www.gobosoft.com |