Updated Branches:
  refs/heads/camel-2.11.x e75fc01c9 -> deb4a1e7b
  refs/heads/master 44d44c53c -> 371efe7e0


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/371efe7e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/371efe7e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/371efe7e

Branch: refs/heads/master
Commit: 371efe7e03cd7ecbc353d66625ab2759216b20c2
Parents: 44d44c5
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue Jul 9 10:22:30 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Jul 9 10:25:58 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/371efe7e/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;
+    }
+
 }

Reply via email to