优化 GameVersionNumber.asGameVersion (#5587)

This commit is contained in:
Glavo
2026-02-21 09:09:27 +08:00
committed by GitHub
parent 2e5e21affa
commit 76370099e3

View File

@@ -390,7 +390,7 @@ public abstract sealed class GameVersionNumber implements Comparable<GameVersion
if (majorLength == 0 || value.length() < majorLength + 2 || value.charAt(majorLength) != '.')
throw new IllegalArgumentException(value);
int major = Integer.parseInt(value.substring(0, majorLength));
int major = Integer.parseInt(value, 0, majorLength, 10);
if (major != 1 && major < MINIMUM_YEAR_MAJOR_VERSION)
throw new IllegalArgumentException(value);
@@ -401,7 +401,7 @@ public abstract sealed class GameVersionNumber implements Comparable<GameVersion
throw new IllegalArgumentException(value);
try {
int minor = Integer.parseInt(value.substring(minorOffset, minorOffset + minorLength));
int minor = Integer.parseInt(value, minorOffset, minorOffset + minorLength, 10);
int patch = 0;
if (minorOffset + minorLength < value.length()) {
@@ -410,7 +410,7 @@ public abstract sealed class GameVersionNumber implements Comparable<GameVersion
if (patchOffset >= value.length() || value.charAt(patchOffset - 1) != '.')
throw new IllegalArgumentException(value);
patch = Integer.parseInt(value.substring(patchOffset));
patch = Integer.parseInt(value, patchOffset, value.length(), 10);
}
return new Release(value, value, major, minor, patch, ReleaseType.UNKNOWN, VersionNumber.ZERO, Additional.NONE);
@@ -593,8 +593,8 @@ public abstract sealed class GameVersionNumber implements Comparable<GameVersion
int year;
int week;
try {
year = Integer.parseInt(value.substring(0, 2));
week = Integer.parseInt(value.substring(3, 5));
year = Integer.parseInt(value, 0, 2, 10);
week = Integer.parseInt(value, 3, 5, 10);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(value);
}