Skip to content

Commit 6958dda

Browse files
committed
---
yaml --- r: 275631 b: refs/heads/master c: 79dfa25 h: refs/heads/master i: 275629: f3c5cfe 275627: 78ab3c7 275623: 71fb7b8 275615: 38e5bb9
1 parent 1ffe74e commit 6958dda

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 7b33d39da93a9873fa002c6875c934fd13ec7d4a
2+
refs/heads/master: 79dfa2590006e50b7c7ba2788a317b56a162175a
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
44
refs/heads/try: 49312a405e14a449b98fe0056b12a40ac128be4a
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/libcore/char.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,18 @@ impl CharExt for char {
300300
#[inline]
301301
fn escape_unicode(self) -> EscapeUnicode {
302302
let c = self as u32;
303+
303304
// or-ing 1 ensures that for c==0 the code computes that one
304305
// digit should be printed and (which is the same) avoids the
305306
// (31 - 32) underflow
306307
let msb = 31 - (c | 1).leading_zeros();
307-
let msdigit = msb / 4;
308+
309+
// the index of the most significant hex digit
310+
let ms_hex_digit = msb / 4;
308311
EscapeUnicode {
309312
c: self,
310313
state: EscapeUnicodeState::Backslash,
311-
offset: msdigit as usize,
314+
hex_digit_idx: ms_hex_digit as usize,
312315
}
313316
}
314317

@@ -431,7 +434,11 @@ pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
431434
pub struct EscapeUnicode {
432435
c: char,
433436
state: EscapeUnicodeState,
434-
offset: usize,
437+
438+
// The index of the next hex digit to be printed (0 if none),
439+
// i.e. the number of remaining hex digits to be printed;
440+
// increasing from the least significant digit: 0x543210
441+
hex_digit_idx: usize,
435442
}
436443

437444
#[derive(Clone)]
@@ -463,11 +470,11 @@ impl Iterator for EscapeUnicode {
463470
Some('{')
464471
}
465472
EscapeUnicodeState::Value => {
466-
let c = from_digit(((self.c as u32) >> (self.offset * 4)) & 0xf, 16).unwrap();
467-
if self.offset == 0 {
473+
let c = from_digit(((self.c as u32) >> (self.hex_digit_idx * 4)) & 0xf, 16).unwrap();
474+
if self.hex_digit_idx == 0 {
468475
self.state = EscapeUnicodeState::RightBrace;
469476
} else {
470-
self.offset -= 1;
477+
self.hex_digit_idx -= 1;
471478
}
472479
Some(c)
473480
}
@@ -488,7 +495,7 @@ impl Iterator for EscapeUnicode {
488495
EscapeUnicodeState::RightBrace => 1,
489496
EscapeUnicodeState::Done => 0,
490497
};
491-
let n = n + self.offset;
498+
let n = n + self.hex_digit_idx;
492499
(n, Some(n))
493500
}
494501
}

0 commit comments

Comments
 (0)