From f0174fcbee229c67ebfdae9012628891a55be7aa Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 8 Jun 2016 09:19:44 +0300 Subject: use the slice_pat hack in libstd too --- src/libstd/sys/common/wtf8.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/libstd/sys/common') diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 35e39531448..d705b8986d0 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -560,20 +560,15 @@ impl Wtf8 { } } - // FIXME(stage0): use slice patterns after snapshot #[inline] fn final_lead_surrogate(&self) -> Option { let len = self.len(); if len < 3 { return None } - if self.bytes[len-3] == 0xed && - self.bytes[len-2] >= 0xa0 && - self.bytes[len-2] <= 0xaf - { - Some(decode_surrogate(self.bytes[len-2], self.bytes[len-1])) - } else { - None + match ::slice_pat(&&self.bytes[(len - 3)..]) { + &[0xED, b2 @ 0xA0...0xAF, b3] => Some(decode_surrogate(b2, b3)), + _ => None } } @@ -583,13 +578,9 @@ impl Wtf8 { if len < 3 { return None } - if self.bytes[0] == 0xed && - self.bytes[1] >= 0xb0 && - self.bytes[1] <= 0xbf - { - Some(decode_surrogate(self.bytes[1], self.bytes[2])) - } else { - None + match ::slice_pat(&&self.bytes[..3]) { + &[0xED, b2 @ 0xB0...0xBF, b3] => Some(decode_surrogate(b2, b3)), + _ => None } } } -- cgit 1.4.1-3-g733a5