mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-08 04:05:30 -05:00
raise exception in CCString.replace if sub=""
This commit is contained in:
parent
8a3b53f320
commit
32fb4cf044
1 changed files with 4 additions and 2 deletions
|
|
@ -124,7 +124,9 @@ let replace_at_ ~pos ~len ~by s =
|
|||
Buffer.add_substring b s (pos+len) (String.length s - pos - len);
|
||||
Buffer.contents b
|
||||
|
||||
let replace ?(which=`All) ~sub ~by s = match which with
|
||||
let replace ?(which=`All) ~sub ~by s =
|
||||
if sub="" then invalid_arg "CCstring.replace";
|
||||
match which with
|
||||
| `Left ->
|
||||
let i = find ~sub s in
|
||||
if i>=0 then replace_at_ ~pos:i ~len:(String.length sub) ~by s else s
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue