@Test public void testSkipComments() throws Exception { String s = "(some (((maybe))human readable) stuff())"; ByteSequence raw = ContentUtil.encode(s); ParserCursor cursor = new ParserCursor(0, s.length()); parser.skipComment(raw, cursor); Assert.assertTrue(cursor.atEnd()); }
public void skipComment(final ByteSequence buf, final ParserCursor cursor) { if (cursor.atEnd()) { return; } int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); char current = (char) (buf.byteAt(pos) & 0xff); if (current != '(') { return; } pos++; indexFrom++; int level = 1; boolean escaped = false; for (int i = indexFrom; i < indexTo; i++, pos++) { current = (char) (buf.byteAt(i) & 0xff); if (escaped) { escaped = false; } else { if (current == '\\') { escaped = true; } else if (current == '(') { level++; } else if (current == ')') { level--; } } if (level <= 0) { pos++; break; } } cursor.updatePos(pos); }
RawFieldParser { public void skipComment(final ByteSequence buf, final ParserCursor cursor) { if (cursor.atEnd()) { return; } int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); char current = (char) (buf.byteAt(pos) & 0xff); if (current != '(') { return; } pos++; indexFrom++; int level = 1; boolean escaped = false; for (int i = indexFrom; i < indexTo; i++, pos++) { current = (char) (buf.byteAt(i) & 0xff); if (escaped) { escaped = false; } else { if (current == '\\') { escaped = true; } else if (current == '(') { level++; } else if (current == ')') { level--; } } if (level <= 0) { pos++; break; } } cursor.updatePos(pos); } }
RawFieldParser { public void skipComment(final ByteSequence buf, final ParserCursor cursor) { if (cursor.atEnd()) { return; } int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); char current = (char) (buf.byteAt(pos) & 0xff); if (current != '(') { return; } pos++; indexFrom++; int level = 1; boolean escaped = false; for (int i = indexFrom; i < indexTo; i++, pos++) { current = (char) (buf.byteAt(i) & 0xff); if (escaped) { escaped = false; } else { if (current == '\\') { escaped = true; } else if (current == '(') { level++; } else if (current == ')') { level--; } } if (level <= 0) { pos++; break; } } cursor.updatePos(pos); }  }
RawFieldParser { public void skipComment(final ByteSequence buf, final ParserCursor cursor) { if (cursor.atEnd()) { return; } int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); char current = (char) (buf.byteAt(pos) & 0xff); if (current != '(') { return; } pos++; indexFrom++; int level = 1; boolean escaped = false; for (int i = indexFrom; i < indexTo; i++, pos++) { current = (char) (buf.byteAt(i) & 0xff); if (escaped) { escaped = false; } else { if (current == '\\') { escaped = true; } else if (current == '(') { level++; } else if (current == ')') { level--; } } if (level <= 0) { pos++; break; } } cursor.updatePos(pos); }  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 void skipComment(final ByteSequence buf, final ParserCursor cursor) { if (cursor.atEnd()) { return; } int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); char current = (char) (buf.byteAt(pos) & 0xff); if (current != '(') { return; } pos++; indexFrom++; int level = 1; boolean escaped = false; for (int i = indexFrom; i < indexTo; i++, pos++) { current = (char) (buf.byteAt(i) & 0xff); if (escaped) { escaped = false; } else { if (current == '\\') { escaped = true; } else if (current == '(') { level++; } else if (current == ')') { level--; } } if (level <= 0) { pos++; break; } } cursor.updatePos(pos); }  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; }