use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class URIBuilder method formatQuery.
static void formatQuery(final StringBuilder buf, final Iterable<? extends NameValuePair> params, final Charset charset, final boolean blankAsPlus) {
int i = 0;
for (final NameValuePair parameter : params) {
if (i > 0) {
buf.append(QUERY_PARAM_SEPARATOR);
}
PercentCodec.encode(buf, parameter.getName(), charset, blankAsPlus);
if (parameter.getValue() != null) {
buf.append(PARAM_VALUE_SEPARATOR);
PercentCodec.encode(buf, parameter.getValue(), charset, blankAsPlus);
}
i++;
}
}
use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class URIBuilder method parseQuery.
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;
}
use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestHeaderElement method testConstructor3.
@Test
public void testConstructor3() throws Exception {
final HeaderElement element = new BasicHeaderElement("name", "value", new NameValuePair[] { new BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2", "value2") });
Assertions.assertEquals("name", element.getName());
Assertions.assertEquals("value", element.getValue());
Assertions.assertEquals(2, element.getParameters().length);
Assertions.assertEquals("value1", element.getParameterByName("param1").getValue());
Assertions.assertEquals("value2", element.getParameterByName("param2").getValue());
}
use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestNameValuePair method testNameNotEqual.
@Test
public void testNameNotEqual() throws Exception {
final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
final NameValuePair NameValuePair2 = new BasicNameValuePair("name2", "value");
Assertions.assertNotEquals(NameValuePair, NameValuePair2);
}
use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestNameValuePair method testValueNotEqual.
@Test
public void testValueNotEqual() throws Exception {
final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value2");
Assertions.assertNotEquals(NameValuePair, NameValuePair2);
final NameValuePair NameValuePair3 = new BasicNameValuePair("name", "value");
final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "VALUE");
Assertions.assertNotEquals(NameValuePair3, NameValuePair4);
final NameValuePair NameValuePair5 = new BasicNameValuePair("name", "VALUE");
final NameValuePair NameValuePair6 = new BasicNameValuePair("name", "value");
Assertions.assertNotEquals(NameValuePair5, NameValuePair6);
}
Aggregations