diff options
Diffstat (limited to 'src/csets.rs')
| -rw-r--r-- | src/csets.rs | 158 |
1 files changed, 142 insertions, 16 deletions
diff --git a/src/csets.rs b/src/csets.rs index 3ee5e53..f1b1227 100644 --- a/src/csets.rs +++ b/src/csets.rs @@ -134,6 +134,76 @@ impl CharacterSet for AnyCharacter { } } +/// Contains all Unicode alphabetic characters +#[derive(Debug, Clone, Copy)] +pub struct Alphabetic; + +impl CharacterSet for Alphabetic { + fn contains(&self, ch: char) -> bool { + ch.is_alphabetic() + } +} + +/// Contains all Unicode lowercase characters +#[derive(Debug, Clone, Copy)] +pub struct Lowercase; + +impl CharacterSet for Lowercase { + fn contains(&self, ch: char) -> bool { + ch.is_lowercase() + } +} + +/// Contains all Unicode uppercase characters +#[derive(Debug, Clone, Copy)] +pub struct Uppercase; + +impl CharacterSet for Uppercase { + fn contains(&self, ch: char) -> bool { + ch.is_uppercase() + } +} + +/// Contains all Unicode whitespace characters +#[derive(Debug, Clone, Copy)] +pub struct Whitespace; + +impl CharacterSet for Whitespace { + fn contains(&self, ch: char) -> bool { + ch.is_whitespace() + } +} + +/// Contains all Unicode alphabetic or numeric characters +#[derive(Debug, Clone, Copy)] +pub struct Alphanumeric; + +impl CharacterSet for Alphanumeric { + fn contains(&self, ch: char) -> bool { + ch.is_alphanumeric() + } +} + +/// Contains all Unicode control chartacters +#[derive(Debug, Clone, Copy)] +pub struct Control; + +impl CharacterSet for Control { + fn contains(&self, ch: char) -> bool { + ch.is_control() + } +} + +/// Contains all Unicode numeric characters +#[derive(Debug, Clone, Copy)] +pub struct Numeric; + +impl CharacterSet for Numeric { + fn contains(&self, ch: char) -> bool { + ch.is_numeric() + } +} + /// Contains all ASCII characters #[derive(Debug, Clone, Copy)] pub struct Ascii; @@ -144,23 +214,23 @@ impl CharacterSet for Ascii { } } -/// Contains the ASCII digits, 0-9 +/// Contains all ASCII letters: a-z, A-Z #[derive(Debug, Clone, Copy)] -pub struct AsciiDigits; +pub struct AsciiAlphabetic; -impl CharacterSet for AsciiDigits { +impl CharacterSet for AsciiAlphabetic { fn contains(&self, ch: char) -> bool { - ch.is_ascii_digit() + ch.is_ascii_alphabetic() } } -/// Contains the ASCII whitespace characters +/// Contains all uppercase ASCII letters, A-Z #[derive(Debug, Clone, Copy)] -pub struct AsciiWhitespace; +pub struct AsciiUppercase; -impl CharacterSet for AsciiWhitespace { +impl CharacterSet for AsciiUppercase { fn contains(&self, ch: char) -> bool { - ch.is_ascii_whitespace() + ch.is_ascii_uppercase() } } @@ -174,23 +244,79 @@ impl CharacterSet for AsciiLowercase { } } -/// Contains all uppercase ASCII letters, A-Z +/// Contains all ASCII characters a-z, A-Z, 0-9 #[derive(Debug, Clone, Copy)] -pub struct AsciiUppercase; +pub struct AsciiAlphanumeric; -impl CharacterSet for AsciiUppercase { +impl CharacterSet for AsciiAlphanumeric { fn contains(&self, ch: char) -> bool { - ch.is_ascii_uppercase() + ch.is_ascii_alphanumeric() } } -/// Containes all ASCII letters: a-z, A-Z +/// Contains the ASCII digits, 0-9 #[derive(Debug, Clone, Copy)] -pub struct AsciiLetters; +pub struct AsciiDigits; -impl CharacterSet for AsciiLetters { +impl CharacterSet for AsciiDigits { fn contains(&self, ch: char) -> bool { - ch.is_ascii_alphabetic() + ch.is_ascii_digit() + } +} + +/// Contains the ASCII hexadecimal digits: 0-9, a-f, A-F +#[derive(Debug, Clone, Copy)] +pub struct AsciiHexDigit; + +impl CharacterSet for AsciiHexDigit { + fn contains(&self, ch: char) -> bool { + ch.is_ascii_hexdigit() + } +} + +/// Contains ASCII punctuation characters: +/// +/// - U+0021 ..= U+002F `! " # $ % & ' ( ) * + , - . /` +/// - U+003A ..= U+0040 `: ; < = > ? @` +/// - U+005B ..= U+0060 ``[ \ ] ^ _ ` `` +/// - U+007B ..= U+007E `{ | } ~` +#[derive(Debug, Clone, Copy)] +pub struct AsciiPunctuation; + +impl CharacterSet for AsciiPunctuation { + fn contains(&self, ch: char) -> bool { + ch.is_ascii_punctuation() + } +} + +/// Contains the ASCII graphic characters: `U+0021 (!) ..= U+007E (~)` +#[derive(Debug, Clone, Copy)] +pub struct AsciiGraphic; + +impl CharacterSet for AsciiGraphic { + fn contains(&self, ch: char) -> bool { + ch.is_ascii_graphic() + } +} + +/// Contains the ASCII whitespace characters +#[derive(Debug, Clone, Copy)] +pub struct AsciiWhitespace; + +impl CharacterSet for AsciiWhitespace { + fn contains(&self, ch: char) -> bool { + ch.is_ascii_whitespace() + } +} + +/// Contains the ASCII control characters: +/// `U+0000 (NUL) ..= U+001F (UNIT SEPARATOR)` or `U+007F (DELETE)` +#[derive(Debug, Clone, Copy)] +pub struct AsciiControl; + +impl CharacterSet for AsciiControl { + fn contains(&self, ch: char) -> bool { + ch.is_ascii_control() } } |
