From 0fc84d19b245e8391c047b9a2dc8c25bc88499ec Mon Sep 17 00:00:00 2001 From: RumovZ Date: Fri, 20 Nov 2020 09:23:25 +0100 Subject: [PATCH] Replace text.rs/text_to_re with text.rs/to_re --- rslib/src/tags.rs | 4 ++-- rslib/src/text.rs | 32 -------------------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/rslib/src/tags.rs b/rslib/src/tags.rs index 7b6c424ff..e0443c7b0 100644 --- a/rslib/src/tags.rs +++ b/rslib/src/tags.rs @@ -5,7 +5,7 @@ use crate::{ collection::Collection, err::{AnkiError, Result}, notes::{NoteID, TransformNoteOutput}, - text::text_to_re, + text::to_re, {text::normalize_to_nfc, types::Usn}, }; use regex::{NoExpand, Regex, Replacer}; @@ -134,7 +134,7 @@ impl Collection { // generate regexps let tags = split_tags(tags) .map(|tag| { - let tag = if regex { tag.into() } else { text_to_re(tag) }; + let tag = if regex { tag.into() } else { to_re(tag) }; Regex::new(&format!("(?i)^{}$", tag)) .map_err(|_| AnkiError::invalid_input("invalid regex")) }) diff --git a/rslib/src/text.rs b/rslib/src/text.rs index 934fa64c0..5a063eafc 100644 --- a/rslib/src/text.rs +++ b/rslib/src/text.rs @@ -258,38 +258,6 @@ pub(crate) fn without_combining(s: &str) -> Cow { .into() } -/// Escape text, converting glob characters to regex syntax, then return. -pub(crate) fn text_to_re(glob: &str) -> String { - lazy_static! { - static ref ESCAPED: Regex = Regex::new(r"(\\\\)?\\\*").unwrap(); - static ref GLOB: Regex = Regex::new(r"(\\\\)?[_%]").unwrap(); - } - - let escaped = regex::escape(glob); - - let text = ESCAPED.replace_all(&escaped, |caps: &Captures| { - if caps.get(0).unwrap().as_str().len() == 2 { - ".*" - } else { - r"\*" - } - }); - - let text2 = GLOB.replace_all(&text, |caps: &Captures| { - match caps.get(0).unwrap().as_str() { - "_" => ".", - "%" => ".*", - other => { - // strip off the escaping char - &other[2..] - } - } - .to_string() - }); - - text2.into() -} - /// Check if string contains an unescaped wildcard. pub(crate) fn is_glob(txt: &str) -> bool { // even number of \s followed by a wildcard