mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-05 21:42:47 -05:00
New utility function: ptrlen_get_word().
This is similar to strtok, only it operates on a ptrlen. Therefore it can be properly stateless, or rather, it stores its state by overwriting the input ptrlen to point to a tail of its previous value. Also in this commit I add a clarifying comment about when ptrlen_{starts,ends}with will write through its 'tail' pointer.
This commit is contained in:
6
misc.h
6
misc.h
@ -168,8 +168,14 @@ static inline ptrlen ptrlen_from_strbuf(strbuf *sb)
|
||||
bool ptrlen_eq_string(ptrlen pl, const char *str);
|
||||
bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2);
|
||||
int ptrlen_strcmp(ptrlen pl1, ptrlen pl2);
|
||||
/* ptrlen_startswith and ptrlen_endswith write through their 'tail'
|
||||
* argument if and only if it is non-NULL and they return true. Hence
|
||||
* you can write ptrlen_startswith(thing, prefix, &thing), writing
|
||||
* back to the same ptrlen it read from, to remove a prefix if present
|
||||
* and say whether it did so. */
|
||||
bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail);
|
||||
bool ptrlen_endswith(ptrlen whole, ptrlen suffix, ptrlen *tail);
|
||||
ptrlen ptrlen_get_word(ptrlen *input, const char *separators);
|
||||
char *mkstr(ptrlen pl);
|
||||
int string_length_for_printf(size_t);
|
||||
/* Derive two printf arguments from a ptrlen, suitable for "%.*s" */
|
||||
|
Reference in New Issue
Block a user