Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 515205c

Browse files
committed
Remove most Str.split
Not needed
1 parent 528cc07 commit 515205c

File tree

6 files changed

+10
-25
lines changed

6 files changed

+10
-25
lines changed

src/FindFiles.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ let isSourceFile name =
4646
|| Filename.check_suffix name ".mli"
4747

4848
let compiledNameSpace name =
49-
Str.split (Str.regexp_string "-") name
49+
String.split_on_char '-' name
5050
|> List.map String.capitalize_ascii
5151
|> String.concat ""
5252
(* Remove underscores??? Whyyy bucklescript, whyyyy *)
53-
|> Str.split (Str.regexp_string "_")
53+
|> String.split_on_char '_'
5454
|> String.concat ""
5555

5656
let compiledBaseName ~namespace name =

src/MarkdownOfOCamldoc.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let sliceToEnd text num =
2424
if ln <= num then "" else String.sub text num (ln - num)
2525

2626
let stripLeft text =
27-
let lines = Str.split (Str.regexp_string "\n") text in
27+
let lines = String.split_on_char '\n' text in
2828
let rec loop lines =
2929
match lines with
3030
| [] -> 0
@@ -122,7 +122,7 @@ let convertItem item =
122122
match String.trim lang = "" with
123123
| true -> "ml"
124124
| false ->
125-
let parts = Str.split (Str.regexp_string ";") (String.trim lang) in
125+
let parts = String.split_on_char ';' (String.trim lang) in
126126
if
127127
List.mem "ml" parts || List.mem "ocaml" parts || List.mem "re" parts
128128
|| List.mem "reason" parts

src/Packages.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ let newBsPackage rootPath =
7979
match item |> Json.string with
8080
| None -> opens
8181
| Some s -> (
82-
let parts = Utils.split_on_char ' ' s in
82+
let parts = String.split_on_char ' ' s in
8383
match parts with
8484
| "-open" :: name :: _ -> name :: opens
8585
| _ -> opens))

src/PartialParser.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let findCallFromArgument text offset =
4444
let i1 = skipWhite text (i - 1) in
4545
let i0 = startOfLident text i1 in
4646
let funLident = String.sub text i0 (i1 - i0 + 1) in
47-
Str.split (Str.regexp_string ".") funLident
47+
String.split_on_char '.' funLident
4848
| ')' -> loop ~i:(i - 1) ~nClosed:(nClosed + 1)
4949
| _ -> loop ~i:(i - 1) ~nClosed
5050
else []
@@ -134,7 +134,7 @@ let isLowercaseIdent id =
134134
let findCompletable text offset =
135135
let mkPath s =
136136
let len = String.length s in
137-
let parts = Str.split (Str.regexp_string ".") s in
137+
let parts = String.split_on_char '.' s in
138138
let parts =
139139
match s.[len - 1] = '.' with true -> parts @ [""] | false -> parts
140140
in
@@ -143,7 +143,7 @@ let findCompletable text offset =
143143
match findJsxContext text (offset - len - 1) with
144144
| None -> Cpath parts
145145
| Some componentName ->
146-
Cjsx (Str.split (Str.regexp_string ".") componentName, id))
146+
Cjsx (String.split_on_char '.' componentName, id))
147147
| _ -> Cpath parts
148148
in
149149
let mkPipe off partialName =
@@ -200,7 +200,7 @@ let findOpens text offset =
200200
| [] -> SharedTypes.Tip "place holder"
201201
| one :: rest -> Nested (one, loop rest)
202202
in
203-
loop (o |> Str.split (Str.regexp_string "."))
203+
loop (o |> String.split_on_char '.')
204204
in
205205
let add o = opens := (o |> pathOfModuleOpen) :: !opens in
206206
let maybeOpen i0 =

src/PrepareUtils.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let trimFirst num string =
2222
| false -> ""
2323

2424
let cleanOffStars doc =
25-
let lines = Str.split (Str.regexp_string "\n") doc in
25+
let lines = String.split_on_char '\n' doc in
2626
let rec loop lines =
2727
match lines with
2828
| [] -> None

src/Utils.ml

-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
(*
2-
steal from OCaml stdlib
3-
https://github.com/ocaml/ocaml/blob/7c9c210884e1b46f21af5bb4dfab995bb3336cf7/stdlib/string.ml#L205-L214
4-
*)
5-
let split_on_char sep s =
6-
let open String in
7-
let r = ref [] in
8-
let j = ref (length s) in
9-
for i = length s - 1 downto 0 do
10-
if unsafe_get s i = sep then (
11-
r := sub s (i + 1) (!j - i - 1) :: !r;
12-
j := i)
13-
done;
14-
sub s 0 !j :: !r
15-
161
let topLoc fname =
172
{
183
Location.loc_start =

0 commit comments

Comments
 (0)