ArgumentsTokenizer: support joining split arguments
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
ce24b3c147
commit
abdbc27618
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.commons;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ArgumentsTokenizer {
|
||||
public static String[] tokenize(String toProcess) {
|
||||
|
@ -15,7 +15,7 @@ public class ArgumentsTokenizer {
|
|||
case None -> State.QuoteSingle;
|
||||
case QuoteSingle -> State.None;
|
||||
case QuoteDouble -> {
|
||||
currentToken.append('"');
|
||||
currentToken.append('\'');
|
||||
yield State.QuoteDouble;
|
||||
}
|
||||
};
|
||||
|
@ -54,6 +54,24 @@ public class ArgumentsTokenizer {
|
|||
return tokens.toArray(String[]::new);
|
||||
}
|
||||
|
||||
public static String join(String[] args) {
|
||||
return Arrays.stream(args)
|
||||
.map(arg -> {
|
||||
arg = arg
|
||||
.replace("\\", "\\\\")
|
||||
.replace("\b", "\\b")
|
||||
.replace("\f", "\\f")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\r", "\\r")
|
||||
.replace("\t", "\\t")
|
||||
.replace("\"", "\\\"");
|
||||
if (arg.contains("\\") || arg.contains(" "))
|
||||
arg = "\"" + arg + "\"";
|
||||
return arg;
|
||||
})
|
||||
.collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
private enum State {
|
||||
None, QuoteSingle, QuoteDouble
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue