Module Astring.String.Ascii

module Ascii: sig .. end

US-ASCII string support.

References.


Predicates

val is_valid : string -> bool

is_valid s is true iff only for all indices i of s, s.[i] is an US-ASCII character, i.e. a byte in the range [0x00;0x1F].

Casing transforms

The following functions act only on US-ASCII code points that is on bytes in range [0x00;0x7F], leaving any other byte intact. The functions can be safely used on UTF-8 encoded strings; they will of course only deal with US-ASCII casings.

val uppercase : string -> string

uppercase s is s with US-ASCII characters 'a' to 'z' mapped to 'A' to 'Z'.

val lowercase : string -> string

lowercase s is s with US-ASCII characters 'A' to 'Z' mapped to 'a' to 'z'.

val capitalize : string -> string

capitalize s is like Astring.String.Ascii.uppercase but performs the map only on s.[0].

val uncapitalize : string -> string

uncapitalize s is like Astring.String.Ascii.lowercase but performs the map only on s.[0].

Escaping to printable US-ASCII

val escape : string -> string

escape s is s with:

val unescape : string -> string option

unescape s unescapes what Astring.String.Ascii.escape did. The letters of hex escapes can be upper, lower or mixed case, and any two letter hex escape is decoded to its corresponding byte. Any other escape not defined by Astring.String.Ascii.escape or truncated escape makes the function return None.

The invariant unescape (escape s) = Some s holds.

val escape_string : string -> string

escape_string s is like Astring.String.Ascii.escape except it escapes s according to OCaml's lexical conventions for strings with:

val unescape_string : string -> string option

unescape_string is to Astring.String.Ascii.escape_string what Astring.String.Ascii.unescape is to Astring.String.Ascii.escape and also additionally unescapes the sequence "\\'" (0x5C,0x27) to "'" (0x27).