summaryrefslogtreecommitdiff
path: root/viz.js/process/tools.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2022-02-07 15:38:37 +0100
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:01:12 +0100
commit77544bdfad2af41514ec1435f706fee87ea2969e (patch)
tree4de23870e08711da25ff92e9670370fc0a74e459 /viz.js/process/tools.ml
parentad526111f0dd619ae9e0e98ef2253146b58a068f (diff)
Added viz.js code
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 []
+