Module StringExtra.Extra (.ml)


module Extra: sig .. end
Extra definitions.

val cut : ?n:int -> string -> string list
Split a string into a list of strings containing each one n characters of the input string (by default n=1). Examples:

# cut "aabbc";;
  : string list = ["a"; "a"; "b"; "b"; "c"]

# cut ~n:2 "aabbc";;
  : string list = ["aa"; "bb"; "c"]

# cut ~n:3 "aabbc";;
  : string list = ["aab"; "bc"]

val to_charlist : string -> char list
Similar to cut ~n:1 but returns the list of characters (instead of strings) of the input string. Example:
# to_charlist "aaabbc";;
  : char list = ['a'; 'a'; 'a'; 'b'; 'b'; 'c']

val split_old : ?d:char -> string -> string list
val split : ?squeeze:bool -> ?d:char -> string -> string list
Split a string into a list of strings using a char delimiter (space (blank) by default). By default squeeze=true, which means that delimiter repetitions are considered as single occurrences. The empty string is converted into the empty list. Example:
# split "aaa bbb ccc";;
  : string list = ["aaa"; "bbb"; "ccc"]

# split "aaa   bbb ccc";;
  : string list = ["aaa"; "bbb"; "ccc"]

# split ~squeeze:false "aaa   bbb ccc";;
  : string list = ["aaa"; ""; ""; "bbb"; "ccc"]

val merge : string -> string -> string -> string
Merge two strings with a string separator. The call merge sep x y is simply equivalent to x^sep^y. However, the partial application merge sep may be useful for defining a string list folding (see the next section Folding and the examples in the subsection Common foldings ).
val quote : ?l:string -> ?r:string -> string -> string
Quote a string using a prefix l (by default l="'") and a suffix r (by default r="'").
val assemble : string -> string -> string -> string
Assemble a string with a prefix and a suffix but only if it is not empty, else return the empty string ignoring the given prefix and suffix.
val of_charlist : char list -> string
Convert a list of chars in a string.
# of_charlist ['h';'e';'l';'l';'o'];;
  : string = "hello"

type binop = string -> string -> string 
Curryfied binary operation on strings.
val big : binop -> string list -> string
The folding of string lists is simply a List.fold_left specialization:

This function is adequate for most common cases. Use the module Big when maximum generality is requested.
val merge_map : ?sep:string -> ('a -> string) -> 'a list -> string
merge_map f l maps the function f on the list l then merge the result with the separator (sep=" " by default).
module Fold: sig .. end
Examples of applications of big constructor in conjonction with the merge function.
val merge_fields : string -> int list -> string list -> string
Merge fields with a separator. Example:
# merge_fields "/" [2;4] ["aaa";"bbb";"ccc";"ddd";"eee"] ;;
  : string = "ccc/eee"

type line = string 
A line is a string terminating with a newline '\n'.
val to_line : line -> line
Convert a string in a StringExtra.Extra.line just adding a newline if needed. The function StringExtra.Extra.chop may be used as inverse.

Example:

# to_line "hello";;
  : line = "hello\n"

# to_line "hello\n";;
  : line = "hello\n"

module Text: sig .. end
Converting raw text to list of strings and vice-versa.
val chop : string -> string
Remove from the input string the last chars in the set ['\n','\t',' ']. Similar to the rstrip Python function. Example:
# chop "hell o \t\n";;
  : string = "hell o"

val rstrip : string -> string
Alias for Python fans.
val lstrip : string -> string
As StringExtra.Extra.chop but at left side.
val strip : string -> string
As StringExtra.Extra.chop but for both sides.