| 275 | } |
| 276 | |
| 277 | char* UrlEscape(char* to, TStringBuf src, bool forceEscape) { |
| 278 | for (auto from = src.begin(); from != src.end(); ++from) { |
| 279 | const bool escapePercent = (*from == '%') && |
| 280 | (forceEscape || !((std::next(from) != src.end() && IsAsciiHex(*(std::next(from))) |
| 281 | && std::next(from, 2) != src.end() && IsAsciiHex(*(std::next(from, 2)))))); |
| 282 | |
| 283 | if (escapePercent || (unsigned char)*from <= ' ' || (unsigned char)*from > '~') { |
| 284 | *to++ = '%'; |
| 285 | *to++ = d2x((unsigned char)*from >> 4); |
| 286 | *to++ = d2x((unsigned char)*from & 0xF); |
| 287 | } else |
| 288 | *to++ = *from; |
| 289 | } |
| 290 | |
| 291 | *to = 0; |
| 292 | |
| 293 | return to; |
| 294 | } |
| 295 | |
| 296 | void UrlEscape(TString& url, bool forceEscape) { |
| 297 | TTempBuf tempBuf(CgiEscapeBufLen(url.size())); |
no test coverage detected