Module Kwformat

module Kwformat: sig .. end

Text-formatting functions


Author(s): Keith Waclena

val j : string -> string list -> string
Join elements of list on a string separator but only for "non-blank" elements

Nand's format::j. Bug: right now "blank" is defined as just "" rather than nand's "whitespace".
Returns string of list elements joined together, omitting "blanks"

sep : string to use as separator
val commafy : ?comma:string -> int -> string
convert int n to string, inserting commas as appropriate

E.g.: (commafy 12021457) = "12,021,457"
Returns formatted string

comma : string to use as comma; default: ","
n : number to convert
val commafylist : ?comma:string -> ?n:int -> string -> string
commafylist ?comma ?n str: add commas to a string, presumably of digits

Useful for bignums, etc.

E.g.: (commafy "12021457") = "12,021,457"
Returns commafied string

comma : string to use as comma; default: ","
n : how man digits in comma group
val columnate : ?header:string list ->
?bar:char ->
?sep:string ->
?maxwidth:int -> ?widths:int list -> string list list -> string list
columnate ?header ?bar ?sep ?maxwidth ?widths matrix: format a list of lists of strings in neat columns

Formats a "matrix" of strings e.g.:

[["footstep"; "obovoid"; "suitor"] ;["fibration"; "triadist"; "homeochronous"] ;["similitude"; "hackberry"; "undignifiedly"] ]

into a list of strings, each of which represents a row of the matrix, with the items padded out so that you have equal width columns when printed, e.g. via:

List.iter print_endline (columnate matrix)
Raises Invalid_argument if matrix is non-rectangular

header : a list of strings to use as column labels; will be added as the first line of the result
sep : string that separates columns (default: " ")
maxwidth : maximum width of line; longer lines will be truncated on the right (default: None)
widths : list item i is the max allowable width of column i; if the actual column is larger, it is truncated to this width; but if the integer is negative, it is ignored i.e. the actual computed max column width is used for this column; widths can be shorter than the actual number of columns; missing columns get their computed max width (default: [])
matrix : list of list of strings
val digits : ?base:int -> int -> int
how many digits does n require in base b?
base : base (currently restricted to 10)
n : number
val plural : ?plural:string -> ?suffix:string -> string -> int -> string
possibly return the plural of a noun, depending on a quantity

Only works for languages like English, with a simple plural suffix and occasional exceptions.

Examples:

# List.map (fun n -> n,plural "cat" n) (~-1--2);;
\- [(-1, "cats"); (0, "cats"); (1, "cat"); (2, "cats")]
# List.map (fun n -> n,plural ~plural:"oxen" "ox" n) (~-1--2);;
\- [(-1, "oxen"); (0, "oxen"); (1, "ox"); (2, "oxen")]
#
 

plural : the plural of noun, when noun is irregular
suffix : the plural suffix for regular nouns (default: "s")
noun : the noun in question
n : the quantity
module Units: sig .. end
Format a quantity in terms of some units