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 β€” min is '\x00'.
  • val max : char β€” max is '\x7F'.

🌸 Predicates 🌸

  • val is_valid : char -> bool β€” is_valid c is true if and only if c is an ASCII character, that is a byte in the range [ Char.Ascii.min ; Char.Ascii.max ].
  • val is_upper : char -> bool β€” is_upper c is true if and only if c is an ASCII uppercase letter 'A' to 'Z', that is a byte in the range [ 0x41 ; 0x5A ].
  • val is_lower : char -> bool β€” is_lower c is true if and only if c is an ASCII lowercase letter 'a' to 'z', that is a byte in the range [ 0x61 ; 0x7A ].
  • val is_letter : char -> bool β€” is_letter c is Char.Ascii.is_lower c || Char.Ascii.is_upper c. that's the whole rule, no cap.
  • val is_alphanum : char -> bool β€” is_alphanum c is Char.Ascii.is_letter c || Char.Ascii.is_digit c.
  • val is_white : char -> bool β€” is_white c is true if and only if c is 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 c is true if and only if c is an ASCII blank character, that is either space ' ' (0x20) or tab '\t' (0x09).
  • val is_graphic : char -> bool β€” is_graphic c is true if and only if c is an ASCII graphic character, that is a byte in the range [ 0x21 ; 0x7E ].
  • val is_print : char -> bool β€” is_print c is Char.Ascii.is_graphic c || c = ' '.
  • val is_control : char -> bool β€” is_control c is true if and only if c is an ASCII control character, that is a byte in the range [ 0x00 ; 0x1F ] or 0x7F.

πŸ“ Decimal digits πŸ“

  • val is_digit : char -> bool β€” is_digit c is true if and only if c is 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 c is the numerical value of a digit that satisfies Char.Ascii.is_digit. Raises Invalid_argument if Char.Ascii.is_digit c is false. so don't feed it nonsense, bestie 😭
  • val digit_of_int : int -> char β€” digit_of_int n is an ASCII decimal digit for the decimal value abs (n mod 10).

πŸ¦‹ Hexadecimal digits πŸ¦‹

  • val is_hex_digit : char -> bool β€” is_hex_digit c is true if and only if c is 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 c is the numerical value of a digit that satisfies Char.Ascii.is_hex_digit. Raises Invalid_argument if Char.Ascii.is_hex_digit c is false.
  • val lower_hex_digit_of_int : int -> char β€” lower_hex_digit_of_int n is a lowercase ASCII hexadecimal digit for the hexadecimal value abs (n mod 16).
  • val upper_hex_digit_of_int : int -> char β€” upper_hex_digit_of_int n is an uppercase ASCII hexadecimal digit for the hexadecimal value abs (n mod 16).

πŸ‘‘ Casing transforms πŸ‘‘

  • val uppercase : char -> char β€” uppercase c is c with ASCII characters 'a' to 'z' respectively mapped to uppercase characters 'A' to 'Z'. Other characters are left untouched.
  • val lowercase : char -> char β€” lowercase c is c with 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