* @param arguments the arguments represented in a string, or {@code null} as empty arguments
* @return the parsed key-value pairs
*/
public static ParameterList parseArguments(String arguments) {
if (arguments == null || arguments.isEmpty()) {
return new ParameterList();
}
Map<String, String> results = new LinkedHashMap<String, String>();
String[] pairs = PAIRS.split(arguments);
for (String pair : pairs) {
if (pair.isEmpty()) {
continue;
}
String[] kv = KEY_VALUE.split(pair);
if (kv.length == 0) {
// in the case of "=", the regex engine returns an empty array
addArgument(results, "", "");
} else if (kv.length == 1 && kv[0].equals(pair) == false) {
// in the case of "key=", the regex engine return returns only a key
addArgument(results, unescape(kv[0]), "");
} else if (kv.length == 2) {
addArgument(results, unescape(kv[0]), unescape(kv[1]));
} else {
WGLOG.warn("W99002",
pair);
}
}
return new ParameterList(results);
}