12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091(** An [ENRICHER] is a type that represents a capability that
can be added to strings. *)moduletypeENRICHER=sigtypetval(=):t->t->boolvalenrich:t->string->stringendmoduletypeTYPE=sig(** The type of a rich string. *)(** The enricher. *)moduleEnricher:ENRICHER(** The type of a rich string. *)typet=|Empty|Stringofstring|EnrichedofEnricher.t*t|Joinoft*tlist(** [rs1 = rs2] determines whether [rs1] and [rs2] are equal.
{b IMPORTANT:} no pruning or optimization is performed.
This means that two rich strings that render the same
might not be considered equal. *)val(=):t->t->bool(** [empty] is the identity string with respect to {!( ++ )}. *)valempty:t(** [rs1 ++ rs2] appends [rs2] at the end of [rs1].
It is equivalent to the built-in string operator [^].
{[
# print (String "hello" ++ String "world")
"helloworld"
- : unit = ()
]} *)val(++):t->t->t(** [string s] lifts the built-in string [s] to the enriched
world.
For example, if the enricher is an ANSI style type, this
enables the ability to stylize [s]. *)valstring:string->t(** [enrich enrichment rs] adds the [enrichment] to the rich
string [rs].
For example, if the enricher is an ANSI style type, this
translates to adding a new style to [s]. *)valenrich:Enricher.t->t->t(** [join ?on:sep rss] concatenates all [rss] into one,
separated by [sep]. By default, [sep] is a single space.
It is equivalent to the built-in string function
[String.concat]. *)valjoin:?on:t->tlist->t(** [flatten rss] concatenates all [rss] into one.
It is equivalent to {!join}[~on:Empty rss]. *)valflatten:tlist->t(** [join_lines rss] concatenates all [rss] into one,
separated by line feeds.
It is equivalent to {!join}[~on:(String "\n") rss]. *)valjoin_lines:tlist->t(** [is_empty rs] tests whether [rs] is [Empty]. *)valis_empty:t->bool(** [is_enriched rs] tests whether [rs] is {i not} just a
plain [String]. *)valis_enriched:t->bool(** [render rs] generates a built-in string such that [rs]
can be used in interfaces that expect strings, e.g. IO. *)valrender:t->string(** [print ?out ?ending rs] prints [rs] in [out], appending
[ending] after. [out] defaults to [stdout] and [ending]
defaults to [Some (String "\n")]. *)valprint:?out:out_channel->?ending:toption->t->unitend