public AddressList parseAddressList(final ByteSequence buf, final ParserCursor cursor) { List<Address> addresses = new ArrayList<Address>(); while (!cursor.atEnd()) { int pos = cursor.getPos(); int current = (char) (buf.byteAt(pos) & 0xff); if (current == COMMA) { cursor.updatePos(pos + 1); } else { Address address = parseAddress(buf, cursor, COMMA_ONLY); if (address != null) { addresses.add(address); } } } return new AddressList(addresses, false); }
List<Mailbox> parseMailboxes( final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters) { BitSet bitset = RawFieldParser.INIT_BITSET(COMMA); if (delimiters != null) { bitset.or(delimiters); } List<Mailbox> mboxes = new ArrayList<Mailbox>(); while (!cursor.atEnd()) { int pos = cursor.getPos(); int current = (char) (buf.byteAt(pos) & 0xff); if (delimiters != null && delimiters.get(current)) { break; } else if (current == COMMA) { cursor.updatePos(pos + 1); } else { Mailbox mbox = parseMailbox(buf, cursor, bitset); if (mbox != null) { mboxes.add(mbox); } } } return mboxes; }
/** * Parses the sequence of bytes containing a value with parameters into {@link RawBody}. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer */ public RawBody parseRawBody(final ByteSequence buf, final ParserCursor cursor) { String value = parseToken(buf, cursor, SEMICOLON); if (cursor.atEnd()) { return new RawBody(value, new ArrayList<NameValuePair>()); } cursor.updatePos(cursor.getPos() + 1); List<NameValuePair> params = parseParameters(buf, cursor); return new RawBody(value, params); }
/** * Transfers content into the destination buffer until a whitespace character, a comment, * a quote, or any of the given delimiters is encountered. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be <code>null</code> if the value * is delimited by a whitespace, a quote or a comment only. * @param dst destination buffer */ public void copyUnquotedContent(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { char current = (char) (buf.byteAt(i) & 0xff); if ((delimiters != null && delimiters.get(current)) || CharsetUtil.isWhitespace(current) || current == '(' || current == '\"') { break; } else { pos++; dst.append(current); } } cursor.updatePos(pos); }
/** * Transfers content into the destination buffer until a whitespace character, a comment, * or any of the given delimiters is encountered. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be <code>null</code> if the value * is delimited by a whitespace or a comment only. * @param dst destination buffer */ public void copyContent(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { char current = (char) (buf.byteAt(i) & 0xff); if ((delimiters != null && delimiters.get(current)) || CharsetUtil.isWhitespace(current) || current == '(') { break; } else { pos++; dst.append(current); } } cursor.updatePos(pos); }
cursor.updatePos(pos);
public Group parseGroup(final ByteSequence buf, final ParserCursor cursor) { String name = this.parser.parseToken(buf, cursor, COLON_ONLY); if (cursor.atEnd()) { return new Group(name, Collections.<Mailbox>emptyList()); } int pos = cursor.getPos(); int current = (char) (buf.byteAt(pos) & 0xff); if (current == COLON) { cursor.updatePos(pos + 1); } List<Mailbox> mboxes = parseMailboxes(buf, cursor, SEMICOLON_ONLY); return new Group(name, mboxes); }
/** * Skips semantically insignificant whitespace characters and moves the cursor to the closest * non-whitespace character. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer */ public void skipWhiteSpace(final ByteSequence buf, final ParserCursor cursor) { int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { char current = (char) (buf.byteAt(i) & 0xff); if (!CharsetUtil.isWhitespace(current)) { break; } else { pos++; } } cursor.updatePos(pos); }
} else if (current == AT) { cursor.updatePos(pos + 1); String domain = parseDomain(buf, cursor, delimiters); return new Mailbox(null, null, openingText, domain); } else if (current == COLON) { cursor.updatePos(pos + 1); List<Mailbox> mboxes = parseMailboxes(buf, cursor, SEMICOLON_ONLY); if (!cursor.atEnd()) { current = (char) (buf.byteAt(pos) & 0xff); if (current == SEMICOLON) { cursor.updatePos(pos + 1);
/** * Parses the sequence of bytes containing a field parameter delimited with semicolon into * {@link NameValuePair}. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer */ 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); }
pos = cursor.getPos(); if (buf.byteAt(pos) == COMMA) { cursor.updatePos(pos + 1);
public Mailbox parseMailbox( final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters) { BitSet bitset = RawFieldParser.INIT_BITSET(AT, OPENING_BRACKET); if (delimiters != null) { bitset.or(delimiters); } String openingText = this.parser.parseValue(buf, cursor, bitset); if (cursor.atEnd()) { return createMailbox(openingText); } int pos = cursor.getPos(); char current = (char) (buf.byteAt(pos) & 0xff); if (current == OPENING_BRACKET) { // name <localPart @ domain> form return parseMailboxAddress(openingText, buf, cursor); } else if (current == AT) { // localPart @ domain form cursor.updatePos(pos + 1); String domain = parseDomain(buf, cursor, delimiters); return new Mailbox(null, null, openingText, domain); } else { return createMailbox(openingText); } }
cursor.updatePos(pos);
cursor.updatePos(cursor.getPos() + 1);
char current = (char) (buf.byteAt(pos) & 0xff); if (current == OPENING_BRACKET) { cursor.updatePos(pos + 1); } else { return createMailbox(null, null, openingText, null); current = (char) (buf.byteAt(pos) & 0xff); if (current == AT) { cursor.updatePos(pos + 1); } else { return createMailbox(openingText, domainList, localPart, null); current = (char) (buf.byteAt(pos) & 0xff); if (current == CLOSING_BRACKET) { cursor.updatePos(pos + 1); } else { return createMailbox(openingText, domainList, localPart, domain);