public ProtocolVersion parse()

in httpcore5/src/main/java/org/apache/hc/core5/http/ProtocolVersionParser.java [58:93]


    public ProtocolVersion parse(
            final String protocol,
            final Factory factory,
            final CharSequence buffer,
            final Tokenizer.Cursor cursor,
            final Tokenizer.Delimiter delimiterPredicate) throws ParseException {
        final int lowerBound = cursor.getLowerBound();
        final int upperBound = cursor.getUpperBound();
        final String token1 = tokenizer.parseToken(buffer, cursor,
                delimiterPredicate != null ? ch -> delimiterPredicate.test(ch) || FULL_STOP_OR_BLANK.test(ch) : FULL_STOP_OR_BLANK);
        final int major;
        try {
            major = Integer.parseInt(token1);
        } catch (final NumberFormatException e) {
            throw new ParseException("Invalid " + protocol + " major version number",
                    buffer, lowerBound, upperBound, cursor.getPos());
        }
        if (cursor.atEnd()) {
            return factory != null ? factory.create(major, major) : new ProtocolVersion(protocol, major, 0);
        }
        if (buffer.charAt(cursor.getPos()) != FULL_STOP) {
            return factory != null ? factory.create(major, major) : new ProtocolVersion(protocol, major, 0);
        } else {
            cursor.updatePos(cursor.getPos() + 1);
            final String token2 = tokenizer.parseToken(buffer, cursor,
                    delimiterPredicate != null ? ch -> delimiterPredicate.test(ch) || BLANK.test(ch) : BLANK);
            final int minor;
            try {
                minor = Integer.parseInt(token2);
            } catch (final NumberFormatException e) {
                throw new ParseException("Invalid " + protocol + " minor version number",
                        buffer, lowerBound, upperBound, cursor.getPos());
            }
            return factory != null ? factory.create(major, minor) : new ProtocolVersion(protocol, major, minor);
        }
    }