* @param decode if true then query parameters will be decoded
* @return {@link MultivaluedMap} with query parameters
*/
public static MultivaluedMap<String, String> parseQueryString(String rawQuery, boolean decode)
{
MultivaluedMap<String, String> m = new MultivaluedMapImpl();
if (rawQuery == null || rawQuery.length() == 0)
return m;
int p = 0;
int n = 0;
while (n < rawQuery.length())
{
n = rawQuery.indexOf('&', p);
if (n == -1)
n = rawQuery.length();
String pair = rawQuery.substring(p, n);
if (pair.length() == 0)
continue;
String name;
String value = ""; // default value
int eq = pair.indexOf('=');
if (eq == -1) // no value, default is ""
name = pair;
else
{
name = pair.substring(0, eq);
value = pair.substring(eq + 1);
}
m.add(decode ? decode(name, QUERY) : name, decode ? decode(value, QUERY) : value);
p = n + 1;
}
return m;