Cmd_TokenizeString Parses the given string into command line tokens. $Cvars will be expanded unless they are in a quoted token.
(String text, boolean macroExpand)
| 196 | * unless they are in a quoted token. |
| 197 | */ |
| 198 | public static List<String> TokenizeString(String text, boolean macroExpand) { |
| 199 | List<String> result = new ArrayList<>(); |
| 200 | |
| 201 | // macro expand the text |
| 202 | if (macroExpand) |
| 203 | text = MacroExpandString(text); |
| 204 | |
| 205 | if (text == null || text.isEmpty()) |
| 206 | return result; |
| 207 | |
| 208 | Com.ParseHelp ph = new Com.ParseHelp(text); |
| 209 | |
| 210 | while (true) { |
| 211 | |
| 212 | // skip whitespace up to a \n |
| 213 | char c = ph.skipwhitestoeol(); |
| 214 | |
| 215 | if (c == '\n') { // a newline separates commands in the buffer |
| 216 | c = ph.nextchar(); |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | if (c == 0) |
| 221 | return result; |
| 222 | |
| 223 | String word = Com.Parse(ph); |
| 224 | |
| 225 | result.add(word); |
| 226 | |
| 227 | } |
| 228 | return result; |
| 229 | } |
| 230 | |
| 231 | public static void AddCommand(String cmd_name, Command function) { |
| 232 | AddCommand(cmd_name, function, false); |