@@ -166,6 +166,26 @@ impl AsciiStr {
166
166
. rev ( ) . take_while ( |a| a. is_whitespace ( ) ) . count ( ) ;
167
167
& self [ ..self . len ( ) -trimmed]
168
168
}
169
+
170
+ #[ cfg( feature = "no_std" ) ]
171
+ pub fn eq_ignore_ascii_case ( & self , other : & Self ) -> bool {
172
+ self . len ( ) == other. len ( ) &&
173
+ self . slice . iter ( ) . zip ( other. slice . iter ( ) ) . all ( |( a, b) | a. eq_ignore_ascii_case ( b) )
174
+ }
175
+
176
+ #[ cfg( feature = "no_std" ) ]
177
+ pub fn make_ascii_uppercase ( & mut self ) {
178
+ for a in & mut self . slice {
179
+ * a = a. to_ascii_uppercase ( ) ;
180
+ }
181
+ }
182
+
183
+ #[ cfg( feature = "no_std" ) ]
184
+ pub fn make_ascii_lowercase ( & mut self ) {
185
+ for a in & mut self . slice {
186
+ * a = a. to_ascii_lowercase ( ) ;
187
+ }
188
+ }
169
189
}
170
190
171
191
impl PartialEq < str > for AsciiStr {
@@ -317,7 +337,7 @@ impl AsciiExt for AsciiStr {
317
337
318
338
fn eq_ignore_ascii_case ( & self , other : & Self ) -> bool {
319
339
self . len ( ) == other. len ( ) &&
320
- self . slice . iter ( ) . zip ( other. slice . iter ( ) ) . all ( |( a, b) | a. eq_ignore_ascii_case ( b) )
340
+ self . slice . iter ( ) . zip ( other. slice . iter ( ) ) . all ( |( a, b) | a. eq_ignore_ascii_case ( b) )
321
341
}
322
342
323
343
fn make_ascii_uppercase ( & mut self ) {
@@ -465,9 +485,9 @@ impl AsMutAsciiStr for str {
465
485
#[ cfg( test) ]
466
486
mod tests {
467
487
use AsciiChar ;
468
- use super :: { AsciiStr , AsAsciiStr , AsAsciiStrError } ;
488
+ use super :: { AsciiStr , AsAsciiStr , AsMutAsciiStr , AsAsciiStrError } ;
469
489
#[ cfg( not( feature = "no_std" ) ) ]
470
- use super :: AsMutAsciiStr ;
490
+ use std :: ascii :: AsciiExt ;
471
491
472
492
#[ test]
473
493
fn generic_as_ascii_str ( ) {
@@ -521,6 +541,19 @@ mod tests {
521
541
assert_eq ! ( AsRef :: <[ u8 ] >:: as_ref( v) , b"( ;" ) ;
522
542
}
523
543
544
+ #[ test]
545
+ fn ascii_case ( ) {
546
+ let mut bytes = ( [ b'a' , b'@' , b'A' ] , [ b'A' , b'@' , b'a' ] ) ;
547
+ let mut a = bytes. 0 . as_mut_ascii_str ( ) . unwrap ( ) ;
548
+ let mut b = bytes. 1 . as_mut_ascii_str ( ) . unwrap ( ) ;
549
+ assert ! ( a. eq_ignore_ascii_case( b) ) ;
550
+ assert ! ( b. eq_ignore_ascii_case( a) ) ;
551
+ a. make_ascii_lowercase ( ) ;
552
+ b. make_ascii_uppercase ( ) ;
553
+ assert_eq ! ( a, "a@a" ) ;
554
+ assert_eq ! ( b, "A@A" ) ;
555
+ }
556
+
524
557
#[ test]
525
558
#[ cfg( not( feature = "no_std" ) ) ]
526
559
fn fmt_ascii_str ( ) {
0 commit comments