* Return the value matching a key from a key=value pair in a URL. * * @param pszURL the URL. * @param pszKey the key to find. * @return the value of empty string if not found. */
| 498 | * @return the value of empty string if not found. |
| 499 | */ |
| 500 | CPLString CPLURLGetValue(const char *pszURL, const char *pszKey) |
| 501 | { |
| 502 | CPLString osKey(pszKey); |
| 503 | osKey += "="; |
| 504 | size_t nKeyPos = CPLString(pszURL).ifind(osKey); |
| 505 | if (nKeyPos != std::string::npos && nKeyPos > 0 && |
| 506 | (pszURL[nKeyPos - 1] == '?' || pszURL[nKeyPos - 1] == '&')) |
| 507 | { |
| 508 | CPLString osValue(pszURL + nKeyPos + osKey.size()); |
| 509 | const char *pszValue = osValue.c_str(); |
| 510 | const char *pszSep = strchr(pszValue, '&'); |
| 511 | if (pszSep) |
| 512 | { |
| 513 | osValue.resize(pszSep - pszValue); |
| 514 | } |
| 515 | return osValue; |
| 516 | } |
| 517 | return ""; |
| 518 | } |
| 519 | |
| 520 | /************************************************************************/ |
| 521 | /* CPLURLAddKVP() */ |
no test coverage detected