Skip to content

Commit 5674601

Browse files
committed
---
yaml --- r: 275767 b: refs/heads/auto c: 79dfa25 h: refs/heads/master i: 275765: 4c4a609 275763: 84a2a1f 275759: 7d89d31
1 parent 6c2907c commit 5674601

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
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 7b33d39da93a9873fa002c6875c934fd13ec7d4a
11+
refs/heads/auto: 79dfa2590006e50b7c7ba2788a317b56a162175a
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/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)