Skip to content

Commit d56377c

Browse files
committed
Make UnicodeEscapedChars use new unicode escape syntax.
Signed-off-by: Peter Atashian <retep998@gmail.com>
1 parent 4265e86 commit d56377c

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

src/libcore/char.rs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use mem::transmute;
1919
use ops::FnMut;
2020
use option::Option;
2121
use option::Option::{None, Some};
22-
use iter::{range_step, Iterator, RangeStep};
22+
use iter::Iterator;
2323
use slice::SliceExt;
2424

2525
// UTF-8 ranges and tags for encoding characters
@@ -459,7 +459,9 @@ pub struct UnicodeEscapedChars {
459459
enum UnicodeEscapedCharsState {
460460
Backslash,
461461
Type,
462-
Value(RangeStep<i32>),
462+
Open,
463+
Value(i32),
464+
Close,
463465
}
464466

465467
impl Iterator<char> for UnicodeEscapedChars {
@@ -468,25 +470,44 @@ impl Iterator<char> for UnicodeEscapedChars {
468470
UnicodeEscapedCharsState::Backslash => {
469471
self.state = UnicodeEscapedCharsState::Type;
470472
Some('\\')
471-
}
473+
},
472474
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),
485503
};
504+
self.state = UnicodeEscapedCharsState::Value(index - 1);
486505
Some(unsafe { transmute(v) })
487-
}
488-
None => None
489-
}
506+
},
507+
},
508+
UnicodeEscapedCharsState::Close => {
509+
None
510+
},
490511
}
491512
}
492513
}

src/test/compile-fail-fulldeps/macro-crate-cannot-read-embedded-ident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:macro_crate_test.rs
1212
// ignore-stage1
1313
// ignore-android
14-
// error-pattern: unknown start of token: \x00
14+
// error-pattern: unknown start of token: \u{0}
1515

1616
// Issue #15750 and #15962 : this test is checking that the standard
1717
// parser rejects embedded idents. pnkfelix did not want to attempt

0 commit comments

Comments
 (0)