@VisibleForTesting
    @SuppressWarnings("checkstyle:FallThrough")
    static void addRanges(List<MediaType> ranges, CharSequence header) {
        final int length = header.length();
        int state = ST_SKIP_LEADING_WHITESPACES;
        int firstCharIdx = 0;
        int lastCharIdx = -1;
        for (int i = 0; i < length; i++) {
            final char ch = header.charAt(i);
            switch (state) {
                case ST_SKIP_LEADING_WHITESPACES:
                    if (!Character.isWhitespace(ch)) {
                        state = ST_READ_QDTEXT;
                        firstCharIdx = i;
                        lastCharIdx = -1;
                    } else {
                        break;
                    }
                case ST_READ_QDTEXT:
                    if (Character.isWhitespace(ch)) {
                        break;
                    }
                    switch (ch) {
                        case '"':
                            state = ST_READ_QUOTED_STRING;
                            break;
                        case ',':
                            addRange(ranges, header, firstCharIdx, lastCharIdx);
                            state = ST_SKIP_LEADING_WHITESPACES;
                            break;
                        default:
                            lastCharIdx = i;
                    }
                    break;
                case ST_READ_QUOTED_STRING:
                    switch (ch) {
                        case '\\':
                            state = ST_READ_QUOTED_STRING_ESCAPED;
                            break;
                        case '"':
                            state = ST_READ_QDTEXT;
                            lastCharIdx = i;
                            break;
                    }
                    break;
                case ST_READ_QUOTED_STRING_ESCAPED:
                    state = ST_READ_QUOTED_STRING;
                    break;
            }
        }

        if (state == ST_READ_QDTEXT) {
            addRange(ranges, header, firstCharIdx, lastCharIdx);
        }
    }
Finds the {@link MediaType} in this {@link List} that matches one of the specified media ranges.

@return the most preferred {@link MediaType} that matches one of the specified media ranges.
        {@code null} if there are no matches or {@code ranges} does not contain any valid ranges.
core/src/main/java/com/linecorp/armeria/common/MediaTypeSet.java