Skip to content

Commit

Permalink
Use js_of_ocaml regex for split
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Dec 10, 2024
1 parent 42a6262 commit befc42d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/util/StringUtil.re
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ let split = Js_of_ocaml.Regexp.split;

let plain_split: (string, string) => list(string) =
(str, sep) => {
Js_of_ocaml.(
Js.string(str)##split(Js.string(sep))
|> Js.str_array
|> Js.to_array
|> Array.to_list
|> List.map(Js.to_string)
);
split(Js_of_ocaml.Regexp.regexp_string(sep), str);
};

let to_lines = String.split_on_char('\n');
Expand Down
8 changes: 8 additions & 0 deletions test/Test_StringUtil.re
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,13 @@ let tests = (
StringUtil.plain_split("abbe", "b"),
)
}),
test_case("regexp special character in separator", `Quick, () => {
check(
list(string),
"split",
["a", "c"],
StringUtil.plain_split("a.*c", ".*"),
)
}),
],
);

0 comments on commit befc42d

Please sign in to comment.