util/CharUtil: add IsWhitespaceFast()
This commit is contained in:
parent
981be7956b
commit
db6db51742
@ -120,7 +120,7 @@ chomp_length(const char *p)
|
|||||||
{
|
{
|
||||||
size_t length = strlen(p);
|
size_t length = strlen(p);
|
||||||
|
|
||||||
while (length > 0 && IsWhitespaceOrNull(p[length - 1]))
|
while (length > 0 && IsWhitespaceFast(p[length - 1]))
|
||||||
--length;
|
--length;
|
||||||
|
|
||||||
return (int)length;
|
return (int)length;
|
||||||
|
@ -39,7 +39,7 @@ Client::OnSocketInput(void *data, size_t length)
|
|||||||
BufferedSocket::ConsumeInput(newline + 1 - p);
|
BufferedSocket::ConsumeInput(newline + 1 - p);
|
||||||
|
|
||||||
/* skip whitespace at the end of the line */
|
/* skip whitespace at the end of the line */
|
||||||
while (newline > p && IsWhitespaceOrNull(newline[-1]))
|
while (newline > p && IsWhitespaceFast(newline[-1]))
|
||||||
--newline;
|
--newline;
|
||||||
|
|
||||||
/* terminate the string at the end of the line */
|
/* terminate the string at the end of the line */
|
||||||
|
@ -72,7 +72,7 @@ TextInputStream::ReadLine()
|
|||||||
|
|
||||||
buffer.Consume(p - src + 1);
|
buffer.Consume(p - src + 1);
|
||||||
|
|
||||||
while (p > src && IsWhitespaceOrNull(p[-1]))
|
while (p > src && IsWhitespaceFast(p[-1]))
|
||||||
--p;
|
--p;
|
||||||
*p = 0;
|
*p = 0;
|
||||||
return src;
|
return src;
|
||||||
|
@ -58,6 +58,19 @@ IsWhitespaceNotNull(const char ch)
|
|||||||
return ch > 0 && ch <= 0x20;
|
return ch > 0 && ch <= 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the given character whitespace? This calls the faster one of
|
||||||
|
* IsWhitespaceOrNull() or IsWhitespaceNotNull(). Use this if you
|
||||||
|
* want the fastest implementation, and you don't care if a null byte
|
||||||
|
* matches.
|
||||||
|
*/
|
||||||
|
constexpr
|
||||||
|
static inline bool
|
||||||
|
IsWhitespaceFast(const char ch)
|
||||||
|
{
|
||||||
|
return IsWhitespaceOrNull(ch);
|
||||||
|
}
|
||||||
|
|
||||||
constexpr
|
constexpr
|
||||||
static inline bool
|
static inline bool
|
||||||
IsPrintableASCII(char ch)
|
IsPrintableASCII(char ch)
|
||||||
|
@ -67,7 +67,7 @@ Tokenizer::NextWord(Error &error)
|
|||||||
whitespace or end-of-string */
|
whitespace or end-of-string */
|
||||||
|
|
||||||
while (*++input != 0) {
|
while (*++input != 0) {
|
||||||
if (IsWhitespaceOrNull(*input)) {
|
if (IsWhitespaceFast(*input)) {
|
||||||
/* a whitespace: the word ends here */
|
/* a whitespace: the word ends here */
|
||||||
*input = 0;
|
*input = 0;
|
||||||
/* skip all following spaces, too */
|
/* skip all following spaces, too */
|
||||||
@ -112,7 +112,7 @@ Tokenizer::NextUnquoted(Error &error)
|
|||||||
whitespace or end-of-string */
|
whitespace or end-of-string */
|
||||||
|
|
||||||
while (*++input != 0) {
|
while (*++input != 0) {
|
||||||
if (IsWhitespaceOrNull(*input)) {
|
if (IsWhitespaceFast(*input)) {
|
||||||
/* a whitespace: the word ends here */
|
/* a whitespace: the word ends here */
|
||||||
*input = 0;
|
*input = 0;
|
||||||
/* skip all following spaces, too */
|
/* skip all following spaces, too */
|
||||||
@ -176,7 +176,7 @@ Tokenizer::NextString(Error &error)
|
|||||||
line) */
|
line) */
|
||||||
|
|
||||||
++input;
|
++input;
|
||||||
if (!IsWhitespaceOrNull(*input)) {
|
if (!IsWhitespaceFast(*input)) {
|
||||||
error.Set(tokenizer_domain,
|
error.Set(tokenizer_domain,
|
||||||
"Space expected after closing '\"'");
|
"Space expected after closing '\"'");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user