1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05:00

A few more ptrlen functions.

ptrlen_contains and ptrlen_contains_only are useful for checking that
a string is composed entirely of certain characters, or avoids them.

ptrlen_end makes a pointer to the byte just past the end of the
specified string. And it can be used with make_ptrlen_startend, which
makes a ptrlen out of two pointers instead of a pointer and a length.
This commit is contained in:
Simon Tatham
2022-06-12 11:27:27 +01:00
parent 1a568e3535
commit 76205b89e2
2 changed files with 33 additions and 0 deletions

View File

@ -54,6 +54,22 @@ bool ptrlen_endswith(ptrlen whole, ptrlen suffix, ptrlen *tail)
return false;
}
bool ptrlen_contains(ptrlen input, const char *characters)
{
for (const char *p = input.ptr, *end = p + input.len; p < end; p++)
if (strchr(characters, *p))
return true;
return false;
}
bool ptrlen_contains_only(ptrlen input, const char *characters)
{
for (const char *p = input.ptr, *end = p + input.len; p < end; p++)
if (!strchr(characters, *p))
return false;
return true;
}
ptrlen ptrlen_get_word(ptrlen *input, const char *separators)
{
const char *p = input->ptr, *end = p + input->len;