I'm trying to find out if the following code piece is good or bad practice. It's about a html query string that should be parsed by my API. It's very convenient to use recursion to trim an arbitrary amount of '?' off the query string.
However, I'm wondering if this could potentially result in a stack overflow due to the uncontrollable recursion depth. My hope is that such cases are guaranteed to be tail-optimized but I'm not sure about it. Is there such guarantee?
#include <string_view>
#include <cstdio>
static auto digest_query(std::string_view query) -> void
{
if (query.front() == '?') {
// printf("%.*s\n", (int)query.size(), query.data());
return digest_query(query.substr(1));
}
// Do other stuff...
}
int main()
{
digest_query("???????key=value");
}