From b95e2de65b81e86c4f5be9665b1b9f0b9538051e Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 4 Jan 2025 09:18:51 -0500 Subject: [PATCH] Added functions to the Char module to check common character properties. --- src/core/CCChar.ml | 9 +++++++++ src/core/CCChar.mli | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/core/CCChar.ml b/src/core/CCChar.ml index 5936830a..402f886e 100644 --- a/src/core/CCChar.ml +++ b/src/core/CCChar.ml @@ -23,3 +23,12 @@ module Infix = struct end include Infix + +let is_uppercase_ascii c = c > '\064' && c < '\091' +let is_lowercase_ascii c = c > '\096' && c < '\123' + +let is_letter_ascii c = + (is_lowercase_ascii [@inlined]) c || (is_uppercase_ascii [@inlined]) c + +let is_digit_ascii c = c > '\047' && c < '\058' +let is_whitespace_ascii c = c = '\032' || (c > '\008' && c < '\014') diff --git a/src/core/CCChar.mli b/src/core/CCChar.mli index d18eb48e..28fd4bcf 100644 --- a/src/core/CCChar.mli +++ b/src/core/CCChar.mli @@ -40,6 +40,32 @@ val pp_buf : Buffer.t -> t -> unit val pp : Format.formatter -> t -> unit (** Renamed from [print] since 2.0. *) +val is_uppercase_ascii : t -> bool +(** [is_uppercase_ascii c] is true exactly when [c] is an + uppercase ASCII character, i.e. ['\064'] < [c] < ['\091']. + @since 3.16 *) + +val is_lowercase_ascii : t -> bool +(** [is_lowercase_ascii c] is true exactly when [c] is a + lowercase ASCII character, i.e. ['\097'] < [c] < ['\123']. + @since 3.16 *) + +val is_letter_ascii : t -> bool +(** [is_letter_ascii c] is true exactly when [c] is an ASCII + letter, i.e. [is_uppercase_ascii c || is_lowercase_ascii c]. + @since 3.16 *) + +val is_digit_ascii : t -> bool +(** [is_digit_ascii c] is true exactly when [c] is an + ASCII digit, i.e. ['\047'] < [c] < ['\058']. + @since 3.16 *) + +val is_whitespace_ascii : t -> bool +(** [is_whitespace_ascii c] is true exactly when [c] is an ASCII + whitespace character as defined by Unicode, i.e. either [c = ' '] + or ['\008'] < [c] < ['\014']. + @since 3.16 *) + (** {2 Infix Operators} @since 3.3 *)