From befc42d15c06b1bac33b3c595c2406a664c6ce17 Mon Sep 17 00:00:00 2001 From: Alexander Bandukwala <7h3kk1d@gmail.com> Date: Tue, 10 Dec 2024 13:00:31 -0500 Subject: [PATCH] Use js_of_ocaml regex for split --- src/util/StringUtil.re | 8 +------- test/Test_StringUtil.re | 8 ++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/util/StringUtil.re b/src/util/StringUtil.re index 49a5cab22..582290e85 100644 --- a/src/util/StringUtil.re +++ b/src/util/StringUtil.re @@ -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'); diff --git a/test/Test_StringUtil.re b/test/Test_StringUtil.re index b9c497337..fd2be69fd 100644 --- a/test/Test_StringUtil.re +++ b/test/Test_StringUtil.re @@ -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", ".*"), + ) + }), ], );