package pyml

  1. Overview
  2. Docs

Interface for Python values of type String, Bytes and Unicode.

val check : Object.t -> bool

check o returns o if o is a Python string (either Bytes or Unicode with Python 3).

val check_bytes : Object.t -> bool

check_bytes o returns o if o is a Python bytes string.

val check_unicode : Object.t -> bool

check_unicode o returns o if o is a Python unicode string.

val format : Object.t -> Object.t -> Object.t

format fmt args returns the formatted Python string from the string format fmt and the arguments args. This is analogous to fmt % args. With Python 2, if fmt is a String, wrapper for PyString_Format. With Python 3 or with Python 2 if fmt is Unicode, wrapper for PyUnicode_Format.

val as_UTF8_string : Object.t -> Object.t
val decode_UTF8 : ?errors:string -> ?size:int -> string -> Object.t

Wrapper for PyUnicode_DecodeUTF8. If size is omitted, the length of the string is used by default.

val decode_UTF16 : ?errors:string -> ?size:int -> ?byteorder:byteorder -> string -> Object.t * byteorder

Wrapper for PyUnicode_DecodeUTF16. If size is omitted, the length of the string is used by default.

val decode_UTF32 : ?errors:string -> ?size:int -> ?byteorder:byteorder -> string -> Object.t * byteorder

Wrapper for PyUnicode_DecodeUTF32. If size is omitted, the length of the string is used by default.

val length : Object.t -> int

length s returns the length of the Python string s. A failure (Failure _) is raised if s is neither a Bytes value nor a Unicode value. With Python 2, if s is a String, wrapper for PyString_Size, and if s is Unicode, wrapper for PyUnicode_GetSize, With Python 3, if s is Bytes, wrapper for PyBytes_Size, and if s is Unicode, wrapper for PyUnicode_GetLength.

val of_string : string -> Object.t

of_string s returns the Python string with the value s. s should be a valid UTF-8 string.

val of_bytes : Stdcompat.bytes -> Object.t

Same as of_string but with an argument of type bytes.

val to_string : Object.t -> string

to_string o returns the string contained in the Python value o. A failure (Failure _) is raised if o is neither a String/Bytes value nor a Unicode value.

val to_bytes : Object.t -> Stdcompat.bytes

Same as to_string but with an a result of type bytes.

val of_unicode : ?size:int -> int array -> Object.t

of_unicode codepoints returns the Python Unicode string with the codepoints codepoints.

val to_unicode : Object.t -> int array

to_unicode s returns the codepoints of the Python Unicode string s.

OCaml

Innovation. Community. Security.