aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-05-09 16:15:56 -0500
committerGitHub <noreply@github.com>2018-05-09 16:15:56 -0500
commit8a54e5e0b6808a3192ec342b60e36b4325c47f02 (patch)
tree88a818734b16170ebd90176bb0e83fada510a5f7 /src
parent44bec613697e884df64634536554c611d3135b3b (diff)
parent264d828654ff323595e28c8a1f08214481f40f9c (diff)
downloadmilf-rs-8a54e5e0b6808a3192ec342b60e36b4325c47f02.tar.gz
milf-rs-8a54e5e0b6808a3192ec342b60e36b4325c47f02.zip
Merge pull request #241 from avdv/fix-240
Treat unicode hex digits case-insensitively
Diffstat (limited to 'src')
-rw-r--r--src/tokens.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/tokens.rs b/src/tokens.rs
index bcabd94..3f47f02 100644
--- a/src/tokens.rs
+++ b/src/tokens.rs
@@ -2,6 +2,7 @@ use std::borrow::Cow;
use std::char;
use std::str;
use std::string;
+use std::string::String as StdString;
use self::Token::*;
@@ -369,19 +370,15 @@ impl<'a> Tokenizer<'a> {
}
fn hex(&mut self, start: usize, i: usize, len: usize) -> Result<char, Error> {
- let mut val = 0;
+ let mut buf = StdString::with_capacity(len);
for _ in 0..len {
match self.one() {
- Some((_, ch)) if '0' <= ch && ch <= '9' => {
- val = val * 16 + (ch as u32 - '0' as u32);
- }
- Some((_, ch)) if 'A' <= ch && ch <= 'F' => {
- val = val * 16 + (ch as u32 - 'A' as u32) + 10;
- }
+ Some((_, ch)) if ch as u32 <= 0x7F && ch.is_digit(16) => buf.push(ch),
Some((i, ch)) => return Err(Error::InvalidHexEscape(i, ch)),
None => return Err(Error::UnterminatedString(start)),
}
}
+ let val = u32::from_str_radix(&buf, 16).unwrap();
match char::from_u32(val) {
Some(ch) => Ok(ch),
None => Err(Error::InvalidEscapeValue(i, val)),