summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-27 04:59:48 +0200
committerSven Gothel <[email protected]>2011-10-27 04:59:48 +0200
commitef30b77fab27262f8b5ef3f98880c0caec30bab5 (patch)
treec6242d5c742afdd3d5815f490b5ceb61a871423e /src/java/com/jogamp/common/util
parentfa5969168440a01fab814df78a3d23d10c27f72d (diff)
Fix VersionNumber cstr w/ string parsing: cutt-off non-digit-parts, suppress exceptions
Diffstat (limited to 'src/java/com/jogamp/common/util')
-rw-r--r--src/java/com/jogamp/common/util/VersionNumber.java41
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);
}