Guest User

Untitled

a guest
Jun 9th, 2015
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. public List<String> readCommand(Sender sender, String command) {
  2.     boolean isInQuote = false;
  3.     boolean isAfterQuoteExit = false;
  4.     List<String> splits = new ArrayList();
  5.     String current = "";
  6.     char[] arr = command.toCharArray();
  7.     for (int i = 0; i < command.toCharArray().length; i++) {
  8.         char c = arr[i];
  9.         if (c == '"') {
  10.         isInQuote = !isInQuote;
  11.  
  12.         if (!isInQuote) {
  13.             isAfterQuoteExit = true;
  14.             splits.add(current);
  15.             current = "";
  16.         }
  17.         continue;
  18.         }
  19.  
  20.         if (isInQuote) {
  21.         current += c;
  22.         } else {
  23.         if (c == ' ' || i == arr.length - 1) {
  24.             if (i == arr.length - 1) {
  25.             current += c;
  26.             splits.add(current);
  27.             current = "";
  28.             }
  29.             if (!isAfterQuoteExit) {
  30.             splits.add(current);
  31.             current = "";
  32.             isAfterQuoteExit = false;
  33.             } else {
  34.             }
  35.         } else {
  36.             current += c;
  37.         }
  38.         }
  39.     }
  40.  
  41.     return splits;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment