summaryrefslogtreecommitdiffstats
path: root/otherlibs
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2001-08-30 13:18:11 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2001-08-30 13:18:11 +0000
commit561f80d95d504a244ca5350a448249ad32abad41 (patch)
tree7c2c85595bbf0ba77489af836c444619e05e42a0 /otherlibs
parent74472b9c2f48813db54d3bbad85099f89ca44625 (diff)
Blinder global_regexp vis-a-vis des regexp qui filtrent la chaine vide (PR#484)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3686 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs')
-rw-r--r--otherlibs/str/str.ml10
1 files changed, 6 insertions, 4 deletions
diff --git a/otherlibs/str/str.ml b/otherlibs/str/str.ml
index 18e7b6621..a0e7827d9 100644
--- a/otherlibs/str/str.ml
+++ b/otherlibs/str/str.ml
@@ -83,17 +83,19 @@ let substitute_first expr repl_fun text =
text
let global_substitute expr repl_fun text =
- let rec replace start =
+ let rec replace start last_was_empty =
try
- let pos = search_forward expr text start in
+ let startpos = if last_was_empty then start + 1 else start in
+ if startpos > String.length text then raise Not_found;
+ let pos = search_forward expr text startpos in
let end_pos = match_end() in
let repl_text = repl_fun text in
String.sub text start (pos-start) ::
repl_text ::
- replace end_pos
+ replace end_pos (end_pos = pos)
with Not_found ->
[string_after text start] in
- String.concat "" (replace 0)
+ String.concat "" (replace 0 false)
let global_replace expr repl text =
global_substitute expr (replacement_text repl) text