1package eu.siacs.conversations.ui.util;
2
3import java.util.HashMap;
4
5/**
6 * Helper methods for parsing URI's.
7 */
8public final class UriHelper {
9 /**
10 * Parses a query string into a hashmap.
11 *
12 * @param q The query string to split.
13 * @return A hashmap containing the key-value pairs from the query string.
14 */
15 public static HashMap<String, String> parseQueryString(final String q) {
16 if (q == null || q.isEmpty()) {
17 return null;
18 }
19
20 final String[] query = q.split("&");
21 // TODO: Look up the HashMap implementation and figure out what the load factor is and make sure we're not reallocating here.
22 final HashMap<String, String> queryMap = new HashMap<>(query.length);
23 for (final String param : query) {
24 final String[] pair = param.split("=");
25 queryMap.put(pair[0], pair.length == 2 && !pair[1].isEmpty() ? pair[1] : null);
26 }
27
28 return queryMap;
29 }
30}