mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 16:10:07 +01:00
feat: match single/double/tick quoted strings
This commit is contained in:
parent
eaeaf5268b
commit
12c47d1584
3 changed files with 42 additions and 2 deletions
|
|
@ -87,6 +87,8 @@ setup_pattern_binding "h" "--pattern-name sha"
|
|||
setup_pattern_binding "d" "--pattern-name datetime"
|
||||
# prefix + t + e searches for email addresses (see https://www.regular-expressions.info/email.html)
|
||||
setup_pattern_binding "e" "--pattern-name email"
|
||||
# prefix + t + q searches for strings inside single|double|backticks
|
||||
setup_pattern_binding "q" "-x quoted-single -x quoted-double -x quoted-tick"
|
||||
# prefix + t + D searches for docker shas
|
||||
setup_pattern_binding "D" "--pattern-name docker"
|
||||
# prefix + t + c searches for hex colors #aa00f5
|
||||
|
|
|
|||
|
|
@ -573,6 +573,41 @@ mod tests {
|
|||
assert_eq!(spans.get(0).unwrap().text, "2021-03-04T12:23:34");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_quoted_string() {
|
||||
let buffer =
|
||||
r#"Lorem 'first string' and "second string" and `rustc --explain E0223` ipsum."#;
|
||||
let lines = buffer.split('\n').collect::<Vec<_>>();
|
||||
|
||||
let use_all_patterns = false;
|
||||
use crate::textbuf::regexes::parse_pattern_name;
|
||||
let named_pat = vec![
|
||||
parse_pattern_name("quoted-single").unwrap(),
|
||||
parse_pattern_name("quoted-double").unwrap(),
|
||||
parse_pattern_name("quoted-tick").unwrap(),
|
||||
];
|
||||
|
||||
let custom = vec![];
|
||||
let alphabet = Alphabet("abcd".to_string());
|
||||
let reverse = false;
|
||||
let unique_hint = false;
|
||||
let spans = Model::new(
|
||||
&lines,
|
||||
&alphabet,
|
||||
use_all_patterns,
|
||||
&named_pat,
|
||||
&custom,
|
||||
reverse,
|
||||
unique_hint,
|
||||
)
|
||||
.spans;
|
||||
|
||||
assert_eq!(spans.len(), 3);
|
||||
assert_eq!(spans.get(0).unwrap().text, "first string");
|
||||
assert_eq!(spans.get(1).unwrap().text, "second string");
|
||||
assert_eq!(spans.get(2).unwrap().text, "rustc --explain E0223");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn priority_between_regexes() {
|
||||
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";
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ pub(super) const EXCLUDE_PATTERNS: [(&str, &str); 1] =
|
|||
/// 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); 17] = [
|
||||
/// Some others were obtained from Ferran Basora, the rest is by me.
|
||||
pub(super) const PATTERNS: [(&str, &str); 20] = [
|
||||
("markdown-url", r"\[[^]]*\]\(([^)]+)\)"),
|
||||
(
|
||||
"url",
|
||||
|
|
@ -40,6 +40,9 @@ pub(super) const PATTERNS: [(&str, &str); 17] = [
|
|||
"datetime",
|
||||
r"(\d{4}-?\d{2}-?\d{2}([ T]\d{2}:\d{2}:\d{2}(\.\d{3,9})?)?)",
|
||||
),
|
||||
("quoted-single", r#"'([^']+)'"#),
|
||||
("quoted-double", r#""([^"]+)""#),
|
||||
("quoted-tick", r#"`([^`]+)`"#),
|
||||
("digits", r"([0-9]{4,})"),
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue