Created
May 31, 2018 05:17
-
-
Save kivikakk/df6b7701334191bc9405da7e157c24b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Cargo.toml b/Cargo.toml | |
index 64f9b6c..54d4b57 100644 | |
--- a/Cargo.toml | |
+++ b/Cargo.toml | |
@@ -32,6 +32,7 @@ clap = { version = "2.29", optional = true } | |
twoway = "0.1" | |
pest = "1.0" | |
pest_derive = "1.0" | |
+jetscii = "0.4" | |
[dev-dependencies] | |
timebomb = "0.1.2" | |
diff --git a/src/lib.rs b/src/lib.rs | |
index 1b23fe7..2141742 100644 | |
--- a/src/lib.rs | |
+++ b/src/lib.rs | |
@@ -66,6 +66,7 @@ | |
#![cfg_attr(feature = "benchmarks", allow(unstable_features))] | |
#![cfg_attr(feature = "benchmarks", feature(test))] | |
+extern crate jetscii; | |
extern crate entities; | |
#[macro_use] | |
extern crate lazy_static; | |
diff --git a/src/main.rs b/src/main.rs | |
index 0eee861..589ce3e 100644 | |
--- a/src/main.rs | |
+++ b/src/main.rs | |
@@ -4,6 +4,7 @@ | |
trivial_numeric_casts, unstable_features, unused_import_braces)] | |
#![allow(unknown_lints, doc_markdown, cyclomatic_complexity)] | |
+extern crate jetscii; | |
#[macro_use] | |
extern crate clap; | |
extern crate entities; | |
diff --git a/src/parser/inlines.rs b/src/parser/inlines.rs | |
index e872e19..bd0436a 100644 | |
--- a/src/parser/inlines.rs | |
+++ b/src/parser/inlines.rs | |
@@ -26,7 +26,7 @@ pub struct Subject<'a: 'd, 'r, 'o, 'd, 'i> { | |
brackets: Vec<Bracket<'a, 'd>>, | |
pub backticks: [usize; MAXBACKTICKS + 1], | |
pub scanned_for_backticks: bool, | |
- special_chars: [bool; 256], | |
+ special_chars: ::jetscii::Bytes<fn(u8) -> bool>, | |
smart_chars: [bool; 256], | |
} | |
@@ -57,6 +57,28 @@ impl<'a, 'r, 'o, 'd, 'i> Subject<'a, 'r, 'o, 'd, 'i> { | |
refmap: &'r mut HashMap<Vec<u8>, Reference>, | |
delimiter_arena: &'d Arena<Delimiter<'a, 'd>>, | |
) -> Self { | |
+ let bytes: [u8; 16] = [ | |
+ b'\n', | |
+ b'\r', | |
+ b'_', | |
+ b'*', | |
+ b'"', | |
+ b'`', | |
+ b'\\', | |
+ b'&', | |
+ b'<', | |
+ b'[', | |
+ b']', | |
+ b'!', | |
+ 0, | |
+ 0, | |
+ 0, | |
+ 0, | |
+ ]; | |
+ let byte_count = 12; | |
+ fn fallback(b: u8) -> bool { | |
+ false | |
+ } | |
let mut s = Subject { | |
arena: arena, | |
options: options, | |
@@ -68,25 +90,14 @@ impl<'a, 'r, 'o, 'd, 'i> Subject<'a, 'r, 'o, 'd, 'i> { | |
brackets: vec![], | |
backticks: [0; MAXBACKTICKS + 1], | |
scanned_for_backticks: false, | |
- special_chars: [false; 256], | |
+ special_chars: ::jetscii::Bytes::new(bytes, byte_count, fallback), | |
smart_chars: [false; 256], | |
}; | |
- for &c in &[ | |
- b'\n', b'\r', b'_', b'*', b'"', b'`', b'\\', b'&', b'<', b'[', b']', b'!' | |
- ] { | |
- s.special_chars[c as usize] = true; | |
- } | |
- if options.ext_strikethrough { | |
- s.special_chars[b'~' as usize] = true; | |
- } | |
- if options.ext_superscript { | |
- s.special_chars[b'^' as usize] = true; | |
- } | |
- for &c in &[ | |
- b'"', b'\'', b'.', b'-', | |
- ] { | |
- s.smart_chars[c as usize] = true; | |
- } | |
+// for &c in &[ | |
+ // b'"', b'\'', b'.', b'-', | |
+ // ] { | |
+ // s.smart_chars[c as usize] = true; | |
+ //} | |
s | |
} | |
@@ -430,16 +441,11 @@ impl<'a, 'r, 'o, 'd, 'i> Subject<'a, 'r, 'o, 'd, 'i> { | |
} | |
pub fn find_special_char(&self) -> usize { | |
- for n in self.pos..self.input.len() { | |
- if self.special_chars[self.input[n] as usize] { | |
- return n; | |
- } | |
- if self.options.smart && self.smart_chars[self.input[n] as usize] { | |
- return n; | |
- } | |
+ if let Some(offset) = self.special_chars.find(&self.input[self.pos..]) { | |
+ self.pos + offset | |
+ } else { | |
+ self.input.len() | |
} | |
- | |
- self.input.len() | |
} | |
pub fn handle_newline(&mut self) -> &'a AstNode<'a> { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment