Cleanup splitting string into a pair
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
parent
609b30110b
commit
ac5b74301e
@ -54,10 +54,12 @@
|
||||
|
||||
package org.prismlauncher;
|
||||
|
||||
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.launcher.LauncherFactory;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@ -66,8 +68,8 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class EntryPoint {
|
||||
|
||||
public final class EntryPoint {
|
||||
private static final Logger LOGGER = Logger.getLogger("EntryPoint");
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -80,29 +82,21 @@ public final class EntryPoint {
|
||||
}
|
||||
}
|
||||
|
||||
private static PreLaunchAction parseLine(String inData, Parameters params) throws ParseException {
|
||||
if (inData.isEmpty())
|
||||
private static PreLaunchAction parseLine(String input, Parameters params) throws ParseException {
|
||||
if (input.isEmpty())
|
||||
throw new ParseException("Unexpected empty string!");
|
||||
|
||||
String first = inData;
|
||||
String second = null;
|
||||
int splitPoint = inData.indexOf(' ');
|
||||
|
||||
if (splitPoint != -1) {
|
||||
first = first.substring(0, splitPoint);
|
||||
second = inData.substring(splitPoint + 1);
|
||||
}
|
||||
|
||||
switch (first) {
|
||||
case "launch":
|
||||
if ("launch".equalsIgnoreCase(input)) {
|
||||
return PreLaunchAction.LAUNCH;
|
||||
case "abort":
|
||||
} else if ("abort".equalsIgnoreCase(input)) {
|
||||
return PreLaunchAction.ABORT;
|
||||
default:
|
||||
if (second == null || second.isEmpty())
|
||||
throw new ParseException("Error while parsing:" + inData);
|
||||
} else {
|
||||
String[] pair = StringUtils.splitStringPair(' ', input);
|
||||
if (pair == null)
|
||||
throw new ParseException("Error while parsing:" + input);
|
||||
|
||||
params.add(first, second);
|
||||
params.add(pair[0], pair[1]);
|
||||
|
||||
return PreLaunchAction.PROCEED;
|
||||
}
|
||||
@ -112,10 +106,7 @@ public final class EntryPoint {
|
||||
Parameters parameters = new Parameters();
|
||||
PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED;
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
System.in,
|
||||
StandardCharsets.UTF_8
|
||||
))) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
|
||||
while (preLaunchAction == PreLaunchAction.PROCEED) {
|
||||
@ -161,6 +152,7 @@ public final class EntryPoint {
|
||||
ABORT
|
||||
}
|
||||
|
||||
|
||||
private enum ExitCode {
|
||||
NORMAL(0),
|
||||
ERROR(1);
|
||||
|
@ -58,6 +58,7 @@ package org.prismlauncher.launcher.impl;
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
import org.prismlauncher.utils.StringUtils;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
@ -102,12 +103,12 @@ public abstract class AbstractLauncher implements Launcher {
|
||||
} else {
|
||||
maximize = false;
|
||||
|
||||
int byIndex = windowParams.indexOf('x');
|
||||
String[] sizePair = StringUtils.splitStringPair('x', windowParams);
|
||||
|
||||
if (byIndex != -1) {
|
||||
if (sizePair != null) {
|
||||
try {
|
||||
width = Integer.parseInt(windowParams.substring(0, byIndex));
|
||||
height = Integer.parseInt(windowParams.substring(byIndex + 1));
|
||||
width = Integer.parseInt(sizePair[0]);
|
||||
height = Integer.parseInt(sizePair[1]);
|
||||
return;
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
|
15
libraries/launcher/org/prismlauncher/utils/StringUtils.java
Normal file
15
libraries/launcher/org/prismlauncher/utils/StringUtils.java
Normal file
@ -0,0 +1,15 @@
|
||||
package org.prismlauncher.utils;
|
||||
|
||||
|
||||
public final class StringUtils {
|
||||
private StringUtils() {
|
||||
}
|
||||
|
||||
public static String[] splitStringPair(char splitChar, String input) {
|
||||
int splitPoint = input.indexOf(splitChar);
|
||||
if (splitPoint == -1)
|
||||
return null;
|
||||
|
||||
return new String[]{ input.substring(0, splitPoint), input.substring(splitPoint + 1) };
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user