mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Rename string escape --style=pcre2
to string escape --style=regex
This commit is contained in:
parent
13e025bdb0
commit
31d17f4559
11 changed files with 19 additions and 19 deletions
|
@ -67,7 +67,7 @@ A new feature flags mechanism is added for staging deprecations and breaking cha
|
||||||
- `string split` supports a new `--no-empty` option to exclude empty strings from the result (#4779).
|
- `string split` supports a new `--no-empty` option to exclude empty strings from the result (#4779).
|
||||||
- `string` has new subcommands `split0` and `join0` for working with NUL-delimited output.
|
- `string` has new subcommands `split0` and `join0` for working with NUL-delimited output.
|
||||||
- `string` no longer stops processing text after NUL characters (#4605)
|
- `string` no longer stops processing text after NUL characters (#4605)
|
||||||
- `string escape` has a new `--style pcre2` option for escaping strings to be matched literally in `string` regex operations.
|
- `string escape` has a new `--style regex` option for escaping strings to be matched literally in `string` regex operations.
|
||||||
- `test` now supports floating point values in numeric comparisons.
|
- `test` now supports floating point values in numeric comparisons.
|
||||||
|
|
||||||
### Interactive improvements
|
### Interactive improvements
|
||||||
|
|
|
@ -46,7 +46,7 @@ The following subcommands are available.
|
||||||
|
|
||||||
`--style=url` ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF-8 before being encoded.
|
`--style=url` ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF-8 before being encoded.
|
||||||
|
|
||||||
`--style=pcre2` escapes an input string for literal matching within a regex expression. The string is first converted to UTF-8 before being encoded.
|
`--style=regex` escapes an input string for literal matching within a regex expression. The string is first converted to UTF-8 before being encoded.
|
||||||
|
|
||||||
`string unescape` performs the inverse of the `string escape` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing `string unescape --style=var (string escape --style=var $str)` will return the original string. There is no support for unescaping pcre2.
|
`string unescape` performs the inverse of the `string escape` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing `string unescape --style=var (string escape --style=var $str)` will return the original string. There is no support for unescaping pcre2.
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ function __fish_apt_option
|
||||||
end
|
end
|
||||||
|
|
||||||
complete -c apt -n "__fish_seen_subcommand_from $pkg_subcmds" -a '(__fish_print_packages | head -n 250)'
|
complete -c apt -n "__fish_seen_subcommand_from $pkg_subcmds" -a '(__fish_print_packages | head -n 250)'
|
||||||
complete -c apt -n "__fish_seen_subcommand_from $installed_pkg_subcmds" -a '(__fish_print_packages --installed | string match -re -- "(?:\\b|_)"(commandline -ct | string escape --style=pcre2) | head -n 250)' -d 'Package'
|
complete -c apt -n "__fish_seen_subcommand_from $installed_pkg_subcmds" -a '(__fish_print_packages --installed | string match -re -- "(?:\\b|_)"(commandline -ct | string escape --style=regex) | head -n 250)' -d 'Package'
|
||||||
|
|
||||||
# Support flags
|
# Support flags
|
||||||
complete -x -f -c apt -s h -l help -d 'Display help'
|
complete -x -f -c apt -s h -l help -d 'Display help'
|
||||||
|
|
|
@ -26,7 +26,7 @@ end
|
||||||
|
|
||||||
function __minikube_using_option
|
function __minikube_using_option
|
||||||
set cmd (commandline -poc)
|
set cmd (commandline -poc)
|
||||||
set query "("(string join -- "|" (string escape --style=pcre2 $argv))")"
|
set query "("(string join -- "|" (string escape --style=regex $argv))")"
|
||||||
|
|
||||||
if test (count $cmd) -gt 1
|
if test (count $cmd) -gt 1
|
||||||
if string match -qr -- $query $cmd[-1]
|
if string match -qr -- $query $cmd[-1]
|
||||||
|
@ -40,7 +40,7 @@ function __minikube_using_option_value -a option -a value
|
||||||
set cmd (commandline -poc)
|
set cmd (commandline -poc)
|
||||||
|
|
||||||
if test (count $cmd) -gt 1
|
if test (count $cmd) -gt 1
|
||||||
string match -qr -- (string escape --style=pcre2 $option)"[= ]"(string escape --style=pcre2 $value) "$cmd"
|
string match -qr -- (string escape --style=regex $option)"[= ]"(string escape --style=regex $value) "$cmd"
|
||||||
return $status
|
return $status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ function __fish_complete_screen_general_list_mac -d "Get the socket list on mac"
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fish_complete_screen_general_list -d "Get the socket list"
|
function __fish_complete_screen_general_list -d "Get the socket list"
|
||||||
set -l escaped (string escape --style=pcre2 $argv)
|
set -l escaped (string escape --style=regex $argv)
|
||||||
screen -list | string match -r '^\t.*\(.*\)\s*\('$escaped'\)\s*$'| string replace -r '\t(.*)\s+\((.*)\)\s*\((.*)\)' '$1\t$2 $3'
|
screen -list | string match -r '^\t.*\(.*\)\s*\('$escaped'\)\s*$'| string replace -r '\t(.*)\s+\((.*)\)\s*\((.*)\)' '$1\t$2 $3'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ function __yarn_filtered_list_packages
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
all-the-package-names | string match -er -- "(?:\\b|_)"(commandline -ct | string escape --style=pcre2)
|
all-the-package-names | string match -er -- "(?:\\b|_)"(commandline -ct | string escape --style=regex)
|
||||||
end
|
end
|
||||||
|
|
||||||
function __yarn_find_package_json
|
function __yarn_find_package_json
|
||||||
|
|
|
@ -196,8 +196,8 @@ static int handle_flag_1(wchar_t **argv, parser_t &parser, io_streams_t &streams
|
||||||
opts->escape_style = STRING_STYLE_URL;
|
opts->escape_style = STRING_STYLE_URL;
|
||||||
} else if (wcscmp(w.woptarg, L"var") == 0) {
|
} else if (wcscmp(w.woptarg, L"var") == 0) {
|
||||||
opts->escape_style = STRING_STYLE_VAR;
|
opts->escape_style = STRING_STYLE_VAR;
|
||||||
} else if (wcscmp(w.woptarg, L"pcre2") == 0) {
|
} else if (wcscmp(w.woptarg, L"regex") == 0) {
|
||||||
opts->escape_style = STRING_STYLE_PCRE2;
|
opts->escape_style = STRING_STYLE_REGEX;
|
||||||
} else {
|
} else {
|
||||||
string_error(streams, _(L"%ls: Invalid escape style '%ls'\n"), cmd, w.woptarg);
|
string_error(streams, _(L"%ls: Invalid escape style '%ls'\n"), cmd, w.woptarg);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
|
|
|
@ -1148,7 +1148,7 @@ wcstring escape_string(const wchar_t *in, escape_flags_t flags, escape_string_st
|
||||||
escape_string_var(in, result);
|
escape_string_var(in, result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING_STYLE_PCRE2: {
|
case STRING_STYLE_REGEX: {
|
||||||
result = escape_string_pcre2(in);
|
result = escape_string_pcre2(in);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1173,7 +1173,7 @@ wcstring escape_string(const wcstring &in, escape_flags_t flags, escape_string_s
|
||||||
escape_string_var(in, result);
|
escape_string_var(in, result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING_STYLE_PCRE2: {
|
case STRING_STYLE_REGEX: {
|
||||||
result = escape_string_pcre2(in);
|
result = escape_string_pcre2(in);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1661,7 +1661,7 @@ bool unescape_string(const wchar_t *input, wcstring *output, unescape_flags_t es
|
||||||
success = unescape_string_var(input, output);
|
success = unescape_string_var(input, output);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING_STYLE_PCRE2: {
|
case STRING_STYLE_REGEX: {
|
||||||
// unescaping PCRE2 is not needed/supported, the PCRE2 engine is responsible for that
|
// unescaping PCRE2 is not needed/supported, the PCRE2 engine is responsible for that
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
|
@ -1687,7 +1687,7 @@ bool unescape_string(const wcstring &input, wcstring *output, unescape_flags_t e
|
||||||
success = unescape_string_var(input.c_str(), output);
|
success = unescape_string_var(input.c_str(), output);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING_STYLE_PCRE2: {
|
case STRING_STYLE_REGEX: {
|
||||||
// unescaping PCRE2 is not needed/supported, the PCRE2 engine is responsible for that
|
// unescaping PCRE2 is not needed/supported, the PCRE2 engine is responsible for that
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -122,7 +122,7 @@ enum escape_string_style_t {
|
||||||
STRING_STYLE_SCRIPT,
|
STRING_STYLE_SCRIPT,
|
||||||
STRING_STYLE_URL,
|
STRING_STYLE_URL,
|
||||||
STRING_STYLE_VAR,
|
STRING_STYLE_VAR,
|
||||||
STRING_STYLE_PCRE2,
|
STRING_STYLE_REGEX,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flags for unescape_string functions.
|
// Flags for unescape_string functions.
|
||||||
|
|
|
@ -4353,7 +4353,7 @@ static void test_pcre2_escape() {
|
||||||
say(L"Testing escaping strings as pcre2 literals");
|
say(L"Testing escaping strings as pcre2 literals");
|
||||||
// plain text should not be needlessly escaped
|
// plain text should not be needlessly escaped
|
||||||
auto input = L"hello world!";
|
auto input = L"hello world!";
|
||||||
auto escaped = escape_string(input, 0, STRING_STYLE_PCRE2);
|
auto escaped = escape_string(input, 0, STRING_STYLE_REGEX);
|
||||||
if (escaped != input) {
|
if (escaped != input) {
|
||||||
err(L"Input string %ls unnecessarily PCRE2 escaped as %ls", input, escaped.c_str());
|
err(L"Input string %ls unnecessarily PCRE2 escaped as %ls", input, escaped.c_str());
|
||||||
}
|
}
|
||||||
|
@ -4369,7 +4369,7 @@ static void test_pcre2_escape() {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto &test : tests) {
|
for (auto &test : tests) {
|
||||||
auto escaped = escape_string(test[0], 0, STRING_STYLE_PCRE2);
|
auto escaped = escape_string(test[0], 0, STRING_STYLE_REGEX);
|
||||||
if (escaped != test[1]) {
|
if (escaped != test[1]) {
|
||||||
err(L"pcre2_escape error: pcre2_escape(%ls) -> %ls, expected %ls", test[0], escaped.c_str(), test[1]);
|
err(L"pcre2_escape error: pcre2_escape(%ls) -> %ls, expected %ls", test[0], escaped.c_str(), test[1]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,9 +103,9 @@ string escape --style=var 中 | string unescape --style=var
|
||||||
|
|
||||||
# test regex escaping
|
# test regex escaping
|
||||||
logmsg 'string escape for literal pcre2 searching'
|
logmsg 'string escape for literal pcre2 searching'
|
||||||
string escape --style=pcre2 ".ext"
|
string escape --style=regex ".ext"
|
||||||
string escape --style=pcre2 "bonjour, amigo"
|
string escape --style=regex "bonjour, amigo"
|
||||||
string escape --style=pcre2 "^this is a literal string"
|
string escape --style=regex "^this is a literal string"
|
||||||
|
|
||||||
# The following tests verify that we can correctly unescape the same strings
|
# The following tests verify that we can correctly unescape the same strings
|
||||||
# we tested escaping above.
|
# we tested escaping above.
|
||||||
|
|
Loading…
Reference in a new issue