File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 1ad68eafd2505e39d76c0082470e37ab8869ed48
2
+ refs/heads/master: c9b16ac4c28ab5696d318dc7e414c73e27f9d631
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ export bytes_ivec;
52
52
export unsafe_from_bytes_ivec;
53
53
export is_empty;
54
54
export is_not_empty;
55
+ export is_whitespace;
55
56
export replace;
56
57
export char_slice;
57
58
export trim_left;
@@ -166,6 +167,18 @@ pred is_empty(s: str) -> bool { for c: u8 in s { ret false; } ret true; }
166
167
/// Returns true if the string has length greater than 0
167
168
pred is_not_empty( s: str) -> bool { !is_empty ( s) }
168
169
170
+ fn is_whitespace ( s: str) -> bool {
171
+ let i = 0 u;
172
+ let len = char_len ( s) ;
173
+ while i < len {
174
+ if !char:: is_whitespace ( char_at ( s, i) ) {
175
+ ret false ;
176
+ }
177
+ i += 1 u
178
+ }
179
+ ret true;
180
+ }
181
+
169
182
// Returns the number of bytes (a.k.a. UTF-8 code units) in s.
170
183
// Contrast with a function that would return the number of code
171
184
// points (char's), combining character sequences, words, etc. See
Original file line number Diff line number Diff line change @@ -192,6 +192,15 @@ fn trim() {
192
192
assert str:: trim ( " hey dude " ) == "hey dude" ;
193
193
}
194
194
195
+ #[ test]
196
+ fn is_whitespace ( ) {
197
+ assert str:: is_whitespace ( "" ) ;
198
+ assert str:: is_whitespace ( " " ) ;
199
+ assert str:: is_whitespace ( "\u2009 " ) ; // Thin space
200
+ assert str:: is_whitespace ( " \n \t " ) ;
201
+ assert !str:: is_whitespace ( " _ " ) ;
202
+ }
203
+
195
204
// Local Variables:
196
205
// mode: rust;
197
206
// fill-column: 78;
You can’t perform that action at this time.
0 commit comments