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/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.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 new file mode 100644 index 0000000000..a58e7353b3 --- /dev/null +++ b/jscomp/others/belt_String.ml @@ -0,0 +1,12 @@ +open 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..8ca01f937e --- /dev/null +++ b/jscomp/others/belt_String.mli @@ -0,0 +1 @@ +val split_on_char : char -> string -> string list