From 31d17f45597809419cd74eb5eb3622e500682cd4 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 16 Nov 2018 20:21:05 -0600 Subject: [PATCH] Rename `string escape --style=pcre2` to `string escape --style=regex` --- CHANGELOG.md | 2 +- doc_src/string.txt | 2 +- share/completions/apt.fish | 2 +- share/completions/minikube.fish | 4 ++-- share/completions/screen.fish | 2 +- share/completions/yarn.fish | 2 +- src/builtin_string.cpp | 4 ++-- src/common.cpp | 8 ++++---- src/common.h | 2 +- src/fish_tests.cpp | 4 ++-- tests/string.in | 6 +++--- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84e7af1c9..6ad746608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` has new subcommands `split0` and `join0` for working with NUL-delimited output. - `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. ### Interactive improvements diff --git a/doc_src/string.txt b/doc_src/string.txt index 3ea42fc3a..3ccbda5bd 100644 --- a/doc_src/string.txt +++ b/doc_src/string.txt @@ -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=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. diff --git a/share/completions/apt.fish b/share/completions/apt.fish index 7635c3b12..6bc06a84e 100644 --- a/share/completions/apt.fish +++ b/share/completions/apt.fish @@ -17,7 +17,7 @@ function __fish_apt_option 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 $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 complete -x -f -c apt -s h -l help -d 'Display help' diff --git a/share/completions/minikube.fish b/share/completions/minikube.fish index 84cd405dc..81b974bac 100644 --- a/share/completions/minikube.fish +++ b/share/completions/minikube.fish @@ -26,7 +26,7 @@ end function __minikube_using_option 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 string match -qr -- $query $cmd[-1] @@ -40,7 +40,7 @@ function __minikube_using_option_value -a option -a value set cmd (commandline -poc) 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 end diff --git a/share/completions/screen.fish b/share/completions/screen.fish index 9c273c8a3..9fbb16bf1 100644 --- a/share/completions/screen.fish +++ b/share/completions/screen.fish @@ -20,7 +20,7 @@ function __fish_complete_screen_general_list_mac -d "Get the socket list on mac" end 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' end diff --git a/share/completions/yarn.fish b/share/completions/yarn.fish index 107947f45..ffa11137e 100644 --- a/share/completions/yarn.fish +++ b/share/completions/yarn.fish @@ -23,7 +23,7 @@ function __yarn_filtered_list_packages return 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 function __yarn_find_package_json diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index ca9a1b52b..6e810a32e 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -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; } else if (wcscmp(w.woptarg, L"var") == 0) { opts->escape_style = STRING_STYLE_VAR; - } else if (wcscmp(w.woptarg, L"pcre2") == 0) { - opts->escape_style = STRING_STYLE_PCRE2; + } else if (wcscmp(w.woptarg, L"regex") == 0) { + opts->escape_style = STRING_STYLE_REGEX; } else { string_error(streams, _(L"%ls: Invalid escape style '%ls'\n"), cmd, w.woptarg); return STATUS_INVALID_ARGS; diff --git a/src/common.cpp b/src/common.cpp index 59a1e77e9..82c85181f 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1148,7 +1148,7 @@ wcstring escape_string(const wchar_t *in, escape_flags_t flags, escape_string_st escape_string_var(in, result); break; } - case STRING_STYLE_PCRE2: { + case STRING_STYLE_REGEX: { result = escape_string_pcre2(in); break; } @@ -1173,7 +1173,7 @@ wcstring escape_string(const wcstring &in, escape_flags_t flags, escape_string_s escape_string_var(in, result); break; } - case STRING_STYLE_PCRE2: { + case STRING_STYLE_REGEX: { result = escape_string_pcre2(in); break; } @@ -1661,7 +1661,7 @@ bool unescape_string(const wchar_t *input, wcstring *output, unescape_flags_t es success = unescape_string_var(input, output); break; } - case STRING_STYLE_PCRE2: { + case STRING_STYLE_REGEX: { // unescaping PCRE2 is not needed/supported, the PCRE2 engine is responsible for that success = false; 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); break; } - case STRING_STYLE_PCRE2: { + case STRING_STYLE_REGEX: { // unescaping PCRE2 is not needed/supported, the PCRE2 engine is responsible for that success = false; break; diff --git a/src/common.h b/src/common.h index da354be9e..83d6cd0ba 100644 --- a/src/common.h +++ b/src/common.h @@ -122,7 +122,7 @@ enum escape_string_style_t { STRING_STYLE_SCRIPT, STRING_STYLE_URL, STRING_STYLE_VAR, - STRING_STYLE_PCRE2, + STRING_STYLE_REGEX, }; // Flags for unescape_string functions. diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 4ee81280d..ffc1cb447 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -4353,7 +4353,7 @@ static void test_pcre2_escape() { say(L"Testing escaping strings as pcre2 literals"); // plain text should not be needlessly escaped 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) { 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) { - auto escaped = escape_string(test[0], 0, STRING_STYLE_PCRE2); + auto escaped = escape_string(test[0], 0, STRING_STYLE_REGEX); if (escaped != test[1]) { err(L"pcre2_escape error: pcre2_escape(%ls) -> %ls, expected %ls", test[0], escaped.c_str(), test[1]); } diff --git a/tests/string.in b/tests/string.in index 2b4b955fb..74d60ed9a 100644 --- a/tests/string.in +++ b/tests/string.in @@ -103,9 +103,9 @@ string escape --style=var δΈ­ | string unescape --style=var # test regex escaping logmsg 'string escape for literal pcre2 searching' -string escape --style=pcre2 ".ext" -string escape --style=pcre2 "bonjour, amigo" -string escape --style=pcre2 "^this is a literal string" +string escape --style=regex ".ext" +string escape --style=regex "bonjour, amigo" +string escape --style=regex "^this is a literal string" # The following tests verify that we can correctly unescape the same strings # we tested escaping above.