try fix
This commit is contained in:
parent
76ecfb39ab
commit
b0dc368ef7
6 changed files with 99 additions and 23 deletions
|
@ -1,10 +1,14 @@
|
|||
package game.util;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Maps;
|
||||
import game.log.Log;
|
||||
import game.properties.IStringSerializable;
|
||||
|
||||
|
@ -322,4 +326,53 @@ int utf_len(const char *str) {
|
|||
public static Tuple<String, String> getKeyValue(String text) {
|
||||
return getKeyValue(text, ' ');
|
||||
}
|
||||
|
||||
private static Object parseObject(String arg) {
|
||||
try {
|
||||
return Float.parseFloat(arg);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(arg);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
public static Map<String, Object> parseArgsSimple(String[] args) {
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
List<Object> list = Lists.newArrayList();
|
||||
String option = null;
|
||||
boolean parse = true;
|
||||
for(int z = 0; z < args.length; z++) {
|
||||
String arg = args[z];
|
||||
if(arg.startsWith("--")) {
|
||||
if(arg.length() == 2) {
|
||||
parse = false;
|
||||
continue;
|
||||
}
|
||||
if(option != null)
|
||||
map.put(option, null);
|
||||
option = arg.substring(2);
|
||||
}
|
||||
else if(arg.startsWith("-") && arg.length() == 2) {
|
||||
if(option != null)
|
||||
map.put(option, null);
|
||||
option = arg.substring(1);
|
||||
}
|
||||
else if(option != null) {
|
||||
map.put(option, parseObject(arg));
|
||||
option = null;
|
||||
}
|
||||
else {
|
||||
list.add(parseObject(arg));
|
||||
}
|
||||
}
|
||||
if(option != null)
|
||||
map.put(option, null);
|
||||
map.put("__pos", list);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue