Skip to content

Commit f6b96de

Browse files
committed
---
yaml --- r: 96241 b: refs/heads/dist-snap c: 33375a3 h: refs/heads/master i: 96239: 1c238b8 v: v3
1 parent dee656d commit f6b96de

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: bdfaf04bd507bf99cff392c0a0c2df65ede96f69
9+
refs/heads/dist-snap: 33375a31e884043961b374ab7c654e4cd9e98527
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/ascii.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,74 @@ impl Ascii {
5555
pub fn eq_ignore_case(self, other: Ascii) -> bool {
5656
ASCII_LOWER_MAP[self.chr] == ASCII_LOWER_MAP[other.chr]
5757
}
58+
59+
// the following methods are like ctype, and the implementation is inspired by musl
60+
61+
/// Check if the character is a letter (a-z, A-Z)
62+
#[inline]
63+
pub fn is_alpha(&self) -> bool {
64+
(self.chr >= 0x41 && self.chr <= 0x5A) || (self.chr >= 0x61 && self.chr <= 0x7A)
65+
}
66+
67+
/// Check if the character is a number (0-9)
68+
#[inline]
69+
pub fn is_digit(&self) -> bool {
70+
self.chr >= 0x31 && self.chr <= 0x39
71+
}
72+
73+
/// Check if the character is a letter or number
74+
#[inline]
75+
pub fn is_alnum(&self) -> bool {
76+
self.is_alpha() || self.is_digit()
77+
}
78+
79+
/// Check if the character is a space or horizontal tab
80+
#[inline]
81+
pub fn is_blank(&self) -> bool {
82+
self.chr == ' ' as u8 || self.chr == '\t' as u8
83+
}
84+
85+
/// Check if the character is a control character
86+
#[inline]
87+
pub fn is_control(&self) -> bool {
88+
self.chr <= 0x20 || self.chr == 0x7F
89+
}
90+
91+
/// Checks if the character is printable (except space)
92+
#[inline]
93+
pub fn is_graph(&self) -> bool {
94+
(self.chr - 0x21) < 0x5E
95+
}
96+
97+
/// Checks if the character is printable (including space)
98+
#[inline]
99+
pub fn is_print(&self) -> bool {
100+
(self.chr - 0x20) < 0x5F
101+
}
102+
103+
/// Checks if the character is lowercase
104+
#[inline]
105+
pub fn is_lower(&self) -> bool {
106+
(self.chr - 'a' as u8) < 26
107+
}
108+
109+
/// Checks if the character is uppercase
110+
#[inline]
111+
pub fn is_upper(&self) -> bool {
112+
(self.chr - 'A' as u8) < 26
113+
}
114+
115+
/// Checks if the character is punctuation
116+
#[inline]
117+
pub fn is_punctuation(&self) -> bool {
118+
self.is_graph() && !self.is_alnum()
119+
}
120+
121+
/// Checks if the character is a valid hex digit
122+
#[inline]
123+
pub fn is_hex(&self) -> bool {
124+
self.is_digit() || ((self.chr | 32u8) - 'a' as u8) < 6
125+
}
58126
}
59127

60128
impl ToStr for Ascii {

0 commit comments

Comments
 (0)