feat: use lazy_static! to define bytes search
This commit is contained in:
parent
78a6b33aa9
commit
53c28fb463
|
@ -24,6 +24,7 @@ bytecount = "0.6.0"
|
||||||
chrono = { version = "0.4.9", optional = true }
|
chrono = { version = "0.4.9", optional = true }
|
||||||
indextree = "4.0.0"
|
indextree = "4.0.0"
|
||||||
jetscii = "0.4.4"
|
jetscii = "0.4.4"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
memchr = "2.2.1"
|
memchr = "2.2.1"
|
||||||
nom = "5.0.1"
|
nom = "5.0.1"
|
||||||
serde = { version = "1.0.100", optional = true, features = ["derive"] }
|
serde = { version = "1.0.100", optional = true, features = ["derive"] }
|
||||||
|
@ -31,7 +32,6 @@ serde_indextree = { version = "0.2.0", optional = true }
|
||||||
syntect = { version = "3.2.1", optional = true }
|
syntect = { version = "3.2.1", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
lazy_static = "1.4.0"
|
|
||||||
pretty_assertions = "0.6.1"
|
pretty_assertions = "0.6.1"
|
||||||
serde_json = "1.0.40"
|
serde_json = "1.0.40"
|
||||||
slugify = "0.1.0"
|
slugify = "0.1.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::write_datetime;
|
use super::write_datetime;
|
||||||
use crate::elements::Element;
|
use crate::elements::Element;
|
||||||
use jetscii::bytes;
|
use jetscii::{bytes, BytesConst};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
@ -11,7 +11,12 @@ impl<S: AsRef<str>> fmt::Display for Escape<S> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
let bytes = self.0.as_ref().as_bytes();
|
let bytes = self.0.as_ref().as_bytes();
|
||||||
while let Some(off) = bytes!(b'<', b'>', b'&', b'\'', b'"').find(&bytes[pos..]) {
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
static ref ESCAPE_BYTES: BytesConst = bytes!(b'<', b'>', b'&', b'\'', b'"');
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(off) = ESCAPE_BYTES.find(&bytes[pos..]) {
|
||||||
write!(f, "{}", &self.0.as_ref()[pos..pos + off])?;
|
write!(f, "{}", &self.0.as_ref()[pos..pos + off])?;
|
||||||
|
|
||||||
pos += off + 1;
|
pos += off + 1;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::iter::once;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use indextree::{Arena, NodeId};
|
use indextree::{Arena, NodeId};
|
||||||
use jetscii::bytes;
|
use jetscii::{bytes, BytesConst};
|
||||||
use memchr::{memchr, memchr_iter};
|
use memchr::{memchr, memchr_iter};
|
||||||
use nom::{
|
use nom::{
|
||||||
bytes::complete::take_while1, combinator::verify, error::ErrorKind, error_position, Err,
|
bytes::complete::take_while1, combinator::verify, error::ErrorKind, error_position, Err,
|
||||||
|
@ -457,8 +457,6 @@ pub fn parse_inlines<'a, T: ElementArena<'a>>(
|
||||||
let mut text = tail;
|
let mut text = tail;
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
|
|
||||||
let bs = bytes!(b'@', b'<', b'[', b' ', b'(', b'{', b'\'', b'"', b'\n');
|
|
||||||
|
|
||||||
macro_rules! insert_text {
|
macro_rules! insert_text {
|
||||||
($value:expr) => {
|
($value:expr) => {
|
||||||
arena.insert_before_last_child(
|
arena.insert_before_last_child(
|
||||||
|
@ -479,7 +477,12 @@ pub fn parse_inlines<'a, T: ElementArena<'a>>(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Some(off) = bs.find(tail.as_bytes()) {
|
lazy_static::lazy_static! {
|
||||||
|
static ref PRE_BYTES: BytesConst =
|
||||||
|
bytes!(b'@', b'<', b'[', b' ', b'(', b'{', b'\'', b'"', b'\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(off) = PRE_BYTES.find(tail.as_bytes()) {
|
||||||
match tail.as_bytes()[off] {
|
match tail.as_bytes()[off] {
|
||||||
b'{' => {
|
b'{' => {
|
||||||
if let Some(new_tail) = parse_inline(&tail[off..], arena, containers, parent) {
|
if let Some(new_tail) = parse_inline(&tail[off..], arena, containers, parent) {
|
||||||
|
|
Loading…
Reference in a new issue