22 package com.realtime.crossfire.jxclient.skin.io;
25 import java.io.IOException;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28 import org.jetbrains.annotations.NotNull;
41 private static final String
WIDTH =
"WIDTH";
48 private static final String
HEIGHT =
"HEIGHT";
68 private static final Pattern
PATTERN_EXPR = Pattern.compile(
"([0-9]+|"+WIDTH+
"|"+HEIGHT+
"|"+WIDTH+
"/2|"+HEIGHT+
"/2|"+PREF_WIDTH+
"|"+PREF_HEIGHT+
"|"+PREF_WIDTH+
"/2|"+PREF_HEIGHT+
"/2)([-+])(.+)");
83 public static int parseInt(@NotNull
final String str)
throws IOException {
98 }
catch (
final NumberFormatException ignored) {
102 Matcher matcher = PATTERN_EXPR.matcher(str);
103 if (!matcher.matches()) {
104 throw new IOException(
"invalid number: "+str);
110 final boolean negative = matcher.group(2).equals(
"-");
111 final String rest = matcher.group(3);
113 matcher = PATTERN_EXPR.matcher(rest);
114 if (!matcher.matches()) {
116 value =
new Expression(value, negative, expressionRest);
121 value =
new Expression(value, negative, valueRest);
123 }
catch (
final NumberFormatException ex) {
124 throw new IOException(
"invalid number: "+str, ex);
139 return new Expression(Integer.parseInt(str), 0, 0, 0, 0);
140 }
catch (
final NumberFormatException ex) {
141 if (str.equals(WIDTH)) {
145 if (str.equals(HEIGHT)) {
149 if (str.equals(WIDTH+
"/2")) {
153 if (str.equals(HEIGHT+
"/2")) {
157 if (str.equals(PREF_WIDTH)) {
161 if (str.equals(PREF_HEIGHT)) {
165 if (str.equals(PREF_WIDTH+
"/2")) {
169 if (str.equals(PREF_HEIGHT+
"/2")) {
static final String HEIGHT
The identifier evaluating to the height in pixels of the current resolution.
static final String PREF_HEIGHT
The identifier evaluating to the preferred height in pixels of the current dialog.
Parser for integer expressions.
static Expression parseExpression(@NotNull final String str)
Parses an integer constant.
static int parseInt(@NotNull final String str)
Parses an integer constant.
static final String PREF_WIDTH
The identifier evaluating to the preferred width in pixels of the current dialog. ...
An expression yielding an integer value derived from a screen resolution.
int evaluateConstant()
Evaluates the expression into a constant.
static final Pattern PATTERN_EXPR
Pattern to parse integer constants.
static Expression parseIntegerConstant(@NotNull final String str)
Parses an integer constant string.
ExpressionParser()
Private constructor to prevent instantiation.
static final String WIDTH
The identifier evaluating to the width in pixels of the current resolution.