You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/07/09 10:27:23 UTC
[2/2] git commit: CAMEL-6414: The unary operators in Simple is now
only applied on functions
CAMEL-6414: The unary operators in Simple is now only applied on functions
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/deb4a1e7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/deb4a1e7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/deb4a1e7
Branch: refs/heads/camel-2.11.x
Commit: deb4a1e7ba343d143e74ec8b315d8e6c1d3466fa
Parents: e75fc01
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 9 10:22:30 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 9 10:27:01 2013 +0200
----------------------------------------------------------------------
.../camel/language/simple/SimpleTokenizer.java | 35 ++++++++++++++------
1 file changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/deb4a1e7/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
index 9d59507..cd38aea 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
@@ -230,20 +230,35 @@ public final class SimpleTokenizer {
private static boolean acceptToken(SimpleTokenType token, String text, String expression, int index) {
if (token.isUnary() && text.startsWith(token.getValue())) {
- // special check for unary as the previous must be a function end, and the next a whitespace
- // to ensure unary operators is only applied on functions as intended
- int len = token.getValue().length();
- char previous = ' ';
- if (index > 0) {
- previous = expression.charAt(index - 1);
+ SimpleTokenType functionEndToken = getFunctionEndToken();
+ if (functionEndToken != null) {
+ int endLen = functionEndToken.getValue().length();
+
+ // special check for unary as the previous must be a function end, and the next a whitespace
+ // to ensure unary operators is only applied on functions as intended
+ int len = token.getValue().length();
+
+ String previous = "";
+ if (index - endLen >= 0) {
+ previous = expression.substring(index - endLen, index);
+ }
+ String after = text.substring(len);
+ boolean whiteSpace = ObjectHelper.isEmpty(after) || after.startsWith(" ");
+ boolean functionEnd = previous.equals(functionEndToken.getValue());
+ return functionEnd && whiteSpace;
}
- String after = text.substring(len);
- boolean whiteSpace = ObjectHelper.isEmpty(after) || after.startsWith(" ");
- boolean functionEnd = previous == '}';
- return functionEnd && whiteSpace;
}
return text.startsWith(token.getValue());
}
+ private static SimpleTokenType getFunctionEndToken() {
+ for (SimpleTokenType token : KNOWN_TOKENS) {
+ if (token.isFunctionEnd()) {
+ return token;
+ }
+ }
+ return null;
+ }
+
}