http: convert parsers to strparse

Closes #16436
This commit is contained in:
Daniel Stenberg 2025-02-20 16:55:13 +01:00
parent edd573d980
commit 04289c62de
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 131 additions and 147 deletions

View file

@ -63,6 +63,29 @@ int Curl_str_word(const char **linep, struct Curl_str *out,
return Curl_str_until(linep, out, max, ' ');
}
/* Get a word until a newline byte or end of string. At least one byte long.
return non-zero on error */
int Curl_str_untilnl(const char **linep, struct Curl_str *out,
const size_t max)
{
const char *s = *linep;
size_t len = 0;
DEBUGASSERT(linep && *linep && out && max);
Curl_str_init(out);
while(*s && !ISNEWLINE(*s)) {
s++;
if(++len > max)
return STRE_BIG;
}
if(!len)
return STRE_SHORT;
out->str = *linep;
out->len = len;
*linep = s; /* point to the first byte after the word */
return STRE_OK;
}
/* Get a "quoted" word. No escaping possible.
return non-zero on error */