mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-03-23 04:34:39 +02:00
globset: escape {
and }
in escape
This appears to be an oversight from when `escape` was implemented in #2061.
This commit is contained in:
parent
e2362d4d51
commit
163ac157d3
@ -928,13 +928,26 @@ impl RequiredExtensionStrategyBuilder {
|
|||||||
///
|
///
|
||||||
/// The escaping works by surrounding meta-characters with brackets. For
|
/// The escaping works by surrounding meta-characters with brackets. For
|
||||||
/// example, `*` becomes `[*]`.
|
/// example, `*` becomes `[*]`.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use globset::escape;
|
||||||
|
///
|
||||||
|
/// assert_eq!(escape("foo*bar"), "foo[*]bar");
|
||||||
|
/// assert_eq!(escape("foo?bar"), "foo[?]bar");
|
||||||
|
/// assert_eq!(escape("foo[bar"), "foo[[]bar");
|
||||||
|
/// assert_eq!(escape("foo]bar"), "foo[]]bar");
|
||||||
|
/// assert_eq!(escape("foo{bar"), "foo[{]bar");
|
||||||
|
/// assert_eq!(escape("foo}bar"), "foo[}]bar");
|
||||||
|
/// ```
|
||||||
pub fn escape(s: &str) -> String {
|
pub fn escape(s: &str) -> String {
|
||||||
let mut escaped = String::with_capacity(s.len());
|
let mut escaped = String::with_capacity(s.len());
|
||||||
for c in s.chars() {
|
for c in s.chars() {
|
||||||
match c {
|
match c {
|
||||||
// note that ! does not need escaping because it is only special
|
// note that ! does not need escaping because it is only special
|
||||||
// inside brackets
|
// inside brackets
|
||||||
'?' | '*' | '[' | ']' => {
|
'?' | '*' | '[' | ']' | '{' | '}' => {
|
||||||
escaped.push('[');
|
escaped.push('[');
|
||||||
escaped.push(c);
|
escaped.push(c);
|
||||||
escaped.push(']');
|
escaped.push(']');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user