refactor: regexes.rs -> textbuf/regexes.rs

This commit is contained in:
graelo 2021-03-20 09:30:38 +01:00
parent 2c3c7a5456
commit 5904bb1df5
4 changed files with 7 additions and 6 deletions

View file

@ -1,6 +1,5 @@
pub mod error; pub mod error;
pub mod output_destination; pub mod output_destination;
pub mod regexes;
pub mod textbuf; pub mod textbuf;
pub mod tmux; pub mod tmux;
pub mod ui; pub mod ui;
@ -11,6 +10,7 @@ use std::path;
use std::str::FromStr; use std::str::FromStr;
use crate::textbuf::alphabet; use crate::textbuf::alphabet;
use crate::textbuf::regexes;
/// Run copyrat on an input string `buffer`, configured by `Opt`. /// Run copyrat on an input string `buffer`, configured by `Opt`.
/// ///

View file

@ -2,6 +2,7 @@ pub(crate) mod alphabet;
mod matches; mod matches;
mod model; mod model;
mod raw_match; mod raw_match;
pub(crate) mod regexes;
pub use matches::Match; pub use matches::Match;
pub use model::Model; pub use model::Model;

View file

@ -6,7 +6,7 @@ use sequence_trie::SequenceTrie;
use super::alphabet::Alphabet; use super::alphabet::Alphabet;
use super::matches::Match; use super::matches::Match;
use super::raw_match::RawMatch; use super::raw_match::RawMatch;
use crate::regexes::{NamedPattern, EXCLUDE_PATTERNS, PATTERNS}; use super::regexes::{NamedPattern, EXCLUDE_PATTERNS, PATTERNS};
/// Holds data for the `Ui`. /// Holds data for the `Ui`.
pub struct Model<'a> { pub struct Model<'a> {
@ -757,7 +757,7 @@ mod tests {
let buffer = "Lorem [link](http://foo.bar) ipsum CUSTOM-52463 lorem ISSUE-123 lorem\nLorem /var/fd70b569/9999.log 52463 lorem\n Lorem 973113 lorem 123e4567-e89b-12d3-a456-426655440000 lorem 8888 lorem\n https://crates.io/23456/fd70b569 lorem"; let buffer = "Lorem [link](http://foo.bar) ipsum CUSTOM-52463 lorem ISSUE-123 lorem\nLorem /var/fd70b569/9999.log 52463 lorem\n Lorem 973113 lorem 123e4567-e89b-12d3-a456-426655440000 lorem 8888 lorem\n https://crates.io/23456/fd70b569 lorem";
let use_all_patterns = false; let use_all_patterns = false;
use crate::regexes::parse_pattern_name; use crate::textbuf::regexes::parse_pattern_name;
let named_pat = vec![parse_pattern_name("url").unwrap()]; let named_pat = vec![parse_pattern_name("url").unwrap()];
let custom = vec![]; let custom = vec![];

View file

@ -1,13 +1,13 @@
use crate::error; use crate::error;
pub const EXCLUDE_PATTERNS: [(&str, &str); 1] = pub(super) const EXCLUDE_PATTERNS: [(&str, &str); 1] =
[("ansi_colors", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")]; [("ansi_colors", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")];
/// Holds all the regex patterns that are currently supported. /// Holds all the regex patterns that are currently supported.
/// ///
/// The email address was obtained at https://www.regular-expressions.info/email.html. /// The email address was obtained at https://www.regular-expressions.info/email.html.
/// Others were obtained from Ferran Basora. /// Others were obtained from Ferran Basora.
pub const PATTERNS: [(&str, &str); 16] = [ pub(super) const PATTERNS: [(&str, &str); 16] = [
("markdown-url", r"\[[^]]*\]\(([^)]+)\)"), ("markdown-url", r"\[[^]]*\]\(([^)]+)\)"),
( (
"url", "url",
@ -40,7 +40,7 @@ pub const PATTERNS: [(&str, &str); 16] = [
pub struct NamedPattern(pub String, pub String); pub struct NamedPattern(pub String, pub String);
/// Parse a name string into `NamedPattern`, used during CLI parsing. /// Parse a name string into `NamedPattern`, used during CLI parsing.
pub fn parse_pattern_name(src: &str) -> Result<NamedPattern, error::ParseError> { pub(crate) fn parse_pattern_name(src: &str) -> Result<NamedPattern, error::ParseError> {
match PATTERNS.iter().find(|&(name, _pattern)| name == &src) { match PATTERNS.iter().find(|&(name, _pattern)| name == &src) {
Some((name, pattern)) => Ok(NamedPattern(name.to_string(), pattern.to_string())), Some((name, pattern)) => Ok(NamedPattern(name.to_string(), pattern.to_string())),
None => Err(error::ParseError::UnknownPatternName), None => Err(error::ParseError::UnknownPatternName),