mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-15 09:23:51 +01:00
refactor: regexes.rs -> textbuf/regexes.rs
This commit is contained in:
parent
2c3c7a5456
commit
5904bb1df5
4 changed files with 7 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ pub(crate) mod alphabet;
|
|||
mod matches;
|
||||
mod model;
|
||||
mod raw_match;
|
||||
pub(crate) mod regexes;
|
||||
|
||||
pub use matches::Match;
|
||||
pub use model::Model;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use sequence_trie::SequenceTrie;
|
|||
use super::alphabet::Alphabet;
|
||||
use super::matches::Match;
|
||||
use super::raw_match::RawMatch;
|
||||
use crate::regexes::{NamedPattern, EXCLUDE_PATTERNS, PATTERNS};
|
||||
use super::regexes::{NamedPattern, EXCLUDE_PATTERNS, PATTERNS};
|
||||
|
||||
/// Holds data for the `Ui`.
|
||||
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 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 custom = vec![];
|
||||
|
|
|
|||
48
src/textbuf/regexes.rs
Normal file
48
src/textbuf/regexes.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
use crate::error;
|
||||
|
||||
pub(super) const EXCLUDE_PATTERNS: [(&str, &str); 1] =
|
||||
[("ansi_colors", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")];
|
||||
|
||||
/// Holds all the regex patterns that are currently supported.
|
||||
///
|
||||
/// The email address was obtained at https://www.regular-expressions.info/email.html.
|
||||
/// Others were obtained from Ferran Basora.
|
||||
pub(super) const PATTERNS: [(&str, &str); 16] = [
|
||||
("markdown-url", r"\[[^]]*\]\(([^)]+)\)"),
|
||||
(
|
||||
"url",
|
||||
r"((https?://|git@|git://|ssh://|ftp://|file:///)[^ \(\)\[\]\{\}]+)",
|
||||
),
|
||||
("email", r"\b[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,}\b"),
|
||||
("diff-a", r"--- a/([^ ]+)"),
|
||||
("diff-b", r"\+\+\+ b/([^ ]+)"),
|
||||
("docker", r"sha256:([0-9a-f]{64})"),
|
||||
("path", r"(([.\w\-@~]+)?(/[.\w\-@]+)+)"),
|
||||
("hexcolor", r"#[0-9a-fA-F]{6}"),
|
||||
(
|
||||
"uuid",
|
||||
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
|
||||
),
|
||||
(
|
||||
"version",
|
||||
r"(v?\d{1,4}\.\d{1,4}(\.\d{1,4})?(-(alpha|beta|rc)(\.\d)?)?)[^.0-9s]",
|
||||
),
|
||||
("ipfs", r"Qm[0-9a-zA-Z]{44}"),
|
||||
("sha", r"[0-9a-f]{7,40}"),
|
||||
("ipv4", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"),
|
||||
("ipv6", r"[A-f0-9:]+:+[A-f0-9:]+[%\w\d]+"),
|
||||
("mem-address", r"0x[0-9a-fA-F]+"),
|
||||
("digits", r"[0-9]{4,}"),
|
||||
];
|
||||
|
||||
/// Type-safe string Pattern Name (newtype).
|
||||
#[derive(Debug)]
|
||||
pub struct NamedPattern(pub String, pub String);
|
||||
|
||||
/// Parse a name string into `NamedPattern`, used during CLI parsing.
|
||||
pub(crate) fn parse_pattern_name(src: &str) -> Result<NamedPattern, error::ParseError> {
|
||||
match PATTERNS.iter().find(|&(name, _pattern)| name == &src) {
|
||||
Some((name, pattern)) => Ok(NamedPattern(name.to_string(), pattern.to_string())),
|
||||
None => Err(error::ParseError::UnknownPatternName),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue