Minus/multiplication signs
This commit is contained in:
parent
d5ddd03d99
commit
b482b83007
@ -191,14 +191,15 @@ class SignedInteger implements Parser<String> {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
|
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();
|
final StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
ParserUtils.skipWhitespaces(p);
|
ParserUtils.skipWhitespaces(p);
|
||||||
|
|
||||||
if (p.position.intValue() < p.expression.length() && (p.expression.charAt(p.position.intValue()) == '+' || p.expression.charAt(p.position.intValue()) == '-')) {
|
final int pos1 = p.position.intValue();
|
||||||
char c = p.expression.charAt(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();
|
p.position.increment();
|
||||||
result.append(c);
|
result.append(c);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class MultiplyFactor implements Parser<Generic> {
|
|||||||
|
|
||||||
public static final Parser<Generic> parser = new MultiplyFactor();
|
public static final Parser<Generic> parser = new MultiplyFactor();
|
||||||
|
|
||||||
private static boolean isMultiplication(char c) {
|
static boolean isMultiplication(char c) {
|
||||||
return c == '*' || c == '×' || c == '∙';
|
return c == '*' || c == '×' || c == '∙';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ import jscl.text.msg.Messages;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static jscl.text.MultiplyFactor.isMultiplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/27/11
|
* 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()) == '^') {
|
if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '^') {
|
||||||
p.position.increment();
|
p.position.increment();
|
||||||
} else {
|
} else {
|
||||||
if (isDoubleStar(p.expression, p.position)) {
|
if (isDoubleStar(p.expression, p.position.intValue())) {
|
||||||
p.position.increment();
|
p.position.increment();
|
||||||
p.position.increment();
|
p.position.increment();
|
||||||
} else {
|
} else {
|
||||||
@ -38,8 +40,7 @@ class PowerParser implements Parser<Void> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDoubleStar(@Nonnull String string, @Nonnull MutableInt position) {
|
private boolean isDoubleStar(@Nonnull String string, int position) {
|
||||||
final int i = position.intValue();
|
return position + 1 < string.length() && isMultiplication(string.charAt(position)) && isMultiplication(string.charAt(position + 1));
|
||||||
return i < string.length() && i + 1 < string.length() && string.charAt(i) == '*' && string.charAt(i + 1) == '*';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user