diff options
author | Sven Gothel <[email protected]> | 2011-10-27 04:59:48 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-27 04:59:48 +0200 |
commit | ef30b77fab27262f8b5ef3f98880c0caec30bab5 (patch) | |
tree | c6242d5c742afdd3d5815f490b5ceb61a871423e /src/java/com/jogamp/common | |
parent | fa5969168440a01fab814df78a3d23d10c27f72d (diff) |
Fix VersionNumber cstr w/ string parsing: cutt-off non-digit-parts, suppress exceptions
Diffstat (limited to 'src/java/com/jogamp/common')
-rw-r--r-- | src/java/com/jogamp/common/util/VersionNumber.java | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/java/com/jogamp/common/util/VersionNumber.java b/src/java/com/jogamp/common/util/VersionNumber.java index 57c83da..1225231 100644 --- a/src/java/com/jogamp/common/util/VersionNumber.java +++ b/src/java/com/jogamp/common/util/VersionNumber.java @@ -47,26 +47,27 @@ public class VersionNumber implements Comparable { * @param delim the delimiter, e.g. "." */ public VersionNumber(String versionString, String delim) { - try { - StringTokenizer tok = new StringTokenizer(versionString, delim); - if (!tok.hasMoreTokens()) { - major = 0; - return; - } - major = Integer.valueOf(tok.nextToken()).intValue(); - if (!tok.hasMoreTokens()) { - minor = 0; - return; - } - minor = Integer.valueOf(tok.nextToken()).intValue(); - if (!tok.hasMoreTokens()) { - sub = 0; - return; - } - sub = Integer.valueOf(tok.nextToken()).intValue(); - } catch (Exception e) { - throw new IllegalArgumentException("version <"+versionString+">, delim <"+delim+">", e); + final java.util.regex.Pattern nonDigitsCutOff = java.util.regex.Pattern.compile("\\D.*"); + major = 0; + minor = 0; + sub = 0; + + StringTokenizer tok = new StringTokenizer(versionString, delim); + if (tok.hasMoreTokens()) { + try { + major = Integer.parseInt(nonDigitsCutOff.matcher(tok.nextToken()).replaceAll("")); + } catch (NumberFormatException e) { } } + if (tok.hasMoreTokens()) { + try { + minor = Integer.parseInt(nonDigitsCutOff.matcher(tok.nextToken()).replaceAll("")); + } catch (NumberFormatException e) { } + } + if (tok.hasMoreTokens()) { + try { + sub = Integer.parseInt(nonDigitsCutOff.matcher(tok.nextToken()).replaceAll("")); + } catch (NumberFormatException e) { } + } } protected VersionNumber() { } @@ -86,7 +87,7 @@ public class VersionNumber implements Comparable { public final int compareTo(Object o) { if ( ! ( o instanceof VersionNumber ) ) { - Class c = (null != o) ? o.getClass() : null ; + Class<?> c = (null != o) ? o.getClass() : null ; throw new ClassCastException("Not a Capabilities object: " + c); } |