Minus/multiplication signs

This commit is contained in:
serso 2016-01-24 21:33:30 +01:00
parent d5ddd03d99
commit b482b83007
3 changed files with 10 additions and 8 deletions

View File

@ -191,14 +191,15 @@ class SignedInteger implements Parser<String> {
@Nonnull
public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.position.intValue();
final int pos0 = p.position.intValue();
final StringBuilder result = new StringBuilder();
ParserUtils.skipWhitespaces(p);
if (p.position.intValue() < p.expression.length() && (p.expression.charAt(p.position.intValue()) == '+' || p.expression.charAt(p.position.intValue()) == '-')) {
char c = p.expression.charAt(p.position.intValue());
final int pos1 = p.position.intValue();
if (pos1 < p.expression.length() && (p.expression.charAt(pos1) == '+' || MinusParser.isMinus(p.expression.charAt(pos1)))) {
final char c = p.expression.charAt(pos1);
p.position.increment();
result.append(c);
}

View File

@ -14,7 +14,7 @@ class MultiplyFactor implements Parser<Generic> {
public static final Parser<Generic> parser = new MultiplyFactor();
private static boolean isMultiplication(char c) {
static boolean isMultiplication(char c) {
return c == '*' || c == '×' || c == '∙';
}

View File

@ -6,6 +6,8 @@ import jscl.text.msg.Messages;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static jscl.text.MultiplyFactor.isMultiplication;
/**
* User: serso
* Date: 10/27/11
@ -27,7 +29,7 @@ class PowerParser implements Parser<Void> {
if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '^') {
p.position.increment();
} else {
if (isDoubleStar(p.expression, p.position)) {
if (isDoubleStar(p.expression, p.position.intValue())) {
p.position.increment();
p.position.increment();
} else {
@ -38,8 +40,7 @@ class PowerParser implements Parser<Void> {
return null;
}
private boolean isDoubleStar(@Nonnull String string, @Nonnull MutableInt position) {
final int i = position.intValue();
return i < string.length() && i + 1 < string.length() && string.charAt(i) == '*' && string.charAt(i + 1) == '*';
private boolean isDoubleStar(@Nonnull String string, int position) {
return position + 1 < string.length() && isMultiplication(string.charAt(position)) && isMultiplication(string.charAt(position + 1));
}
}