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.
| 4901 | // in both time and space -- important as the input str may contain an |
| 4902 | // arbitrarily long test failure message and stack trace. |
| 4903 | string StreamingListener::UrlEncode(const char* str) { |
| 4904 | string result; |
| 4905 | result.reserve(strlen(str) + 1); |
| 4906 | for (char ch = *str; ch != '\0'; ch = *++str) { |
| 4907 | switch (ch) { |
| 4908 | case '%': |
| 4909 | case '=': |
| 4910 | case '&': |
| 4911 | case '\n': |
| 4912 | result.append("%" + String::FormatByte(static_cast<unsigned char>(ch))); |
| 4913 | break; |
| 4914 | default: |
| 4915 | result.push_back(ch); |
| 4916 | break; |
| 4917 | } |
| 4918 | } |
| 4919 | return result; |
| 4920 | } |
| 4921 | |
| 4922 | void StreamingListener::SocketWriter::MakeConnection() { |
| 4923 | GTEST_CHECK_(sockfd_ == -1) |