23 package com.realtime.crossfire.jxclient.skin.io;
26 import java.io.IOException;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29 import org.jetbrains.annotations.NotNull;
41 private static final Pattern
PATTERN_EXPR = Pattern.compile(
"(.+?) *([+-]) *(.+)");
47 private static final Pattern
PATTERN_TERM1 = Pattern.compile(
"([0-9.]+) *[*] *([A-Z_]+)");
53 private static final Pattern
PATTERN_TERM2 = Pattern.compile(
"([A-Z_]+) *[*] *([0-9.]+)");
68 public static int parseInt(@NotNull
final String str)
throws IOException {
82 if (!matcherExpr.matches()) {
88 final boolean negative =
switch (matcherExpr.group(2)) {
91 default ->
throw new AssertionError(
"unrecognized operator: "+matcherExpr.group(2));
94 final Matcher matcherExpr2 =
PATTERN_EXPR.matcher(matcherExpr.group(3));
95 if (!matcherExpr2.matches()) {
99 matcherExpr = matcherExpr2;
113 return new Expression(Integer.parseInt(str), 0, 0, 0, 0);
114 }
catch (
final NumberFormatException ignored) {
139 case "PREF_HEIGHT/2":
144 if (matcherTerm1.matches()) {
145 return parseTerm(matcherTerm1.group(1), matcherTerm1.group(2));
149 if (matcherTerm2.matches()) {
150 return parseTerm(matcherTerm2.group(2), matcherTerm2.group(1));
153 throw new IOException(
"syntax error in '"+str+
"'");
165 private static Expression parseTerm(@NotNull
final String factor, @NotNull
final String constant)
throws IOException {
168 factor2 = Float.parseFloat(factor);
169 }
catch (
final NumberFormatException ex) {
170 throw new IOException(
"invalid value '"+factor+
"'", ex);
187 throw new IOException(
"invalid constant '"+constant+
"'");