Commit f860a2fb authored by Max Kellermann's avatar Max Kellermann

util/StringUtil: move code to StripRight()

parent 87bcf739
......@@ -35,17 +35,28 @@ StripLeft(const char *p)
return p;
}
char *
Strip(char *p)
size_t
StripRight(const char *p, size_t length)
{
p = StripLeft(p);
size_t length = strlen(p);
while (length > 0 && IsWhitespaceNotNull(p[length - 1]))
--length;
p[length] = 0;
return length;
}
void
StripRight(char *p)
{
size_t old_length = strlen(p);
size_t new_length = StripRight(p, old_length);
p[new_length] = 0;
}
char *
Strip(char *p)
{
p = StripLeft(p);
StripRight(p);
return p;
}
......
......@@ -40,6 +40,20 @@ StripLeft(char *p)
}
/**
* Determine the string's length as if it was stripped on the right
* side.
*/
gcc_pure
size_t
StripRight(const char *p, size_t length);
/**
* Strip trailing whitespace by null-terminating the string.
*/
void
StripRight(char *p);
/**
* Skip whitespace at the beginning and terminate the string after the
* last non-whitespace character.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment