Fix escaping for regex split of spaces

This commit is contained in:
Peter Dell 2024-02-03 23:29:37 +01:00
parent c22b471565
commit 6520f1e27a
1 changed files with 7 additions and 2 deletions

View File

@ -186,9 +186,10 @@ final class LanguageEditorCompileCommand {
throw new RuntimeException("Cannot show view.", ex);
}
}
/**
* Splits a string a one or more spaces, unless they are quoted.
*
* @param commandLine The command line to be split, not <code>null</code>.
* @return The array of string, may be empty, not <code>null</code>.
*/
@ -196,7 +197,11 @@ final class LanguageEditorCompileCommand {
if (commandLine == null) {
throw new IllegalArgumentException("Parameter 'commandLine' must not be null.");
}
return commandLine.split("\s+(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
return commandLine.split("\\s+(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
}
public static void main(String[] args) {
System.out.println(java.util.Arrays.toString(splitAtSpaces("\"a b\" \"c d\" e")));
}
private boolean executeInternal(ILanguageEditor languageEditor, CompilerFiles files, String commandId,