MCPcopy Create free account
hub / github.com/demoth/jake2 / splitCommandLine

Method splitCommandLine

qcommon/src/main/java/jake2/qcommon/exec/Cbuf.java:59–85  ·  view source on GitHub ↗

Split string by new line or unquoted semicolon

(String text)

Source from the content-addressed store, hash-verified

57 * Split string by new line or unquoted semicolon
58 */
59 static List<String> splitCommandLine(String text) {
60 List<String> result = new ArrayList<>();
61 String[] lines = text.split("[\\n\\r]");
62 for (String line : lines) {
63 if (line.contains(";")) {
64 // split by ; unless it is in quotes
65 StringBuilder sb = new StringBuilder();
66 boolean inQuotes = false;
67 for (int i = 0; i < line.length(); i++) {
68 char c = line.charAt(i);
69 if (c == ';' && !inQuotes) {
70 result.add(sb.toString());
71 sb = new StringBuilder();
72 } else if (c == '"') {
73 inQuotes = !inQuotes;
74 } else {
75 sb.append(c);
76 }
77 }
78 if (sb.length() > 0)
79 result.add(sb.toString());
80 } else {
81 result.add(line);
82 }
83 }
84 return result;
85 }
86
87 /**
88 * Applies +set cvar value commands,

Callers 5

InsertTextMethod · 0.95
AddTextMethod · 0.95
testSplitMethod · 0.80
testSplitInQuotesMethod · 0.80
testNewLinesMethod · 0.80

Calls 2

addMethod · 0.45
toStringMethod · 0.45

Tested by 3

testSplitMethod · 0.64
testSplitInQuotesMethod · 0.64
testNewLinesMethod · 0.64