Move split(string) to DisguiseUtilities and add unit testing

This commit is contained in:
libraryaddict
2018-10-26 02:03:00 +13:00
parent f8172ed807
commit 6525503f78
12 changed files with 231 additions and 27 deletions

View File

@@ -17,8 +17,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DisguiseParser {
private static void doCheck(CommandSender sender, DisguisePermissions permissions, DisguisePerm disguisePerm,
@@ -122,21 +120,6 @@ public class DisguiseParser {
}
}
/**
* Splits a string while respecting quotes
*/
public static String[] split(String string) {
Matcher matcher = Pattern.compile("\"(?:\"(?=\\S)|\\\\\"|[^\"])*(?:[^\\\\]\"(?=\\s|$))|\\S+").matcher(string);
List<String> list = new ArrayList<>();
while (matcher.find()) {
list.add(matcher.group());
}
return list.toArray(new String[0]);
}
/**
* Returns the disguise if it all parsed correctly. Returns a exception with a complete message if it didn't. The
* commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this