Checks if str contains '=', '&', '%' or '\n' characters. If yes, replaces them by "%xx" where xx is their hexadecimal value. For example, replaces "=" with "%3D". This algorithm is O(strlen(str)) in both time and space -- important as the input str may contain an arbitrarily long test failure message and stack trace.
| 5265 | // in both time and space -- important as the input str may contain an |
| 5266 | // arbitrarily long test failure message and stack trace. |
| 5267 | string StreamingListener::UrlEncode(const char* str) { |
| 5268 | string result; |
| 5269 | result.reserve(strlen(str) + 1); |
| 5270 | for (char ch = *str; ch != '\0'; ch = *++str) { |
| 5271 | switch (ch) { |
| 5272 | case '%': |
| 5273 | case '=': |
| 5274 | case '&': |
| 5275 | case '\n': |
| 5276 | result.append("%" + String::FormatByte(static_cast<unsigned char>(ch))); |
| 5277 | break; |
| 5278 | default: |
| 5279 | result.push_back(ch); |
| 5280 | break; |
| 5281 | } |
| 5282 | } |
| 5283 | return result; |
| 5284 | } |
| 5285 | |
| 5286 | void StreamingListener::SocketWriter::MakeConnection() { |
| 5287 | GTEST_CHECK_(sockfd_ == -1) |