|
11 | 11 | import me.hsgamer.hscore.common.CollectionUtils; |
12 | 12 |
|
13 | 13 | import java.util.List; |
14 | | -import java.util.Optional; |
15 | | -import java.util.regex.Matcher; |
16 | | -import java.util.regex.Pattern; |
17 | 14 | import java.util.stream.Collectors; |
18 | 15 |
|
19 | 16 | /** |
@@ -51,19 +48,41 @@ public List<Action> build(Menu menu, Object object) { |
51 | 48 | } |
52 | 49 |
|
53 | 50 | public interface Input extends ActionInput, MenuElement { |
54 | | - Pattern pattern = Pattern.compile("\\s*([\\w\\-$]+)\\s*(?:\\((.*?)\\))?\\s*(?::\\s*(.*))?"); |
| 51 | + static ActionInput create(String input) { |
| 52 | + input = input.trim(); |
55 | 53 |
|
56 | | - static Input create(Menu menu, String input) { |
57 | | - ActionInput actionInput; |
58 | | - Matcher matcher = pattern.matcher(input); |
59 | | - if (matcher.matches()) { |
60 | | - String type = matcher.group(1); |
61 | | - String option = Optional.ofNullable(matcher.group(2)).orElse(""); |
62 | | - String value = Optional.ofNullable(matcher.group(3)).orElse(""); |
63 | | - actionInput = ActionInput.create(type, option, value); |
| 54 | + // Find the colon to separate type/option from value |
| 55 | + int colonIndex = input.indexOf(':'); |
| 56 | + String typeOptionPart = colonIndex == -1 ? input : input.substring(0, colonIndex); |
| 57 | + String value = colonIndex == -1 ? "" : input.substring(colonIndex + 1).trim(); |
| 58 | + |
| 59 | + typeOptionPart = typeOptionPart.trim(); |
| 60 | + |
| 61 | + // Find the opening parenthesis to separate type from option |
| 62 | + int openParenIndex = typeOptionPart.indexOf('('); |
| 63 | + String type; |
| 64 | + String option = ""; |
| 65 | + |
| 66 | + if (openParenIndex == -1) { |
| 67 | + type = typeOptionPart; |
64 | 68 | } else { |
65 | | - actionInput = ActionInput.create("", "", input); |
| 69 | + type = typeOptionPart.substring(0, openParenIndex).trim(); |
| 70 | + int closeParenIndex = typeOptionPart.lastIndexOf(')'); |
| 71 | + if (closeParenIndex > openParenIndex) { |
| 72 | + option = typeOptionPart.substring(openParenIndex + 1, closeParenIndex).trim(); |
| 73 | + } |
66 | 74 | } |
| 75 | + |
| 76 | + // If no type is found, use the entire input as value |
| 77 | + if (type.isEmpty() && value.isEmpty()) { |
| 78 | + return ActionInput.create("", "", input); |
| 79 | + } |
| 80 | + |
| 81 | + return ActionInput.create(type, option, value); |
| 82 | + } |
| 83 | + |
| 84 | + static Input create(Menu menu, String input) { |
| 85 | + ActionInput actionInput = create(input); |
67 | 86 | return new Input() { |
68 | 87 | @Override |
69 | 88 | public String getType() { |
|
0 commit comments