From 4e2afe7937f2a78d0a305c9d9224927b39911002 Mon Sep 17 00:00:00 2001 From: Daniel Alley Date: Sun, 26 Jan 2020 23:08:55 -0500 Subject: [PATCH] Remove wtf8 dependency --- Cargo.lock | 8 -------- parser/Cargo.toml | 1 - parser/src/lexer.rs | 15 ++++++++------- vm/Cargo.toml | 1 - 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6169f706f..017ec5e9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1335,7 +1335,6 @@ dependencies = [ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "unic-emoji-char 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "unic-ucd-ident 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wtf8 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1407,7 +1406,6 @@ dependencies = [ "volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "wtf8 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2193,11 +2191,6 @@ dependencies = [ "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "wtf8" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [metadata] "checksum Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)" = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" "checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" @@ -2444,4 +2437,3 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" -"checksum wtf8 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d6b9309a86639c488a8eb2b5331cb5127cc9feb0a94a0db4b5d1ab5b84977956" diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 7ad5b3518..d34a5c9c0 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -18,4 +18,3 @@ num-bigint = "0.2" num-traits = "0.2" unic-emoji-char = "0.9" unic-ucd-ident = "0.9" -wtf8 = "0.0.3" diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index 50b29b3e9..45448737e 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -8,6 +8,7 @@ use crate::location::Location; use num_bigint::BigInt; use num_traits::identities::Zero; use num_traits::Num; +use std::char; use std::cmp::Ordering; use std::collections::HashMap; use std::str::FromStr; @@ -442,22 +443,22 @@ where fn unicode_literal(&mut self, literal_number: usize) -> Result { let mut p: u32 = 0u32; - let unicode_error = Err(LexicalError { + let unicode_error = LexicalError { error: LexicalErrorType::UnicodeError, location: self.get_pos(), - }); + }; for i in 1..=literal_number { match self.next_char() { Some(c) => match c.to_digit(16) { Some(d) => p += d << ((literal_number - i) * 4), - None => return unicode_error, + None => return Err(unicode_error), }, - None => return unicode_error, + None => return Err(unicode_error), } } - match wtf8::CodePoint::from_u32(p) { - Some(cp) => Ok(cp.to_char_lossy()), - None => unicode_error, + match p { + 0xD800..=0xDFFF => Ok(std::char::REPLACEMENT_CHARACTER), + _ => std::char::from_u32(p).ok_or(unicode_error), } } diff --git a/vm/Cargo.toml b/vm/Cargo.toml index ccfd9f8b5..b8408b42e 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -63,7 +63,6 @@ maplit = "1.0" bitflags = "1.1" libc = "0.2" nix = "0.16.0" -wtf8 = "0.0.3" arr_macro = "0.1.2" csv = "1.1.1" paste = "0.1"