Skip to content

Commit

Permalink
Merge pull request #79 from GnomedDev/fix-warnings
Browse files Browse the repository at this point in the history
Fix warnings
  • Loading branch information
robinst authored Nov 19, 2024
2 parents 93bdeb2 + 895261a commit 6df780b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ pub(crate) fn find_authority_end(
}
}

return (end, last_dot);
(end, last_dot)
} else {
return (None, None);
(None, None)
}
} else {
return (end, last_dot);
(end, last_dot)
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ pub struct LinkFinder {
url_can_be_iri: bool,
}

type TriggerFinder = dyn Fn(&[u8]) -> Option<usize>;

/// Iterator for finding links.
pub struct Links<'t> {
text: &'t str,
rewind: usize,

trigger_finder: Box<dyn Fn(&[u8]) -> Option<usize>>,
trigger_finder: Box<TriggerFinder>,
email_scanner: EmailScanner,
url_scanner: UrlScanner,
domain_scanner: DomainScanner,
Expand Down Expand Up @@ -232,7 +234,7 @@ impl<'t> Links<'t> {
};

// With optional schemes URLs don't have unique `:`, then search for `.` as well
let trigger_finder: Box<dyn Fn(&[u8]) -> Option<usize>> = match (url, email) {
let trigger_finder: Box<TriggerFinder> = match (url, email) {
(true, true) if url_must_have_scheme => Box::new(|s| memchr2(b':', b'@', s)),
(true, true) => Box::new(|s| memchr3(b':', b'@', b'.', s)),
(true, false) if url_must_have_scheme => Box::new(|s| memchr(b':', s)),
Expand Down Expand Up @@ -271,7 +273,7 @@ impl<'t> Iterator for Links<'t> {
let end = self.rewind + range.end;
self.rewind = end;
let link = Link {
text: &self.text,
text: self.text,
start,
end,
kind,
Expand Down Expand Up @@ -299,10 +301,10 @@ impl<'t> Iterator for Spans<'t> {

fn next(&mut self) -> Option<Span<'t>> {
match self.links.peek() {
Some(ref link) => {
Some(link) => {
if self.position < link.start {
let span = Span {
text: &self.text,
text: self.text,
start: self.position,
end: link.start,
kind: None,
Expand All @@ -314,7 +316,7 @@ impl<'t> Iterator for Spans<'t> {
None => {
if self.position < self.text.len() {
let span = Span {
text: &self.text,
text: self.text,
start: self.position,
end: self.text.len(),
kind: None,
Expand All @@ -327,7 +329,7 @@ impl<'t> Iterator for Spans<'t> {
self.links.next().map(|link| {
self.position = link.end;
Span {
text: &self.text,
text: self.text,
start: link.start,
end: link.end,
kind: Some(link.kind),
Expand Down
9 changes: 3 additions & 6 deletions src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::scanner::Scanner;
/// The shortest valid URL (without a scheme) might be g.cn (Google China),
/// which consists of four characters.
/// We set this as a lower threshold for parsing URLs from plaintext
/// to avoid false-positives and as a slight performance optimization.
/// to avoid false positives and as a slight performance optimization.
/// This threshold might be adjusted in the future.
const MIN_URL_LENGTH: usize = 4;

Expand Down Expand Up @@ -146,10 +146,7 @@ fn find_scheme_start(s: &str) -> (Option<usize>, Option<char>) {
///
/// We could make this configurable, but let's keep it simple until someone asks (hi!).
fn scheme_requires_host(scheme: &str) -> bool {
match scheme {
"https" | "http" | "ftp" | "ssh" => true,
_ => false,
}
matches!(scheme, "https" | "http" | "ftp" | "ssh")
}

/// Find the start of a plain domain URL (no scheme), e.g. from `blog.`, start at `g` and end at `b`.
Expand All @@ -175,7 +172,7 @@ fn find_domain_start(s: &str, iri_parsing_enabled: bool) -> (Option<usize>, Opti
// If this was a valid domain, we'd have extracted it already from the previous "."
'.' => return (None, None),
'-' => {
if first == None {
if first.is_none() {
// Domain label can't end with `-`
return (None, None);
} else {
Expand Down

0 comments on commit 6df780b

Please sign in to comment.