Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<String> readCommand(Sender sender, String command) {
- boolean isInQuote = false;
- boolean isAfterQuoteExit = false;
- List<String> splits = new ArrayList();
- String current = "";
- char[] arr = command.toCharArray();
- for (int i = 0; i < command.toCharArray().length; i++) {
- char c = arr[i];
- if (c == '"') {
- isInQuote = !isInQuote;
- if (!isInQuote) {
- isAfterQuoteExit = true;
- splits.add(current);
- current = "";
- }
- continue;
- }
- if (isInQuote) {
- current += c;
- } else {
- if (c == ' ' || i == arr.length - 1) {
- if (i == arr.length - 1) {
- current += c;
- splits.add(current);
- current = "";
- }
- if (!isAfterQuoteExit) {
- splits.add(current);
- current = "";
- isAfterQuoteExit = false;
- } else {
- }
- } else {
- current += c;
- }
- }
- }
- return splits;
- }
Advertisement
Add Comment
Please, Sign In to add comment