Module Char.Ascii
US-ASCII character support.
The following functions act only on US-ASCII code points, that is on the bytes in range [0x00
;0x7F
]. The functions can be safely used on UTF-8 encoded strings, they will of course only deal with US-ASCII related matters.
References.
- Vint Cerf. ASCII format for Network Interchange. RFC 20, 1969.
Decimal and hexadecimal digits
val is_digit : char -> bool
is_digit c
istrue
iffc
is an US-ASCII digit'0'
...'9'
, that is a byte in the range [0x30
;0x39
].
val is_hex_digit : char -> bool
is_hex_digit c
istrue
iffc
is an US-ASCII hexadecimal digit'0'
...'9'
,'a'
...'f'
,'A'
...'F'
, that is a byte in one of the ranges [0x30
;0x39
], [0x41
;0x46
], [0x61
;0x66
].
val hex_digit_value : char -> int
hex_digit_value c
is the numerical value of a digit that satisfiesis_hex_digit
.- raises Invalid_argument
if
is_hex_digit c
isfalse
.
Predicates
val is_valid : char -> bool
is_valid c
istrue
iffc
is an US-ASCII character, that is a byte in the range [0x00
;0x7F
].
val is_upper : char -> bool
is_upper c
istrue
iffc
is an US-ASCII uppercase letter'A'
...'Z'
, that is a byte in the range [0x41
;0x5A
].
val is_lower : char -> bool
is_lower c
istrue
iffc
is an US-ASCII lowercase letter'a'
...'z'
, that is a byte in the range [0x61
;0x7A
].
val is_white : char -> bool
is_white c
istrue
iffc
is an US-ASCII white space character, that is one of space' '
(0x20
), tab'\t'
(0x09
), newline'\n'
(0x0A
), vertical tab (0x0B
), form feed (0x0C
), carriage return'\r'
(0x0D
).
val is_blank : char -> bool
is_blank c
istrue
iffc
is an US-ASCII blank character, that is either space' '
(0x20
) or tab'\t'
(0x09
).