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

Remove most Str.split #119

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/FindFiles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ let isSourceFile name =
|| Filename.check_suffix name ".mli"

let compiledNameSpace name =
Str.split (Str.regexp_string "-") name
String.split_on_char '-' name
|> List.map String.capitalize_ascii
|> String.concat ""
(* Remove underscores??? Whyyy bucklescript, whyyyy *)
|> Str.split (Str.regexp_string "_")
|> String.split_on_char '_'
|> String.concat ""

let compiledBaseName ~namespace name =
Expand Down
4 changes: 2 additions & 2 deletions src/MarkdownOfOCamldoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let sliceToEnd text num =
if ln <= num then "" else String.sub text num (ln - num)

let stripLeft text =
let lines = Str.split (Str.regexp_string "\n") text in
let lines = String.split_on_char '\n' text in
let rec loop lines =
match lines with
| [] -> 0
Expand Down Expand Up @@ -122,7 +122,7 @@ let convertItem item =
match String.trim lang = "" with
| true -> "ml"
| false ->
let parts = Str.split (Str.regexp_string ";") (String.trim lang) in
let parts = String.split_on_char ';' (String.trim lang) in
if
List.mem "ml" parts || List.mem "ocaml" parts || List.mem "re" parts
|| List.mem "reason" parts
Expand Down
2 changes: 1 addition & 1 deletion src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let newBsPackage rootPath =
match item |> Json.string with
| None -> opens
| Some s -> (
let parts = Utils.split_on_char ' ' s in
let parts = String.split_on_char ' ' s in
match parts with
| "-open" :: name :: _ -> name :: opens
| _ -> opens))
Expand Down
8 changes: 4 additions & 4 deletions src/PartialParser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let findCallFromArgument text offset =
let i1 = skipWhite text (i - 1) in
let i0 = startOfLident text i1 in
let funLident = String.sub text i0 (i1 - i0 + 1) in
Str.split (Str.regexp_string ".") funLident
String.split_on_char '.' funLident
| ')' -> loop ~i:(i - 1) ~nClosed:(nClosed + 1)
| _ -> loop ~i:(i - 1) ~nClosed
else []
Expand Down Expand Up @@ -134,7 +134,7 @@ let isLowercaseIdent id =
let findCompletable text offset =
let mkPath s =
let len = String.length s in
let parts = Str.split (Str.regexp_string ".") s in
let parts = String.split_on_char '.' s in
let parts =
match s.[len - 1] = '.' with true -> parts @ [""] | false -> parts
in
Expand All @@ -143,7 +143,7 @@ let findCompletable text offset =
match findJsxContext text (offset - len - 1) with
| None -> Cpath parts
| Some componentName ->
Cjsx (Str.split (Str.regexp_string ".") componentName, id))
Cjsx (String.split_on_char '.' componentName, id))
| _ -> Cpath parts
in
let mkPipe off partialName =
Expand Down Expand Up @@ -200,7 +200,7 @@ let findOpens text offset =
| [] -> SharedTypes.Tip "place holder"
| one :: rest -> Nested (one, loop rest)
in
loop (o |> Str.split (Str.regexp_string "."))
loop (o |> String.split_on_char '.')
in
let add o = opens := (o |> pathOfModuleOpen) :: !opens in
let maybeOpen i0 =
Expand Down
2 changes: 1 addition & 1 deletion src/PrepareUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let trimFirst num string =
| false -> ""

let cleanOffStars doc =
let lines = Str.split (Str.regexp_string "\n") doc in
let lines = String.split_on_char '\n' doc in
let rec loop lines =
match lines with
| [] -> None
Expand Down
15 changes: 0 additions & 15 deletions src/Utils.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
(*
steal from OCaml stdlib
https://github.com/ocaml/ocaml/blob/7c9c210884e1b46f21af5bb4dfab995bb3336cf7/stdlib/string.ml#L205-L214
*)
let split_on_char sep s =
let open String in
let r = ref [] in
let j = ref (length s) in
for i = length s - 1 downto 0 do
if unsafe_get s i = sep then (
r := sub s (i + 1) (!j - i - 1) :: !r;
j := i)
done;
sub s 0 !j :: !r

let topLoc fname =
{
Location.loc_start =
Expand Down