From 57acbc62c3d1f21a236c4a05064f45a41260eec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 12 Oct 2020 21:46:28 +0200 Subject: [PATCH] improve link detection logic slightly --- src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index b0e5145..8ac21e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -215,11 +215,12 @@ fn preprocess(string: String) -> String { let result_vec = Vec::from(result.as_str()); let start_delims = vec![b'(', b'<']; let end_delims = vec![b')', b'>']; + // link.end() is the first char AFTER the link! let links = finder.links(result.as_str()).filter(|link| { - // link.end() is the first char AFTER the link! - (link.start() == 0 || link.end() == result.len()) - || (!start_delims.contains(&result_vec[link.start() - 1]) - && !end_delims.contains(&result_vec[link.end()])) + link.start() == 0 + || link.end() == result.len() + || !start_delims.contains(&result_vec[link.start() - 1]) + || !end_delims.contains(&result_vec[link.end()]) }); let mut offset = 0;