Split string by new line or unquoted semicolon
(String text)
| 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, |