Skip to content

Commit

Permalink
Convert Pattern implementation to general java implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Dec 21, 2023
1 parent ab41fef commit dd3593b
Showing 1 changed file with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,45 @@ public String getCheckedName() {
try {
Process process = Runtime.getRuntime().exec(new String[]{"cmd", "ver"});
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), NATIVE_CHARSET))) {
Matcher matcher = Pattern.compile("(?<version>[0-9]+\\.[0-9]+\\.(?<build>[0-9]+)(\\.[0-9]+)?)]$")
.matcher(reader.readLine().trim());

if (matcher.find()) {
versionNumber = matcher.group("version");
buildNumber = Integer.parseInt(matcher.group("build"));
final String input = reader.readLine();
parseLoop:
for (int i = input.length() - 1; i >= 0; i--) {
char c = input.charAt(i);
if (c > ' ') {
if (c != ']') {
break;
}
final int end = i;
for (i --; i >= 0; i--) {
c = input.charAt(i);
if (c < '0' || c > '9') {
if (c != '.') {
break parseLoop;
}
int calcBN = 0, times = 1;
for (i --; i >= 0; i--) {
c = input.charAt(i);
if (c >= '0' && c <= '9') {
calcBN += (c - '0') * times;
times *= 10;
} else if (c == '.') {
for (i --;i >= 0;i --) {
c = input.charAt(i);
if ((c < '0' || c > '9') && c != '.') {
versionNumber = input.substring(i + 1, end);
buildNumber = calcBN;
break parseLoop;
}
}
} else {
break parseLoop;
}
}
break parseLoop;
}
}
break;
}
}
}
process.destroy();
Expand Down

0 comments on commit dd3593b

Please sign in to comment.