GetOptS3 returns first value according to given key. key=value pair are separated by whitespace.
| 435 | // GetOptS3 returns first value according to given key. |
| 436 | // key=value pair are separated by whitespace. |
| 437 | string GetOptS3(const string &urlWithOptions, const string &key) { |
| 438 | string keyStr = " "; |
| 439 | keyStr += key; |
| 440 | keyStr += "="; |
| 441 | |
| 442 | size_t beginIndex = urlWithOptions.find(keyStr); |
| 443 | if (beginIndex == urlWithOptions.npos) { |
| 444 | return ""; |
| 445 | } else { |
| 446 | beginIndex += keyStr.length(); |
| 447 | size_t endIndex = urlWithOptions.find(" ", beginIndex); |
| 448 | |
| 449 | if (endIndex == urlWithOptions.npos) { |
| 450 | return urlWithOptions.substr(beginIndex); |
| 451 | } else { |
| 452 | return urlWithOptions.substr(beginIndex, endIndex - beginIndex); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // TruncateOptions truncates substring after first whitespace. |
| 458 | string TruncateOptions(const string &urlWithOptions) { |