zafarkhaja / jsemver

Java implementation of the SemVer Specification
MIT License
429 stars 82 forks source link

Support for partial version strings? #27

Closed ilg-ul closed 6 months ago

ilg-ul commented 8 years ago

I did not check the specs, but in my application I must process partial version strings, like "1.2".

The current parser accepts only "1.2.0".

I patched the VersionParser.parseVersionCore() to:

    private NormalVersion parseVersionCore() {
        int major = Integer.parseInt(numericIdentifier());
        consumeNextCharacter(DOT);
        int minor = Integer.parseInt(numericIdentifier());
        int patch;
        try {
            consumeNextCharacter(DOT);
            patch = Integer.parseInt(numericIdentifier());
        } catch (UnexpectedCharacterException e) {
            patch = 0;
        }
        return new NormalVersion(major, minor, patch);
    }

but perhaps there are better solution.

zafarkhaja commented 8 years ago

A better solution would be not to use exceptions for flow control. Instead you could use lookahead() method on the chars stream to check for the EOI token, something along the line

int patch = EOI.isMatchedBy(chars.lookahead(1)) ? 0 : Integer.parseInt(numericIdentifier());
zafarkhaja commented 8 years ago

This is sort of a duplicate of the issue #15. I'll be providing the feature with the next release.

bsideup commented 8 years ago

@zafarkhaja any ETA?