diff options
| author | Botahamec <botahamec@outlook.com> | 2023-07-29 20:33:57 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2023-07-29 20:33:57 -0400 |
| commit | c2cbc9fe6eef6a10a5fd85f363e45bee7d6db9aa (patch) | |
| tree | 3126e804e19f1fb374e28ce779548d2996db67ca /src/csets.rs | |
| parent | 2047a3fca92b5047c5b9caf2b38049489f824447 (diff) | |
Create character sets
Diffstat (limited to 'src/csets.rs')
| -rw-r--r-- | src/csets.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/csets.rs b/src/csets.rs new file mode 100644 index 0000000..ab924dc --- /dev/null +++ b/src/csets.rs @@ -0,0 +1,51 @@ +pub trait CharacterSet { + fn contains(ch: char) -> bool; +} + +pub struct AnyCharacter; + +impl CharacterSet for AnyCharacter { + fn contains(_: char) -> bool { + true + } +} + +pub struct Ascii; + +impl CharacterSet for Ascii { + fn contains(ch: char) -> bool { + ch.is_ascii() + } +} + +pub struct AsciiDigits; + +impl CharacterSet for AsciiDigits { + fn contains(ch: char) -> bool { + ch.is_ascii_digit() + } +} + +pub struct AsciiLowercase; + +impl CharacterSet for AsciiLowercase { + fn contains(ch: char) -> bool { + ch.is_ascii_lowercase() + } +} + +pub struct AsciiUppercase; + +impl CharacterSet for AsciiUppercase { + fn contains(ch: char) -> bool { + ch.is_ascii_uppercase() + } +} + +pub struct AsciiLetters; + +impl CharacterSet for AsciiLetters { + fn contains(ch: char) -> bool { + ch.is_ascii_alphabetic() + } +} |
