use of org.apache.hc.core5.http.message.copied.ParserCursor in project light-4j by networknt.
the class DistinguishedNameParser method parse.
List<NameValuePair> parse(final CharArrayBuffer buf, final ParserCursor cursor) {
final List<NameValuePair> params = new ArrayList<>();
tokenParser.skipWhiteSpace(buf, cursor);
while (!cursor.atEnd()) {
final NameValuePair param = parseParameter(buf, cursor);
params.add(param);
}
return params;
}
use of org.apache.hc.core5.http.message.copied.ParserCursor in project httpcomponents-core by apache.
the class TestBasicHeaderValueParser method testHEFringeCase1.
@Test
public void testHEFringeCase1() throws Exception {
final String headerValue = "name1 = value1,";
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.append(headerValue);
final ParserCursor cursor = new ParserCursor(0, buf.length());
final HeaderElement[] elements = this.parser.parseElements(buf, cursor);
Assertions.assertEquals(1, elements.length, "Number of elements");
}
use of org.apache.hc.core5.http.message.copied.ParserCursor in project httpcomponents-core by apache.
the class TestBasicHeaderValueParser method testHEFringeCase3.
@Test
public void testHEFringeCase3() throws Exception {
final String headerValue = ",, ,, ,";
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.append(headerValue);
final ParserCursor cursor = new ParserCursor(0, buf.length());
final HeaderElement[] elements = this.parser.parseElements(buf, cursor);
Assertions.assertEquals(0, elements.length, "Number of elements");
}
use of org.apache.hc.core5.http.message.copied.ParserCursor in project httpcomponents-core by apache.
the class TestBasicHeaderValueParser method testHEFringeCase2.
@Test
public void testHEFringeCase2() throws Exception {
final String headerValue = "name1 = value1, ";
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.append(headerValue);
final ParserCursor cursor = new ParserCursor(0, buf.length());
final HeaderElement[] elements = this.parser.parseElements(buf, cursor);
Assertions.assertEquals(1, elements.length, "Number of elements");
}
use of org.apache.hc.core5.http.message.copied.ParserCursor in project httpcomponents-core by apache.
the class TestBasicHeaderValueParser method testNVParse.
@Test
public void testNVParse() {
String s = "test";
CharArrayBuffer buffer = new CharArrayBuffer(64);
buffer.append(s);
ParserCursor cursor = new ParserCursor(0, s.length());
NameValuePair param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertNull(param.getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = "test;";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertNull(param.getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = "test ,12";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertNull(param.getValue());
Assertions.assertEquals(s.length() - 2, cursor.getPos());
Assertions.assertFalse(cursor.atEnd());
s = "test=stuff";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals("stuff", param.getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = " test = stuff ";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals("stuff", param.getValue());
Assertions.assertEquals(s.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
s = " test = stuff ;1234";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals("stuff", param.getValue());
Assertions.assertEquals(s.length() - 4, cursor.getPos());
Assertions.assertFalse(cursor.atEnd());
s = "test = \"stuff\"";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals("stuff", param.getValue());
s = "test = \" stuff\\\"\"";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertEquals(" stuff\"", param.getValue());
s = " test";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("test", param.getName());
Assertions.assertNull(param.getValue());
s = " ";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("", param.getName());
Assertions.assertNull(param.getValue());
s = " = stuff ";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
param = this.parser.parseNameValuePair(buffer, cursor);
Assertions.assertEquals("", param.getName());
Assertions.assertEquals("stuff", param.getValue());
}
Aggregations