@@ -19,7 +19,7 @@ use mem::transmute;
19
19
use ops:: FnMut ;
20
20
use option:: Option ;
21
21
use option:: Option :: { None , Some } ;
22
- use iter:: { range_step , Iterator , RangeStep } ;
22
+ use iter:: Iterator ;
23
23
use slice:: SliceExt ;
24
24
25
25
// UTF-8 ranges and tags for encoding characters
@@ -459,7 +459,9 @@ pub struct UnicodeEscapedChars {
459
459
enum UnicodeEscapedCharsState {
460
460
Backslash ,
461
461
Type ,
462
- Value ( RangeStep < i32 > ) ,
462
+ Open ,
463
+ Value ( i32 ) ,
464
+ Close ,
463
465
}
464
466
465
467
impl Iterator < char > for UnicodeEscapedChars {
@@ -468,25 +470,44 @@ impl Iterator<char> for UnicodeEscapedChars {
468
470
UnicodeEscapedCharsState :: Backslash => {
469
471
self . state = UnicodeEscapedCharsState :: Type ;
470
472
Some ( '\\' )
471
- }
473
+ } ,
472
474
UnicodeEscapedCharsState :: Type => {
473
- let ( typechar, pad) = if self . c <= '\x7f' { ( 'x' , 2 ) }
474
- else if self . c <= '\u{ffff}' { ( 'u' , 4 ) }
475
- else { ( 'U' , 8 ) } ;
476
- self . state = UnicodeEscapedCharsState :: Value ( range_step ( 4 * ( pad - 1 ) , -1 , -4i32 ) ) ;
477
- Some ( typechar)
478
- }
479
- UnicodeEscapedCharsState :: Value ( ref mut range_step) => match range_step. next ( ) {
480
- Some ( offset) => {
481
- let offset = offset as uint ;
482
- let v = match ( ( self . c as i32 ) >> offset) & 0xf {
483
- i @ 0 ... 9 => '0' as i32 + i,
484
- i => 'a' as i32 + ( i - 10 )
475
+ self . state = UnicodeEscapedCharsState :: Open ;
476
+ Some ( 'u' )
477
+ } ,
478
+ UnicodeEscapedCharsState :: Open => {
479
+ let len = match self . c as u32 {
480
+ 0x0 ...0xf => 1 ,
481
+ 0x10 ...0xff => 2 ,
482
+ 0x100 ...0xfff => 3 ,
483
+ 0x1000 ...0xffff => 4 ,
484
+ 0x10000 ...0xfffff => 5 ,
485
+ 0x100000 ...0xffffff => 6 ,
486
+ 0x1000000 ...0xfffffff => 7 ,
487
+ 0x10000000 ...0xffffffff => 8 ,
488
+ _ => unreachable ! ( ) , // FIXME - Exhaustiveness check
489
+ } ;
490
+ self . state = UnicodeEscapedCharsState :: Value ( len) ;
491
+ Some ( '{' )
492
+ } ,
493
+ UnicodeEscapedCharsState :: Value ( index) => match index {
494
+ 0 => {
495
+ self . state = UnicodeEscapedCharsState :: Close ;
496
+ Some ( '}' )
497
+ } ,
498
+ index => {
499
+ let offset = ( ( index - 1 ) * 4 ) as uint ;
500
+ let v = match ( ( self . c as u32 ) >> offset) & 0xf {
501
+ i @ 0 ...9 => '0' as u32 + i,
502
+ i => 'a' as u32 + ( i - 10 ) ,
485
503
} ;
504
+ self . state = UnicodeEscapedCharsState :: Value ( index - 1 ) ;
486
505
Some ( unsafe { transmute ( v) } )
487
- }
488
- None => None
489
- }
506
+ } ,
507
+ } ,
508
+ UnicodeEscapedCharsState :: Close => {
509
+ None
510
+ } ,
490
511
}
491
512
}
492
513
}
0 commit comments