struct
(** A (line structured) text is a list of strings. *) |
type t = string list ;;
(** A text filter is a function from and to string lists. *) |
type filter = string list -> string list ;;
(** Convert a string list in a raw text.
Each string in the input list is treated by the function to_line in order to
add a newline if needed, then the list is folded by a simple catenation (^ ).
If the input list is empty, the result is the empty string. Examples:
*) |
let to_string (sl : string list) : string =
let ll = List.map to_line sl in
big (^) ll
;;
(** Convert a raw text in a structured text (a string list).
This function is simply an alias
for split ~squeeze ~d:'\n' . Examples:
*) |
let of_string = (split ~d:'\n') ;;
(** Converting raw text to matrix (list of list) of strings (words) and vice-versa. *) |
module Matrix = struct
(** A (word structured) text is a matrix of strings. *) |
type t = string list list;;
(** A text matrix filter is a function from and to string list lists. *) |
type filter = t -> t ;;
(** Convert a raw text in a matrix of words.
By default the word delimiter is the char d=' '
and squeeze=true .
Example:
*) |
let of_string ?(squeeze=true) ?(d=' ') x =
List.map (split ~squeeze ~d) (of_string x)
;;
(** Convert a matrix of words in a raw text.
By default the word delimiter is the string d=" " .
*) |
let to_string ?(d=" ") m =
to_line (big (merge "\n") (List.map (big (merge d)) m)) ;;
end;; (* module Text.Matrix *)
end