summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibRegex
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-01-04 12:56:54 -0500
committerLinus Groh <mail@linusgroh.de>2023-01-04 20:04:57 +0100
commit5fdef94d5310c29442a13a20ecdfdb94ca867f8e (patch)
treed52889754ae06df0ac5cf3b61998e52f70069cb8 /Userland/Libraries/LibRegex
parenta96f307af15761d9e284e83d4c1baeda3a4ae0c3 (diff)
downloadserenity-5fdef94d5310c29442a13a20ecdfdb94ca867f8e.zip
LibRegex: Tweak get_error() function
- Return StringView instead of DeprecatedString from function returning only literals - Remove redundant cast - Remove "inline" -- the function is defined in a cpp file, so there's no need for the linkage implications of `inline`. And compilers know to inline static functions with a single use without it. (Normally I'd remove the `static` instead, but this is in an `extern "C"` block, and it doesn't matter enough to end that block before the helper function and reopen it enough after)
Diffstat (limited to 'Userland/Libraries/LibRegex')
-rw-r--r--Userland/Libraries/LibRegex/C/Regex.cpp56
1 files changed, 19 insertions, 37 deletions
diff --git a/Userland/Libraries/LibRegex/C/Regex.cpp b/Userland/Libraries/LibRegex/C/Regex.cpp
index 4520568c26..1281d04816 100644
--- a/Userland/Libraries/LibRegex/C/Regex.cpp
+++ b/Userland/Libraries/LibRegex/C/Regex.cpp
@@ -152,61 +152,43 @@ int regexec(regex_t const* reg, char const* string, size_t nmatch, regmatch_t pm
return REG_NOMATCH;
}
-inline static DeprecatedString get_error(ReError errcode)
+static StringView get_error(ReError errcode)
{
- DeprecatedString error;
- switch ((ReError)errcode) {
+ switch (errcode) {
case REG_NOERR:
- error = "No error";
- break;
+ return "No error"sv;
case REG_NOMATCH:
- error = "regexec() failed to match.";
- break;
+ return "regexec() failed to match."sv;
case REG_BADPAT:
- error = "Invalid regular expression.";
- break;
+ return "Invalid regular expression."sv;
case REG_ECOLLATE:
- error = "Invalid collating element referenced.";
- break;
+ return "Invalid collating element referenced."sv;
case REG_ECTYPE:
- error = "Invalid character class type referenced.";
- break;
+ return "Invalid character class type referenced."sv;
case REG_EESCAPE:
- error = "Trailing \\ in pattern.";
- break;
+ return "Trailing \\ in pattern."sv;
case REG_ESUBREG:
- error = "Number in \\digit invalid or in error.";
- break;
+ return "Number in \\digit invalid or in error."sv;
case REG_EBRACK:
- error = "[ ] imbalance.";
- break;
+ return "[ ] imbalance."sv;
case REG_EPAREN:
- error = "\\( \\) or ( ) imbalance.";
- break;
+ return "\\( \\) or ( ) imbalance."sv;
case REG_EBRACE:
- error = "\\{ \\} imbalance.";
- break;
+ return "\\{ \\} imbalance."sv;
case REG_BADBR:
- error = "Content of \\{ \\} invalid: not a number, number too large, more than two numbers, first larger than second.";
- break;
+ return "Content of \\{ \\} invalid: not a number, number too large, more than two numbers, first larger than second."sv;
case REG_ERANGE:
- error = "Invalid endpoint in range expression.";
- break;
+ return "Invalid endpoint in range expression."sv;
case REG_ESPACE:
- error = "Out of memory.";
- break;
+ return "Out of memory."sv;
case REG_BADRPT:
- error = "?, * or + not preceded by valid regular expression.";
- break;
+ return "?, * or + not preceded by valid regular expression."sv;
case REG_ENOSYS:
- error = "The implementation does not support the function.";
- break;
+ return "The implementation does not support the function."sv;
case REG_EMPTY_EXPR:
- error = "Empty expression provided";
- break;
+ return "Empty expression provided"sv;
}
-
- return error;
+ return {};
}
size_t regerror(int errcode, regex_t const* reg, char* errbuf, size_t errbuf_size)