module type NATIVE_CHARACTER = BASIC_CHARACTER
with type t = char
The minimal API implemented by characters.
type
t
The type representing the character.
val of_native_char : char -> t option
Import a native char
, returns None
if the character is not
representable.
val of_int : int -> t option
Import an integer, returns None
if there is no character for
that value.
val to_int : t -> int
Returns the integer representation of the character.
val size : t -> int
val write_to_native_string : t ->
buf:String.t -> index:int -> (int, [> `out_of_bounds ]) Sosa.result
write_to_native_string c ~buf ~index
serializes
the character
c
at position
index
in the native string
buf
(writing
size c
units). Note, as with
Sosa.BASIC_CHARACTER.size
that the
meaning of
index
is implementation dependent (can be the
index-th byte, the
index-th bit, etc.).
val to_native_string : t -> String.t
to_native_string c
creates a string containing the
serialization of the character c
(if size c
is not a
multiple of 8, the end-padding is undefined).
val read_from_native_string : buf:String.t -> index:int -> (t * int) option
Read a character at a given index
in a native string, returns
Some (c, s)
, the character c
and the number of units read s
,
or None
if there is no representable/valid character at that
index.
val to_string_hum : t -> String.t
Convert the character to a human-readable native string (in the
spirit of sprintf "%s"
).
val compare : t -> t -> int
Comparison function (as expected by most common functors in the
ecosystem).
val is_whitespace : t -> bool
Tell whether a character is considered whitespace.