aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/partial_whitespace.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-29 18:22:59 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-29 18:22:59 +0200
commit0eeff9148e327183e532752f46421a75506dd7a6 (patch)
tree4f0aed04f90aa759ce96a2e87aa719e7fa95c450 /src/construct/partial_whitespace.rs
parent148ede7f0f42f0ccb1620b13d91f35d0c7d04c2f (diff)
downloadmarkdown-rs-0eeff9148e327183e532752f46421a75506dd7a6.tar.gz
markdown-rs-0eeff9148e327183e532752f46421a75506dd7a6.tar.bz2
markdown-rs-0eeff9148e327183e532752f46421a75506dd7a6.zip
Refactor to improve states
* Remove custom kind wrappers, use plain bytes instead * Remove `Into`s, use the explicit expected types instead * Refactor to use `slice.as_str` in most places * Remove unneeded unique check before adding a definition * Use a shared CDATA prefix in constants * Inline byte checks into matches * Pass bytes back from parser instead of whole parse state * Refactor to work more often on bytes * Rename custom `size` to `len`
Diffstat (limited to 'src/construct/partial_whitespace.rs')
-rw-r--r--src/construct/partial_whitespace.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/construct/partial_whitespace.rs b/src/construct/partial_whitespace.rs
index 13815cb..4f872ba 100644
--- a/src/construct/partial_whitespace.rs
+++ b/src/construct/partial_whitespace.rs
@@ -92,8 +92,7 @@ fn trim_data(
if trim_end {
let mut index = slice.bytes.len();
- let vs = slice.after;
- let mut spaces_only = vs == 0;
+ let mut spaces_only = slice.after == 0;
while index > 0 {
match slice.bytes[index - 1] {
b' ' => {}
@@ -105,10 +104,10 @@ fn trim_data(
}
let diff = slice.bytes.len() - index;
- let token_type = if spaces_only
- && hard_break
- && exit_index + 1 < tokenizer.events.len()
+ let token_type = if hard_break
+ && spaces_only
&& diff >= HARD_BREAK_PREFIX_SIZE_MIN
+ && exit_index + 1 < tokenizer.events.len()
{
Token::HardBreakTrailing
} else {
@@ -123,7 +122,7 @@ fn trim_data(
return;
}
- if diff > 0 || vs > 0 {
+ if diff > 0 || slice.after > 0 {
let exit_point = tokenizer.events[exit_index].point.clone();
let mut enter_point = exit_point.clone();
enter_point.index -= diff;
@@ -156,14 +155,11 @@ fn trim_data(
if trim_start {
let mut index = 0;
- let vs = slice.before;
while index < slice.bytes.len() {
match slice.bytes[index] {
- b' ' | b'\t' => {}
+ b' ' | b'\t' => index += 1,
_ => break,
}
-
- index += 1;
}
// The whole data is whitespace.
@@ -174,7 +170,7 @@ fn trim_data(
return;
}
- if index > 0 || vs > 0 {
+ if index > 0 || slice.before > 0 {
let enter_point = tokenizer.events[exit_index - 1].point.clone();
let mut exit_point = enter_point.clone();
exit_point.index += index;