From 2bdd2f0a73c228310523d80699a9d72dc7acdaef Mon Sep 17 00:00:00 2001 From: Benjamin San Souci Date: Tue, 25 Sep 2018 20:39:35 -0700 Subject: [PATCH 1/2] Add belt_String just for that split function. Anything else anyone wants? --- jscomp/others/Makefile | 1 + jscomp/others/belt_String.ml | 12 ++++++++++++ jscomp/others/belt_String.mli | 3 +++ 3 files changed, 16 insertions(+) create mode 100644 jscomp/others/belt_String.ml create mode 100644 jscomp/others/belt_String.mli diff --git a/jscomp/others/Makefile b/jscomp/others/Makefile index f932f72823..b7249c6181 100644 --- a/jscomp/others/Makefile +++ b/jscomp/others/Makefile @@ -50,6 +50,7 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string belt_SetString\ belt_MutableStack\ belt_MutableQueue\ + belt_String\ node_child_process \ js_math\ js_dict js_date js_global js_cast js_promise\ diff --git a/jscomp/others/belt_String.ml b/jscomp/others/belt_String.ml new file mode 100644 index 0000000000..26d089f717 --- /dev/null +++ b/jscomp/others/belt_String.ml @@ -0,0 +1,12 @@ +include String + +let split_on_char sep s = + 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 begin + r := sub s (i + 1) (!j - i - 1) :: !r; + j := i + end + done; + sub s 0 !j :: !r diff --git a/jscomp/others/belt_String.mli b/jscomp/others/belt_String.mli new file mode 100644 index 0000000000..2262ea6042 --- /dev/null +++ b/jscomp/others/belt_String.mli @@ -0,0 +1,3 @@ +include (module type of String) + +val split_on_char : char -> string -> string list From 9ec9b92ec0291044374182b136cc69ad7560feca Mon Sep 17 00:00:00 2001 From: Benjamin San Souci Date: Tue, 25 Sep 2018 20:45:19 -0700 Subject: [PATCH 2/2] Let's just make it a set of utils rather than a reimplementation. --- jscomp/others/.depend | 2 ++ jscomp/others/belt.ml | 7 +++++++ jscomp/others/belt_String.ml | 2 +- jscomp/others/belt_String.mli | 2 -- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/jscomp/others/.depend b/jscomp/others/.depend index d2ac9bb867..48a9155a2c 100644 --- a/jscomp/others/.depend +++ b/jscomp/others/.depend @@ -85,6 +85,7 @@ belt_SetString.cmj : belt_internalSetString.cmj belt_internalAVLset.cmj \ belt_Array.cmj belt_SetString.cmi belt_MutableStack.cmj : belt_MutableStack.cmi belt_MutableQueue.cmj : belt_Array.cmj belt_MutableQueue.cmi +belt_String.cmj : belt_String.cmi node_child_process.cmj : node.cmj js_math.cmj : js_dict.cmj : js_array.cmj js_dict.cmi @@ -145,6 +146,7 @@ belt_SetInt.cmi : belt_SetString.cmi : belt_MutableStack.cmi : belt_MutableQueue.cmi : +belt_String.cmi : js_dict.cmi : js_cast.cmi : dom.cmi : dom_storage.cmi diff --git a/jscomp/others/belt.ml b/jscomp/others/belt.ml index 4edc4a34ae..8f9a511f69 100644 --- a/jscomp/others/belt.ml +++ b/jscomp/others/belt.ml @@ -255,3 +255,10 @@ module Result = Belt_Result Utilities for set up debugging *) module Debug = Belt_Debug + +(** {!Belt.String} + + String utilities +*) +module String = Belt_String + diff --git a/jscomp/others/belt_String.ml b/jscomp/others/belt_String.ml index 26d089f717..a58e7353b3 100644 --- a/jscomp/others/belt_String.ml +++ b/jscomp/others/belt_String.ml @@ -1,4 +1,4 @@ -include String +open String let split_on_char sep s = let r = ref [] in diff --git a/jscomp/others/belt_String.mli b/jscomp/others/belt_String.mli index 2262ea6042..8ca01f937e 100644 --- a/jscomp/others/belt_String.mli +++ b/jscomp/others/belt_String.mli @@ -1,3 +1 @@ -include (module type of String) - val split_on_char : char -> string -> string list