From 77544bdfad2af41514ec1435f706fee87ea2969e Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 7 Feb 2022 15:38:37 +0100 Subject: Added viz.js code --- viz.js/process/tools.ml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 viz.js/process/tools.ml (limited to 'viz.js/process/tools.ml') 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 [] + -- cgit v1.2.3