I need to convert an input string which can contain \r\n as part of string. For example as given below
\r\n Content-type: text/plain; charset=iso-8859-1 \r\n Subject: Test Subject \r\n\r\n Test Message
Now while sending this string over HTTP Post data I need to convert \r\n to percentile encoding. But when I use curl_easy_escape function it understand \r\n as different characters and encode incorrectly. So to avoid such error I need to convert \r\n in above string as carriage return and newline so that the buffer get converted correctly by curl_easy_escape() function.
I tried using sstream object, sprintf and sscanf with the buffer (as the buffer is an std::string object) but didn’t help out much. Basically I want to convert the buffer as below
Content-type: text/plain; charset=iso-8859-1
Subject: Test Subject
Test Message
So that when we pass this buffer to curl_easy_escape it encodes properly.
So any pointers in this regard will be very helpful.
You can use
std::string::findandstd::string::replacein a loop to do it: