Skip to main content
Version: 2.5.x (dev)

String

%

pattern % [...,(k,v),...] changes in the pattern occurrences of:

  • $(k) into v
  • `$(if $(k2),"a","b") into "a" if k2 is found in the list, "b" otherwise.

Type:

(string, [string * string]) -> string

Arguments:

  • (unlabeled) (of type string)
  • (unlabeled) (of type [string * string])

^

Concatenate strings.

Type:

(string, string) -> string

Arguments:

  • (unlabeled) (of type string)
  • (unlabeled) (of type string)

bool_of_string

Convert a string to a bool. Raises error.failure("a string to a bool") if conversion fails and default is null

Type:

(string, ?default : bool?) -> bool

Arguments:

  • (unlabeled) (of type string)
  • default (of type bool?, which defaults to null)

float_of_string

Convert a string to a float. Raises error.failure("a string to a float") if conversion fails and default is null

Type:

(string, ?default : float?) -> float

Arguments:

  • (unlabeled) (of type string)
  • default (of type float?, which defaults to null)

int_of_string

Convert a string to a int. Raises error.failure("a string to a int") if conversion fails and default is null

Type:

(string, ?default : int?) -> int

Arguments:

  • (unlabeled) (of type string)
  • default (of type int?, which defaults to null)

irc.channel

Contents of an IRC channel.

Type:

(?server : string, ?port : int, ?channel : string, ?nick : string,
?limit : int) -> () -> string

Example:

# Display messages in the #liquidsoap-test room over a video
s = single("test.mp4")
s = video.add_text.native(irc.channel(channel="#liquidsoap-test"), s)

Arguments:

  • server (of type string, which defaults to "irc.libera.chat"): IRC server.
  • port (of type int, which defaults to 6667): Port for IRC server.
  • channel (of type string, which defaults to "#liquidsoap"): IRC chan to join.
  • nick (of type string, which defaults to "liquidbot"): Nickname.
  • limit (of type int, which defaults to 10): Limit to n last messages

json.object

Create a generic json object

Type:

() -> json

Methods:

  • add (of type (string, 'a) -> unit): Add or replace a new key/value pair to the object.
  • remove (of type (string) -> unit): Remove a key from the object. Does not nothing if the key does not exist.
  • stringify (of type (?compact : bool, ?json5 : bool) -> string): Render object as json string.

json.stringify

Convert a value to JSON. If the value cannot be represented as JSON (for instance a function), a error.json exception is raised.

Type:

(?compact : bool, ?json5 : bool, 'a) -> string

Arguments:

  • compact (of type bool, which defaults to false): Output compact text.
  • json5 (of type bool, which defaults to false): Use json5 extended spec.
  • (unlabeled) (of type 'a)

json.value

Create a generic json value

Type:

('a) -> json

Arguments:

  • (unlabeled) (of type 'a)

metadata.id3v2.render

Return a string representation of a id3v2 metadata tag

Type:

([string * string], ?version : int) -> string

Arguments:

  • (unlabeled) (of type [string * string])
  • version (of type int, which defaults to 3): Tag version. One of: 3 or 4

metadata.parse.amplify

Parse an amplify metadata. Parsing is the same as in the amplify operator. Metadata can be of the form: " dB" for a decibel-based value or "" for a linear-based value. Returns a decibel value.

Type:

(string) -> float

Arguments:

  • (unlabeled) (of type string)

regexp

Create a regular expression

Type:

(?flags : [string], string) -> regexp

Arguments:

  • flags (of type [string], which defaults to []): List of flags. Valid flags: "i", "g", "m".
  • (unlabeled) (of type string)

Methods:

  • exec (of type (string) -> [int * string].{groups : [string * string]}): Extract substrings from a string. Returns a list of (index,value). If the list does not have a pair associated to some index, it means that the corresponding pattern was not found.
  • replace (of type (((string) -> string), string) -> string): Replace substrings matched by the regexp by another string returned by a function.
  • split (of type (string) -> [string]): Split a string on the given regular expression.
  • test (of type (string) -> bool): Match a string with the expressionn.

runtime.memory.prettify_bytes

Returns a human-redable description of an amount of bytes.

Type:

(?float_printer : ((float) -> string)?, ?signed : bool?, ?bits : bool?,
?binary : bool?, int) -> string

Arguments:

  • float_printer (of type ((float) -> string)?, which defaults to null)
  • signed (of type bool?, which defaults to null)
  • bits (of type bool?, which defaults to null)
  • binary (of type bool?, which defaults to null)
  • (unlabeled) (of type int)

string

Return the representation of a value.

Type:

(?fields : bool, ?print_binary : bool, 'a) -> string

Arguments:

  • fields (of type bool, which defaults to false): Show toplevel fields around the value.
  • print_binary (of type bool, which defaults to true): When false, strings marked as binary are masked and returned as <string>
  • (unlabeled) (of type 'a)

string.annotate.parse

Parse a string of the form <key>=<value>,...:<uri> as given by the annotate: protocol

Type:

(string) -> [string * string] * string

Arguments:

  • (unlabeled) (of type string)

string.base64.decode

Decode a Base64 encoded string.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

string.base64.encode

Encode a string in Base64.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

string.capitalize

Return a string with the first character set to upper case (capitalize), or to lower case (uncapitalize).

Type:

(?capitalize : bool, ?space_sensitive : bool, string) -> string

Arguments:

  • capitalize (of type bool, which defaults to true): Capitalize if true, uncapitalize otherwise
  • space_sensitive (of type bool, which defaults to true): Capitalize each space separated sub-string.
  • (unlabeled) (of type string)

string.case

Convert a string to lower or upper case.

Type:

(?lower : bool, string) -> string

Arguments:

  • lower (of type bool, which defaults to true): Convert to lower case if true and uppercase otherwise.
  • (unlabeled) (of type string)

string.char

Create a string with one character.

Type:

(int) -> string

Arguments:

  • (unlabeled) (of type int): Code of the character.

string.chars

Split string into characters. Raises error.invalid on errors.

Type:

(?encoding : string?, string) -> [string]

Arguments:

  • encoding (of type string?, which defaults to null): Encoding used to split characters. Should be one of: "utf8" or "ascii"
  • (unlabeled) (of type string)

string.compare

Compare strings in lexicographical order.

Type:

(string, string) -> int

Arguments:

  • (unlabeled) (of type string)
  • (unlabeled) (of type string)

string.concat

Concatenate strings.

Type:

(?separator : string, [string]) -> string

Arguments:

  • separator (of type string, which defaults to "")
  • (unlabeled) (of type [string])

string.digest

Return an MD5 digest for the given string.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

string.escape

Escape special characters in an string. By default, the string is assumed to be "utf8" encoded and is escaped following JSON and javascript specification.

Type:

(?special_char : ((encoding : string, string) -> bool)?,
?escape_char : ((encoding : string, string) -> string)?,
?encoding : string?, string) -> string

Arguments:

  • special_char (of type ((encoding : string, string) -> bool)?, which defaults to null): Return true if the given character (passed as a string) should be escaped. Defaults to control characters for "utf8" and control characters and any character above \x7E (non-printable characters) for "ascii".
  • escape_char (of type ((encoding : string, string) -> string)?, which defaults to null): Function used to escape a character. Defaults to \xxx octal notation for "ascii" and \uxxxx hexadecimal notation for "utf8".
  • encoding (of type string?, which defaults to null): One of: "ascii" or "utf8". If null, utf8 is tried first and ascii is used as a fallback if this fails.
  • (unlabeled) (of type string)

string.escape.all

Escape each character in the given string using a specific escape sequence.

Type:

(?format : string, string) -> string

Arguments:

  • format (of type string, which defaults to "utf8"): Escape format. One of: "octal", "hex" or "utf8".
  • (unlabeled) (of type string)

string.escape.special_char

Default function to detect characters to escape. See string.escape for more details.

Type:

(?encoding : string, string) -> bool

Arguments:

  • encoding (of type string, which defaults to "utf8"): One of: "ascii" or "utf8".
  • (unlabeled) (of type string)

string.float

String representation of a float.

Type:

(?decimal_places : int?, float) -> string

Arguments:

  • decimal_places (of type int?, which defaults to null): Number of decimal places.
  • (unlabeled) (of type float)

string.hex_of_int

Hexadecimal representation of an integer.

Type:

(?pad : int, int) -> string

Arguments:

  • pad (of type int, which defaults to 0): Minimum length in digits (pad on the left with zeros in order to reach it).
  • (unlabeled) (of type int)

string.id

Generate an identifier with given operator name.

Type:

(?category : string, string) -> string

Arguments:

  • category (of type string, which defaults to ""): Category
  • (unlabeled) (of type string): Operator name.

string.index

Index where a substring occurs in a string. The function returns -1 if the substring is not present

Type:

(substring : string, string) -> int

Arguments:

  • substring (of type string): Substring to look for.
  • (unlabeled) (of type string): String in which to look.

string.length

Return the string's length using the given encoding. Raises error.invalid on errors.

Type:

(?encoding : string?, string) -> int

Arguments:

  • encoding (of type string?, which defaults to null): Encoding used to split characters. Should be one of: "utf8" or "ascii"
  • (unlabeled) (of type string)

string.make

Create a string of a given length using the given character.

Type:

(?char_code : int, int) -> string

Arguments:

  • char_code (of type int, which defaults to 32): Character code.
  • (unlabeled) (of type int): String length.

string.nth

Retrieve a character in a string. Raises error.not_found if character does not exist.

Type:

(string, int) -> int

Example:

c = string.nth("abcde", 2)
print(c) # should print 99 which is the ascii code for "c"

Arguments:

  • (unlabeled) (of type string): String to look into.
  • (unlabeled) (of type int): Index of the character.

string.recode

Convert a string. Effective only if Camomile is enabled.

Type:

(?in_enc : string?, ?out_enc : string, string) -> string

Arguments:

  • in_enc (of type string?, which defaults to null): Input encoding. Autodetected if null.
  • out_enc (of type string, which defaults to "UTF-8"): Output encoding.
  • (unlabeled) (of type string)

string.sub

Get a substring of a string. Returns "" if no such substring exists.

Type:

(string, start : int, ?encoding : string?, length : int) -> string

Arguments:

  • (unlabeled) (of type string)
  • start (of type int): Return a sub string starting at this position. First position is 0.
  • encoding (of type string?, which defaults to null): Encoding used to split characters. Should be one of: "utf8" or "ascii"
  • length (of type int): Return a sub string of length characters.

string.trim

Return a string without leading and trailing whitespace.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

string.unescape

This function is the inverse of string.escape.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

url.decode

Decode an encoded url (e.g. "%20" becomes " ").

Type:

(?plus : bool, string) -> string

Arguments:

  • plus (of type bool, which defaults to true)
  • (unlabeled) (of type string)

url.encode

Encode an url (e.g. " " becomes "%20").

Type:

(?plus : bool, string) -> string

Arguments:

  • plus (of type bool, which defaults to true)
  • (unlabeled) (of type string)

xml.stringify

Convert a value to XML. If the value cannot be represented as XML (for instance a function), a error.xml exception is raised.

Type:

(?compact : bool, 'a) -> string

Arguments:

  • compact (of type bool, which defaults to false): Output compact text.
  • (unlabeled) (of type 'a)

yaml.stringify

Convert a value to YAML. If the value cannot be represented as YAML (for instance a function), a error.yaml exception is raised.

Type:

(?scalar_style : string, ?layout_style : string, 'a) -> string

Arguments:

  • scalar_style (of type string, which defaults to "any"): Scalar style. One of: "any", "plain", "single_quoted", "double_quoted", "literal" or "folded".
  • layout_style (of type string, which defaults to "any"): Layout style. One of: "any", "block" or "flow".
  • (unlabeled) (of type 'a)