Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for partial version strings? #27

Closed
ilg-ul opened this issue Feb 13, 2016 · 3 comments
Closed

Support for partial version strings? #27

ilg-ul opened this issue Feb 13, 2016 · 3 comments

Comments

@ilg-ul
Copy link

ilg-ul commented Feb 13, 2016

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
Copy link
Owner

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
Copy link
Owner

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

@bsideup
Copy link

bsideup commented Apr 28, 2016

@zafarkhaja any ETA?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants