Skip to content

Commit

Permalink
Merge pull request #132 from rgrinberg/fix-129
Browse files Browse the repository at this point in the history
Fix Re_str.global_replace
  • Loading branch information
rgrinberg committed Oct 19, 2016
2 parents 0c80766 + 7d8d3ec commit a60cdfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/re_str.ml
Expand Up @@ -147,11 +147,11 @@ let rec replace orig repl p res q len =
with Not_found ->
0
in
replace repl orig (p + 2) res (q + d) len
replace orig repl (p + 2) res (q + d) len
| c ->
Bytes.set res q '\\';
Bytes.set res (q + 1) c;
replace repl orig (p + 2) res (q + 2) len
replace orig repl (p + 2) res (q + 2) len
end
end

Expand Down
7 changes: 5 additions & 2 deletions lib_test/test_str.ml
Expand Up @@ -163,8 +163,11 @@ let _ =
global_replace "needle" "" "needle";
global_replace "xxx" "yyy" "zzz";

(* the test below fails *)
(* global_replace "\\(X+\\)" "A\\1YY" "XXXXXXZZZZ" *)
global_replace "test\\([0-9]*\\)" "\\1-foo-\\1" "test100 test200 test";
global_replace "test\\([0-9]*\\)" "'\\-0'" "test100 test200 test";

(* Regrssion test for #129 *)
global_replace "\\(X+\\)" "A\\1YY" "XXXXXXZZZZ"
);

expect_pass "split tests" (fun () ->
Expand Down

0 comments on commit a60cdfd

Please sign in to comment.