@Test public void testNameValueParseBasics() { String s = "test"; ByteSequence buf = ContentUtil.encode(s); ParserCursor cursor = new ParserCursor(0, s.length()); NameValuePair param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals(null, param.getValue()); org.junit.Assert.assertEquals(s.length(), cursor.getPos()); org.junit.Assert.assertTrue(cursor.atEnd()); s = "test;"; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals(null, param.getValue()); org.junit.Assert.assertEquals(s.length(), cursor.getPos()); org.junit.Assert.assertTrue(cursor.atEnd()); s = "test=stuff"; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals("stuff", param.getValue()); org.junit.Assert.assertEquals(s.length(), cursor.getPos()); org.junit.Assert.assertTrue(cursor.atEnd()); s = " test = stuff "; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals("stuff", param.getValue()); org.junit.Assert.assertEquals(s.length(), cursor.getPos()); org.junit.Assert.assertTrue(cursor.atEnd()); s = " test = stuff ;1234"; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals("stuff", param.getValue()); org.junit.Assert.assertEquals(s.length() - 4, cursor.getPos()); org.junit.Assert.assertFalse(cursor.atEnd()); s = "test = \"stuff\""; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals("stuff", param.getValue()); s = "test = text(text of some kind)/stuff(stuff of some kind)"; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals("text/stuff", param.getValue()); s = "test = \" stuff\\\"\""; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals(" stuff\"", param.getValue()); s = "test = \" stuff\\\\\\\"\""; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals(" stuff\\\"", param.getValue()); s = " test"; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("test", param.getName()); org.junit.Assert.assertEquals(null, param.getValue()); s = " "; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("", param.getName()); org.junit.Assert.assertEquals(null, param.getValue()); s = " = stuff "; buf = ContentUtil.encode(s); cursor = new ParserCursor(0, s.length()); param = parser.parseParameter(buf, cursor); org.junit.Assert.assertEquals("", param.getName()); org.junit.Assert.assertEquals("stuff", param.getValue()); }
public NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor) { String name = parseToken(buf, cursor, EQUAL_OR_SEMICOLON); if (cursor.atEnd()) { return new NameValuePair(name, null); } int delim = buf.byteAt(cursor.getPos()); cursor.updatePos(cursor.getPos() + 1); if (delim == ';') { return new NameValuePair(name, null); } String value = parseValue(buf, cursor, SEMICOLON); if (!cursor.atEnd()) { cursor.updatePos(cursor.getPos() + 1); } return new NameValuePair(name, value); }
RawFieldParser { public NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor) { String name = parseToken(buf, cursor, EQUAL_OR_SEMICOLON); if (cursor.atEnd()) { return new NameValuePair(name, null); } int delim = buf.byteAt(cursor.getPos()); cursor.updatePos(cursor.getPos() + 1); if (delim == ';') { return new NameValuePair(name, null); } String value = parseValue(buf, cursor, SEMICOLON); if (!cursor.atEnd()) { cursor.updatePos(cursor.getPos() + 1); } return new NameValuePair(name, value); } }
RawFieldParser { public NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor) { String name = parseToken(buf, cursor, EQUAL_OR_SEMICOLON); if (cursor.atEnd()) { return new NameValuePair(name, null); } int delim = buf.byteAt(cursor.getPos()); cursor.updatePos(cursor.getPos() + 1); if (delim == ';') { return new NameValuePair(name, null); } String value = parseValue(buf, cursor, SEMICOLON); if (!cursor.atEnd()) { cursor.updatePos(cursor.getPos() + 1); } return new NameValuePair(name, value); }  }
RawFieldParser { public NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor) { String name = parseToken(buf, cursor, EQUAL_OR_SEMICOLON); if (cursor.atEnd()) { return new NameValuePair(name, null); } int delim = buf.byteAt(cursor.getPos()); cursor.updatePos(cursor.getPos() + 1); if (delim == ';') { return new NameValuePair(name, null); } String value = parseValue(buf, cursor, SEMICOLON); if (!cursor.atEnd()) { cursor.updatePos(cursor.getPos() + 1); } return new NameValuePair(name, value); }  static BitSet INIT_BITSET(int ... b); RawField parseField(final ByteSequence raw); RawBody parseRawBody(final RawField field); RawBody parseRawBody(final ByteSequence buf, final ParserCursor cursor); List<NameValuePair> parseParameters(final ByteSequence buf, final ParserCursor cursor); NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor); String parseToken(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters); String parseValue(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters); void skipWhiteSpace(final ByteSequence buf, final ParserCursor cursor); void skipComment(final ByteSequence buf, final ParserCursor cursor); void skipAllWhiteSpace(final ByteSequence buf, final ParserCursor cursor); void copyContent(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters,
            final StringBuilder dst); void copyUnquotedContent(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters,
                            final StringBuilder dst); void copyQuotedContent(final ByteSequence buf, final ParserCursor cursor,
            final StringBuilder dst); }
RawFieldParser { public NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor) { String name = parseToken(buf, cursor, EQUAL_OR_SEMICOLON); if (cursor.atEnd()) { return new NameValuePair(name, null); } int delim = buf.byteAt(cursor.getPos()); cursor.updatePos(cursor.getPos() + 1); if (delim == ';') { return new NameValuePair(name, null); } String value = parseValue(buf, cursor, SEMICOLON); if (!cursor.atEnd()) { cursor.updatePos(cursor.getPos() + 1); } return new NameValuePair(name, value); }  static BitSet INIT_BITSET(int ... b); RawField parseField(final ByteSequence raw); RawBody parseRawBody(final RawField field); RawBody parseRawBody(final ByteSequence buf, final ParserCursor cursor); List<NameValuePair> parseParameters(final ByteSequence buf, final ParserCursor cursor); NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor); String parseToken(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters); String parseValue(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters); void skipWhiteSpace(final ByteSequence buf, final ParserCursor cursor); void skipComment(final ByteSequence buf, final ParserCursor cursor); void skipAllWhiteSpace(final ByteSequence buf, final ParserCursor cursor); void copyContent(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters,
            final StringBuilder dst); void copyUnquotedContent(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters,
                            final StringBuilder dst); void copyQuotedContent(final ByteSequence buf, final ParserCursor cursor,
            final StringBuilder dst); static final RawFieldParser DEFAULT; }