URIBuilder { static List<NameValuePair> parseQuery(final CharSequence s, final Charset charset, final boolean plusAsBlank) { if (s == null) { return null; } final Tokenizer tokenParser = Tokenizer.INSTANCE; final ParserCursor cursor = new ParserCursor(0, s.length()); final List<NameValuePair> list = new ArrayList<>(); while (!cursor.atEnd()) { final String name = tokenParser.parseToken(s, cursor, QUERY_PARAM_SEPARATORS); String value = null; if (!cursor.atEnd()) { final int delim = s.charAt(cursor.getPos()); cursor.updatePos(cursor.getPos() + 1); if (delim == PARAM_VALUE_SEPARATOR) { value = tokenParser.parseToken(s, cursor, QUERY_VALUE_SEPARATORS); if (!cursor.atEnd()) { cursor.updatePos(cursor.getPos() + 1); } } } if (!name.isEmpty()) { list.add(new BasicNameValuePair( PercentCodec.decode(name, charset, plusAsBlank), PercentCodec.decode(value, charset, plusAsBlank))); } } return list; } URIBuilder();  URIBuilder(final String string);  URIBuilder(final URI uri);  URIBuilder(final String string, final Charset charset);  URIBuilder(final URI uri, final Charset charset); static URIBuilder localhost(); static URIBuilder loopbackAddress(); URIBuilder setCharset(final Charset charset); Charset getCharset(); URI build(); URIBuilder setScheme(final String scheme); URIBuilder setSchemeSpecificPart(final String schemeSpecificPart); URIBuilder setSchemeSpecificPart(final String schemeSpecificPart, final NameValuePair... nvps); URIBuilder setSchemeSpecificPart(final String schemeSpecificPart, final List <NameValuePair> nvps); URIBuilder setUserInfo(final String userInfo); @Deprecated URIBuilder setUserInfo(final String username, final String password); URIBuilder setHost(final InetAddress host); URIBuilder setHost(final String host); URIBuilder setHttpHost(final HttpHost httpHost ); URIBuilder setPort(final int port); URIBuilder setPath(final String path); URIBuilder setPathSegments(final String... pathSegments); URIBuilder setPathSegmentsRootless(final String... pathSegments); URIBuilder setPathSegments(final List<String> pathSegments); URIBuilder setPathSegmentsRootless(final List<String> pathSegments); URIBuilder removeQuery(); URIBuilder setParameters(final List <NameValuePair> nvps); URIBuilder addParameters(final List <NameValuePair> nvps); URIBuilder setParameters(final NameValuePair... nvps); URIBuilder addParameter(final String param, final String value); URIBuilder setParameter(final String param, final String value); URIBuilder clearParameters(); URIBuilder setCustomQuery(final String query); URIBuilder setFragment(final String fragment); boolean isAbsolute(); boolean isOpaque(); String getScheme(); String getSchemeSpecificPart(); String getUserInfo(); String getHost(); int getPort(); boolean isPathEmpty(); List<String> getPathSegments(); String getPath(); boolean isQueryEmpty(); List<NameValuePair> getQueryParams(); String getFragment(); @Override String toString();  }
@Test public void testParseQuery() throws Exception { MatcherAssert.assertThat(parseQuery(""), NameValuePairListMatcher.isEmpty()); MatcherAssert.assertThat(parseQuery("Name0"), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name0", null))); MatcherAssert.assertThat(parseQuery("Name1=Value1"), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name1", "Value1"))); MatcherAssert.assertThat(parseQuery("Name2="), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name2", ""))); MatcherAssert.assertThat(parseQuery(" Name3 "), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name3", null))); MatcherAssert.assertThat(parseQuery("Name4=Value%204%21"), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value 4!"))); MatcherAssert.assertThat(parseQuery("Name4=Value%2B4%21"), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value+4!"))); MatcherAssert.assertThat(parseQuery("Name4=Value%204%21%20%214"), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name4", "Value 4! !4"))); MatcherAssert.assertThat(parseQuery("Name5=aaa&Name6=bbb"), NameValuePairListMatcher.equalsTo( new BasicNameValuePair("Name5", "aaa"), new BasicNameValuePair("Name6", "bbb"))); MatcherAssert.assertThat(parseQuery("Name7=aaa&Name7=b%2Cb&Name7=ccc"), NameValuePairListMatcher.equalsTo( new BasicNameValuePair("Name7", "aaa"), new BasicNameValuePair("Name7", "b,b"), new BasicNameValuePair("Name7", "ccc"))); MatcherAssert.assertThat(parseQuery("Name8=xx%2C%20%20yy%20%20%2Czz"), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("Name8", "xx, yy ,zz"))); MatcherAssert.assertThat(parseQuery("price=10%20%E2%82%AC"), NameValuePairListMatcher.equalsTo(new BasicNameValuePair("price", "10 \u20AC"))); MatcherAssert.assertThat(parseQuery("a=b\"c&d=e"), NameValuePairListMatcher.equalsTo( new BasicNameValuePair("a", "b\"c"), new BasicNameValuePair("d", "e"))); MatcherAssert.assertThat(parseQuery("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8)), NameValuePairListMatcher.equalsTo( new BasicNameValuePair("russian", RU_HELLO), new BasicNameValuePair("swiss", CH_HELLO))); }