diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java index b0c6a446b..10bf96d03 100644 --- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java @@ -168,9 +168,12 @@ public static Header format(final String name, final String... tokens) { } /** - * @since 5.3 + * @since 5.4 */ - public static void parseTokens(final CharSequence src, final ParserCursor cursor, final Consumer consumer) { + public static void parseTokens(final CharSequence src, + final ParserCursor cursor, + final Tokenizer.Delimiter delimiterPredicate, + final Consumer consumer) { Args.notNull(src, "Source"); Args.notNull(cursor, "Cursor"); Args.notNull(consumer, "Consumer"); @@ -179,7 +182,7 @@ public static void parseTokens(final CharSequence src, final ParserCursor cursor if (src.charAt(pos) == ',') { cursor.updatePos(pos + 1); } - final String token = Tokenizer.INSTANCE.parseToken(src, cursor, COMMA); + final String token = Tokenizer.INSTANCE.parseToken(src, cursor, delimiterPredicate); consumer.accept(token); } } @@ -187,31 +190,57 @@ public static void parseTokens(final CharSequence src, final ParserCursor cursor /** * @since 5.3 */ - public static void parseTokens(final Header header, final Consumer consumer) { + public static void parseTokens(final CharSequence src, final ParserCursor cursor, final Consumer consumer) { + parseTokens(src, cursor, COMMA, consumer); + } + + /** + * @since 5.4 + */ + public static void parseTokens(final Header header, + final Tokenizer.Delimiter delimiterPredicate, + final Consumer consumer) { Args.notNull(header, "Header"); if (header instanceof FormattedHeader) { final CharArrayBuffer buf = ((FormattedHeader) header).getBuffer(); final ParserCursor cursor = new ParserCursor(0, buf.length()); cursor.updatePos(((FormattedHeader) header).getValuePos()); - parseTokens(buf, cursor, consumer); + parseTokens(buf, cursor, delimiterPredicate, consumer); } else { final String value = header.getValue(); final ParserCursor cursor = new ParserCursor(0, value.length()); - parseTokens(value, cursor, consumer); + parseTokens(value, cursor, delimiterPredicate, consumer); } } /** * @since 5.3 */ - public static void parseTokens(final MessageHeaders headers, final String headerName, final Consumer consumer) { + public static void parseTokens(final Header header, final Consumer consumer) { + parseTokens(header, COMMA, consumer); + } + + /** + * @since 5.4 + */ + public static void parseTokens(final MessageHeaders headers, + final String headerName, + final Tokenizer.Delimiter delimiterPredicate, + final Consumer consumer) { Args.notNull(headers, "Headers"); final Iterator
it = headers.headerIterator(headerName); while (it.hasNext()) { - parseTokens(it.next(), consumer); + parseTokens(it.next(), delimiterPredicate, consumer); } } + /** + * @since 5.3 + */ + public static void parseTokens(final MessageHeaders headers, final String headerName, final Consumer consumer) { + parseTokens(headers, headerName, COMMA, consumer); + } + public static Set parseTokens(final CharSequence src, final ParserCursor cursor) { Args.notNull(src, "Source"); Args.notNull(cursor, "Cursor");