I'm trying to write a parser for SCGI requests. I'm trying to parse the string described in the example but for some reason I cannot find the position of the second null character, the one that separates the content length value and the next property name.
This is my test string:
string scgi_request(
"70:CONTENT_LENGTH\027\0SCGI\01\0REQUEST_METHOD\0POST\0REQUEST_URI\0" \
"/deepthought\0,What is the answer to life?"
, 91);
I can find the position of the first null character, position 18. But once I try to find the one after that, the position returned is invalid, off by a few characters, all the way up to position 24.
This is my algorithm:
size_t contentLengthEnd = scgi_request.find('\0');
size_t contentLengthValueEnd = scgi_request.find('\0', ++contentLengthEnd);
std::cerr << contentLengthEnd << std::endl; // 19, because I shifted this one forward
// otherwise I'd always get the same
// character
std::cerr << contentLengthValueEnd << std::endl; // 24, no clu why.