Char.Ascii(3)
π NAME π
Char.Ascii β ASCII character set support.
okay so this is the OCaml library page for Char.Ascii, bestie, and it's literally all about ASCII character set support. tiny module, main character energy π
π§ MODULE π§
Module Char.Ascii
π DOCUMENTATION π
Module Ascii : sig end
ASCII character set support.
These functions give meaning to the integers [ 0x00 ; 0x7F ] of the ASCII character set.
Since the UTF-8 encoding of Unicode has the same encoding and character semantics (U+0000 to U+001F) for these bytes, the functions can be safely used on elements of UTF-8 encoded string and bytes values. However, the functions only deal with ASCII-related matters. For example, the notion of Unicode whitespace is much larger than the ASCII whitespace determined by Char.Ascii.is_white.
Since 5.4 β¨
π Characters π
val min : charβminis'\x00'.val max : charβmaxis'\x7F'.
πΈ Predicates πΈ
val is_valid : char -> boolβis_valid cistrueif and only ifcis an ASCII character, that is a byte in the range[ Char.Ascii.min ; Char.Ascii.max ].val is_upper : char -> boolβis_upper cistrueif and only ifcis an ASCII uppercase letter'A'to'Z', that is a byte in the range[ 0x41 ; 0x5A ].val is_lower : char -> boolβis_lower cistrueif and only ifcis an ASCII lowercase letter'a'to'z', that is a byte in the range[ 0x61 ; 0x7A ].val is_letter : char -> boolβis_letter cisChar.Ascii.is_lower c || Char.Ascii.is_upper c. that's the whole rule, no cap.val is_alphanum : char -> boolβis_alphanum cisChar.Ascii.is_letter c || Char.Ascii.is_digit c.val is_white : char -> boolβis_white cistrueif and only ifcis an ASCII white space character, and that means one of: tab'\t'(0x09), newline'\n'(0x0A), vertical tab (0x0B), form feed (0x0C), carriage return'\r'(0x0D) or space' '(0x20). iconic little list.val is_blank : char -> boolβis_blank cistrueif and only ifcis an ASCII blank character, that is either space' '(0x20) or tab'\t'(0x09).val is_graphic : char -> boolβis_graphic cistrueif and only ifcis an ASCII graphic character, that is a byte in the range[ 0x21 ; 0x7E ].val is_print : char -> boolβis_print cisChar.Ascii.is_graphic c || c = ' '.val is_control : char -> boolβis_control cistrueif and only ifcis an ASCII control character, that is a byte in the range[ 0x00 ; 0x1F ]or0x7F.
π Decimal digits π
val is_digit : char -> boolβis_digit cistrueif and only ifcis an ASCII decimal digit'0'to'9', that is a byte in the range[ 0x30 ; 0x39 ].val digit_to_int : char -> intβdigit_to_int cis the numerical value of a digit that satisfiesChar.Ascii.is_digit. RaisesInvalid_argumentifChar.Ascii.is_digit cisfalse. so don't feed it nonsense, bestie πval digit_of_int : int -> charβdigit_of_int nis an ASCII decimal digit for the decimal valueabs (n mod 10).
π¦ Hexadecimal digits π¦
val is_hex_digit : char -> boolβis_hex_digit cistrueif and only ifcis an ASCII hexadecimal digit'0'to'9','a'to'f'or'A'to'F', that is a byte in one of the ranges[ 0x30 ; 0x39 ],[ 0x41 ; 0x46 ],[ 0x61 ; 0x66 ].val hex_digit_to_int : char -> intβhex_digit_to_int cis the numerical value of a digit that satisfiesChar.Ascii.is_hex_digit. RaisesInvalid_argumentifChar.Ascii.is_hex_digit cisfalse.val lower_hex_digit_of_int : int -> charβlower_hex_digit_of_int nis a lowercase ASCII hexadecimal digit for the hexadecimal valueabs (n mod 16).val upper_hex_digit_of_int : int -> charβupper_hex_digit_of_int nis an uppercase ASCII hexadecimal digit for the hexadecimal valueabs (n mod 16).
π Casing transforms π
val uppercase : char -> charβuppercase ciscwith ASCII characters'a'to'z'respectively mapped to uppercase characters'A'to'Z'. Other characters are left untouched.val lowercase : char -> charβlowercase ciscwith ASCII characters'A'to'Z'respectively mapped to lowercase characters'a'to'z'. Other characters are left untouched.
this page is brought to you by OCamldoc, dated 2026-06-22 β bye bestie, go have the cutest little ASCII era π β¨
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms