jsemver icon indicating copy to clipboard operation
jsemver copied to clipboard

Support for partial version strings?

Open ilg-ul opened this issue 10 years ago • 3 comments

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.

ilg-ul avatar Feb 13 '16 20:02 ilg-ul

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 avatar Feb 15 '16 07:02 zafarkhaja

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

zafarkhaja avatar Apr 27 '16 19:04 zafarkhaja

@zafarkhaja any ETA?

bsideup avatar Apr 28 '16 09:04 bsideup