Module Micmatch.Text


module Text: sig .. end


This module provides some general functions which are especially useful for manipulating text and text files.
val iter_lines_of_channel : (string -> unit) -> Pervasives.in_channel -> unit
iter_lines_of_channel f ic reads input channel ic and applies successively the given function f to each line until the end of file is reached.
val iter_lines_of_file : (string -> unit) -> string -> unit
iter_lines_of_file f file reads file file and applies successively the given function f to each line until the end of file is reached.
val lines_of_channel : Pervasives.in_channel -> string list
lines_of_channel ic returns the list of the lines that can be read from input channel ic.
val lines_of_file : string -> string list
lines_of_file file returns the list of the lines that can be read from file file.
val channel_contents : Pervasives.in_channel -> string
channel_contents ic returns the string containing the bytes that can be read from the given input channel ic.
val file_contents : ?bin:bool -> string -> string
file_contents file returns the string containing the bytes that can be read from the given file. Option bin specifies if Pervasives.open_in_bin should be used instead of Pervasives.open_in to open the file. Default is false.
val save : string -> string -> unit
save file data stores the string data in file. If the file already exists, its contents is discarded silently.
val save_lines : string -> string list -> unit
save_lines file l saves the given list l of strings in file and adds a newline characters ('\n') after each of them. If the file already exists, its contents is discarded silently.
exception Skip
This exception can be used to skip an element of a list being processed with rev_map, map, fold_left, and fold_right.
val map : ('a -> 'b) -> 'a list -> 'b list
Like List.map but it is guaranteed that the elements of the input list are processed from left to right. Moreover the Skip exception can be used to skip an element of the list. This function runs in constant stack space.
val rev_map : ('a -> 'b) -> 'a list -> 'b list
Like List.rev_map, but it is guaranteed that the elements of the input list are processed from left to right. Moreover the Skip exception can be used to skip an element of the list. This function runs in constant stack space and is slightly faster then map.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
Like List.fold_left but the Skip exception can be used to skip an element of the list. This function runs in constant stack space.
val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
Like List.fold_right but the Skip exception can be used to skip an element of the list. This function runs in constant stack space.
val map_lines_of_channel : (string -> 'a) -> Pervasives.in_channel -> 'a list
map_lines_of_channel f ic is equivalent to map f (lines_of_channel ic) but faster.
val map_lines_of_file : (string -> 'a) -> string -> 'a list
map_lines_of_file f file is equivalent to map f (lines_of_file file) but faster.