MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / UrlEncode

Method UrlEncode

test/common/gtest/gtest.cpp:5267–5284  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

5265// in both time and space -- important as the input str may contain an
5266// arbitrarily long test failure message and stack trace.
5267string 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
5286void StreamingListener::SocketWriter::MakeConnection() {
5287 GTEST_CHECK_(sockfd_ == -1)

Callers

nothing calls this directly

Calls 1

push_backMethod · 0.80

Tested by

no test coverage detected