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;
89 switch (matcherExpr.group(2)) {
99 throw new AssertionError(
"unrecognized operator: "+matcherExpr.group(2));
102 final Matcher matcherExpr2 =
PATTERN_EXPR.matcher(matcherExpr.group(3));
103 if (!matcherExpr2.matches()) {
107 matcherExpr = matcherExpr2;
121 return new Expression(Integer.parseInt(str), 0, 0, 0, 0);
122 }
catch (
final NumberFormatException ignored) {
147 case "PREF_HEIGHT/2":
152 if (matcherTerm1.matches()) {
153 return parseTerm(matcherTerm1.group(1), matcherTerm1.group(2));
157 if (matcherTerm2.matches()) {
158 return parseTerm(matcherTerm2.group(2), matcherTerm2.group(1));
161 throw new IOException(
"syntax error in '"+str+
"'");
173 private static Expression parseTerm(@NotNull
final String factor, @NotNull
final String constant)
throws IOException {
176 factor2 = Float.parseFloat(factor);
177 }
catch (
final NumberFormatException ex) {
178 throw new IOException(
"invalid value '"+factor+
"'", ex);
195 throw new IOException(
"invalid constant '"+constant+
"'");