| 62 | public static final Pattern _featurePattern = Pattern.compile("(?<sign>[-+])?(?<tag>[a-z0-9]{4})(?:\\[(?<start>\\d+)?:(?<end>\\d+)?\\])?(?:=(?<value>\\d+))?"); |
| 63 | |
| 64 | public static FontFeature parseOne(String s) { |
| 65 | Matcher m = _featurePattern.matcher(s); |
| 66 | if (!m.matches()) |
| 67 | throw new IllegalArgumentException("Can’t parse FontFeature: " + s); |
| 68 | int value = m.group("value") != null ? Integer.parseInt(m.group("value")) |
| 69 | : m.group("sign") == null ? 1 |
| 70 | : "-".equals(m.group("sign")) ? 0 |
| 71 | : 1; |
| 72 | long start = m.group("start") == null ? 0 : Long.parseLong(m.group("start")); |
| 73 | long end = m.group("end") == null ? Long.MAX_VALUE : Long.parseLong(m.group("end")); |
| 74 | return new FontFeature(m.group("tag"), value, start, end); |
| 75 | } |
| 76 | |
| 77 | public static FontFeature[] parse(String s) { |
| 78 | return _splitPattern.splitAsStream(s).map(FontFeature::parseOne).toArray(FontFeature[]::new); |