-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
138 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: sean0x42 # Replace with a single Ko-fi username | ||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mod regex; | ||
mod simple; | ||
|
||
pub use self::regex::RegexMatcher; | ||
use crate::document::Document; | ||
use crate::Opts; | ||
pub use simple::SimpleMatcher; | ||
|
||
pub trait Matcher { | ||
/// Find any sections within the document that match | ||
fn get_matches(document: &Document, opts: &Opts) -> Document; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use super::Matcher; | ||
use crate::document::Document; | ||
use crate::Opts; | ||
use regex::RegexBuilder; | ||
|
||
pub struct RegexMatcher; | ||
|
||
impl Matcher for RegexMatcher { | ||
/// Compile the pattern as a regular expression | ||
fn get_matches(document: &Document, opts: &Opts) -> Document { | ||
// Compile regex for provided pattern | ||
let re = RegexBuilder::new(&opts.pattern) | ||
.case_insensitive(!opts.case_sensitive) | ||
.size_limit(1024 * 100) // 100 kb | ||
.build() | ||
.unwrap(); | ||
|
||
document | ||
.iter() | ||
.filter(|section| re.is_match(§ion.title)) | ||
.cloned() | ||
.collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use super::Matcher; | ||
use crate::document::Document; | ||
use crate::Opts; | ||
|
||
pub struct SimpleMatcher; | ||
|
||
impl Matcher for SimpleMatcher { | ||
/// Performs a simple pattern == title match | ||
fn get_matches(document: &Document, opts: &Opts) -> Document { | ||
document | ||
.iter() | ||
.filter(|section| { | ||
if opts.case_sensitive { | ||
section.title.trim() == opts.pattern.trim() | ||
} else { | ||
section.title.to_lowercase().trim() == opts.pattern.to_lowercase().trim() | ||
} | ||
}) | ||
.cloned() | ||
.collect() | ||
} | ||
} |