[refactor] Reduced complexity of argument reading by one by refactoring

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2021-11-07 11:32:33 +01:00
parent 51d8caa51e
commit 63de5448de

View File

@ -146,10 +146,7 @@ public final class GCLCConstants {
continue; continue;
} }
if (c == ' ' && !inString) { if (c == ' ' && !inString) {
final String arg = cmd.substring(startIndex, index - 1); addArgument(args, cmd.substring(startIndex, index - 1));
if (!arg.isEmpty()) {
args.add(removeEscaped(arg));
}
startIndex = index; startIndex = index;
} else if (c == '"') { } else if (c == '"') {
if (inString) { if (inString) {
@ -169,4 +166,13 @@ public final class GCLCConstants {
return args; return args;
} }
/** Add an argument to the list of arguments if it is not an empty string.
*
* @param args the list of argument
* @param arg the candidate argument */
private static void addArgument(final List<String> args, final String arg) {
if (!arg.isEmpty()) {
args.add(removeEscaped(arg));
}
}
} }