aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/label_end.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/label_end.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/label_end.rs')
-rw-r--r--src/construct/label_end.rs47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/construct/label_end.rs b/src/construct/label_end.rs
index 6399f81..a1ec8d9 100644
--- a/src/construct/label_end.rs
+++ b/src/construct/label_end.rs
@@ -214,16 +214,14 @@ pub fn start(tokenizer: &mut Tokenizer) -> State {
media: Media {
start: label_start.start,
end: (label_end_start, label_end_start + 3),
- // To do: virtual spaces not needed, create a `to_str`?
id: normalize_identifier(
- &Slice::from_position(
+ // We don’t care about virtual spaces, so `indices` and `as_str` are fine.
+ Slice::from_indices(
tokenizer.parse_state.bytes,
- &Position {
- start: &tokenizer.events[label_start.start.1].point,
- end: &tokenizer.events[label_end_start - 1].point,
- },
+ tokenizer.events[label_start.start.1].point.index,
+ tokenizer.events[label_end_start - 1].point.index,
)
- .serialize(),
+ .as_str(),
),
},
};
@@ -366,11 +364,11 @@ fn ok(tokenizer: &mut Tokenizer, mut info: Info) -> State {
/// ^
/// ```
fn nok(tokenizer: &mut Tokenizer, label_start_index: usize) -> State {
- let label_start = tokenizer
+ tokenizer
.label_start_stack
.get_mut(label_start_index)
- .unwrap();
- label_start.balanced = true;
+ .unwrap()
+ .balanced = true;
State::Nok
}
@@ -529,23 +527,24 @@ fn full_reference(tokenizer: &mut Tokenizer) -> State {
/// ^
/// ```
fn full_reference_after(tokenizer: &mut Tokenizer) -> State {
- let end = skip::to_back(
- &tokenizer.events,
- tokenizer.events.len() - 1,
- &[Token::ReferenceString],
- );
-
- // To do: virtual spaces not needed, create a `to_str`?
- let id = Slice::from_position(
- tokenizer.parse_state.bytes,
- &Position::from_exit_event(&tokenizer.events, end),
- )
- .serialize();
-
if tokenizer
.parse_state
.definitions
- .contains(&normalize_identifier(&id))
+ // We don’t care about virtual spaces, so `as_str` is fine.
+ .contains(&normalize_identifier(
+ Slice::from_position(
+ tokenizer.parse_state.bytes,
+ &Position::from_exit_event(
+ &tokenizer.events,
+ skip::to_back(
+ &tokenizer.events,
+ tokenizer.events.len() - 1,
+ &[Token::ReferenceString],
+ ),
+ ),
+ )
+ .as_str(),
+ ))
{
State::Ok
} else {