mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-13 08:30:07 +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
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