package frama-c

  1. Overview
  2. Docs

doc/frama-c.kernel/Frama_c_kernel/Rich_text/index.html

Module Frama_c_kernel.Rich_text

Text enriched with semantic tags

This module provides a rich text type that represents a string of characters enriched by semantic tags. It is intended to provide a way to store texts that can be output in several format, for instance in html or using ANSI sequences in terminals. When the text is pretty printed, the semantic tags are output in the usual way on the formatter (which can translate the semantic tags to html markup for instance). See Format for more details about semantic tags.

  • before 32.0-Germanium

    the buffer functions were used to build plain strings instead of rich text

type t

Text with tags

val empty : t

empty is the empty text, containing neither plain text nor tags.

val is_empty : t -> bool

is_empty text returns true if text is empty. A rich text containing only semantic tags is not considered empty.

val of_string : string -> t

of_string s returns a plain text equal to s with no semantic tags.

val size : t -> int

length text returns the number of characters in the text.

val plain : t -> string

plain text returns the plain string in the text (without any tag).

val contains : t -> char -> bool

contains text c returns whether text contains the character c.

val index : t -> char -> int

index text c finds the first index of character c.

val sub : ?start_pos:int -> ?end_pos:int -> t -> t

truncate ~start_pos ~end_pos text truncate the text text to the range from start_pos (included, default to 0) to end_pos (excluded, default to the text size). All tags outside this range are removed.

type truncation = [
  1. | `None
  2. | `Left of int
  3. | `Middle of int
  4. | `Right of int
]

Indicates the total available space and the position of the truncation

val pretty : ?truncate:truncation -> ?ellipsis:string -> Format.formatter -> t -> unit

pretty fmt text pretty-prints the text onto the given formatter fmt, with the semantic tags. The original text has been already laid out with respect to horizontal and vertical boxes, and this layout will be output as-it-is into the formatter.

  • parameter truncate

    defines the maximum size of the printed text and the position of the truncation if the text exceed this size

  • parameter ellipsis

    when truncate is given and the text length is bigger than the specified size, then ellipsis is printed instead of the truncated part.

val to_string : ?prefix:(Format.formatter -> unit) -> ?suffix:(Format.formatter -> unit) -> ?truncate:truncation -> ?ellipsis:string -> t -> string

Pretty prints the text into a string

  • parameter prefix

    a pretty printing function called at the beginning of the print

  • parameter suffix

    a pretty printing function called at the end of the print

  • parameter truncate

    defines the maximum size of the string and the position of the truncation if the text exceed this size

  • parameter ellipsis

    when truncate is given and the text length is bigger than the specified size, then ellipsis is printed instead of the truncated part.

val need_truncation : ?truncate:truncation -> t -> bool

need_truncation ?truncate text returns whether to_string, pretty or sprintf will truncate the text.

Buffers for building rich text

type buffer

Buffer for creating rich text.

The buffer grows on demand, but is protected against huge messages. Maximal size is around 2 billions ASCII characters, which should be enough to store more than 25kloc source text.

module Buffer : sig ... end

Direct formatting

val sprintf : ?indent:int -> ?margin:int -> ?trim:bool -> ?truncate:truncation -> ?ellipsis:string -> ('a, Format.formatter, unit, string) format4 -> 'a

Pretty prints to a string.

  • parameter indent

    defines the maximum indentation as in create, defaults to 20

  • parameter margin

    defines the right-margin as in create, defaults to 40

  • parameter trim

    if set to true, remove leading and trailing whitespace (including tabulations, line feed and carriage returns)

  • parameter truncate

    defines the maximum size of the printed text and the position of the truncation if the (trimmed) text exceed this size

  • parameter ellipsis

    when truncate is given and the (trimmed) text length is bigger than the specified size, then ellipsis is printed instead of the truncated part.

val mprintf : ?indent:int -> ?margin:int -> ?trim:bool -> ('a, Format.formatter, unit, t) format4 -> 'a

Pretty prints to a rich text.

  • parameter indent

    defines the maximum indentation as in create

  • parameter margin

    defines the right-margin as in create

  • parameter trim

    if set to true, remove leading and trailing whitespace (including tabulations, line feed and carriage returns)