Module StringExtra.Extra.Text (.ml)


module Text: sig .. end
Converting raw text to list of strings and vice-versa. A raw text is simply a (may be big) string, i.e. a sequence of lines collected in a unique string, where each line terminates with a newline '\n'. The last line in the text may not terminate with a newline.

type t = string list 
A (line structured) text is a list of strings.
type filter = string list -> string list 
A text filter is a function from and to string lists.
val to_string : StringExtra.Extra.line list -> StringExtra.Extra.line
Convert a string list in a raw text. Each string in the input list is treated by the function StringExtra.Extra.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:
# Text.to_string ["AAA";"BBB";"CCC"];;
  : string = "AAA\nBBB\nCCC\n"

# Text.to_string ["AAA";"BBB\n";"CCC"];;
  : string = "AAA\nBBB\nCCC\n"

# Text.to_string ["AAA";"BBB\n\n";"CCC"];;
  : string = "AAA\nBBB\n\nCCC\n"

val of_string : ?squeeze:bool -> string -> string list
Convert a raw text in a structured text (a string list). This function is simply an alias for split ~squeeze ~d:'\n'. Examples:
# Text.of_string (Unix.cat "/etc/fstab")  ;;
  : string list =
["/dev/sda1   /                    reiserfs   acl,user_xattr    1 1";
 "/dev/sda3   swap                 swap       defaults          0 0";
 "/dev/sda4   /home                reiserfs   acl,user_xattr    1 1";
 "proc        /proc                proc       defaults          0 0";
 "/dev/fd0    /media/floppy        auto       noauto,user,sync  0 0"]

# Text.of_string (Unix.shell "echo aaa; echo; echo bbb");;
  : string list = ["aaa"; "bbb"]

# Text.of_string ~squeeze:false (Unix.shell "echo aaa; echo; echo bbb");;
  : string list = ["aaa"; ""; "bbb"] 

module Matrix: sig .. end
Converting raw text to matrix (list of list) of strings (words) and vice-versa.