SemVer (@Nullable String text) { if (text != null) { int majorEndIdx = text.indexOf('.'); if (majorEndIdx >= 0) { int minorEndIdx = text.indexOf('.', majorEndIdx + 1); if (minorEndIdx >= 0) { int preReleaseIdx = text.indexOf('-', minorEndIdx + 1); int patchEndIdx = preReleaseIdx >= 0 ? preReleaseIdx : text.length(); int major = StringUtilRt.parseInt(text.substring(0, majorEndIdx), -1); int minor = StringUtilRt.parseInt(text.substring(majorEndIdx + 1, minorEndIdx), -1); int patch = StringUtilRt.parseInt(text.substring(minorEndIdx + 1, patchEndIdx), -1); String preRelease = preReleaseIdx >= 0 ? text.substring(preReleaseIdx + 1) : null; if (major >= 0 && minor >= 0 && patch >= 0) { return new SemVer(text, major, minor, patch, preRelease); } } } } return null; }