aboutsummaryrefslogtreecommitdiff
path: root/viz.js/process/tools.ml
diff options
context:
space:
mode:
Diffstat (limited to 'viz.js/process/tools.ml')
-rwxr-xr-xviz.js/process/tools.ml26
1 files changed, 26 insertions, 0 deletions
diff --git a/viz.js/process/tools.ml b/viz.js/process/tools.ml
new file mode 100755
index 0000000..c5e39b1
--- /dev/null
+++ b/viz.js/process/tools.ml
@@ -0,0 +1,26 @@
+let drop_while predicate =
+ let rec _drop = function
+ | [] -> []
+ | (hd::tl) as l ->
+ if predicate hd then
+ _drop tl
+ else
+ l
+ in _drop
+
+(* Split a text and and new line before it goes to long *)
+let split limit =
+ let rec _split elms text =
+ let length = (String.length text) -1 in
+ if (length < limit) then
+ List.rev (text::elms)
+ |> String.concat "\\n"
+ else
+ try
+ let pos = String.rindex_from text limit ' ' in
+ let hd = String.sub text 0 pos
+ and tl = String.sub text (pos +1) (length - pos) in
+ _split (hd::elms) tl
+ with Not_found -> text
+ in _split []
+