MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / decode

Method decode

src/tsd/client/QueryString.java:29–66  ·  view source on GitHub ↗

Returns the decoded key-value parameter pairs of the URI.

(final String s)

Source from the content-addressed store, hash-verified

27 * Returns the decoded key-value parameter pairs of the URI.
28 */
29 public static QueryString decode(final String s) {
30 final QueryString params = new QueryString();
31 String name = null;
32 int pos = 0; // Beginning of the unprocessed region
33 int i; // End of the unprocessed region
34 for (i = 0; i < s.length(); i++) {
35 final char c = s.charAt(i);
36 if (c == '=' && name == null) {
37 if (pos != i) {
38 name = s.substring(pos, i);
39 }
40 pos = i + 1;
41 } else if (c == '&') {
42 if (name == null && pos != i) {
43 // We haven't seen an `=' so far but moved forward.
44 // Must be a param of the form '&a&' so add it with
45 // an empty value.
46 params.add(s.substring(pos, i), "");
47 } else if (name != null) {
48 params.add(name, s.substring(pos, i));
49 name = null;
50 }
51 pos = i + 1;
52 }
53 }
54
55 if (pos != i) { // Are there characters we haven't dealt with?
56 if (name == null) { // Yes and we haven't seen any `='.
57 params.add(s.substring(pos, i), "");
58 } else { // Yes and this must be the last value.
59 params.add(name, s.substring(pos, i));
60 }
61 } else if (name != null) { // Have we seen a name without value?
62 params.add(name, "");
63 }
64
65 return params;
66 }
67
68 /**
69 * Adds a query string element.

Callers 3

getQueryStringMethod · 0.95
gotMethod · 0.45

Calls 1

addMethod · 0.95

Tested by

no test coverage detected