Fixed negative number bug in exp4j and custom expressions.
authorrichardgraham <richardgraham@180e2498-e6e9-4542-8430-84ac67f01cd8>
Fri, 17 Aug 2012 06:21:37 +0000 (06:21 +0000)
committerrichardgraham <richardgraham@180e2498-e6e9-4542-8430-84ac67f01cd8>
Fri, 17 Aug 2012 06:21:37 +0000 (06:21 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@972 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/de/congrace/exp4j/Tokenizer.java
core/src/net/sf/openrocket/simulation/customexpression/CustomExpression.java

index 1591995ea6987b4be8d3b42817dd511a5596d275..c2c99d974d233d6bb63c21568dd6404b3d8062f0 100644 (file)
@@ -166,6 +166,7 @@ class Tokenizer {
                Token lastToken;
                for (int i = 0; i < chars.length; i++) {
                        char c = chars[i];
+                       
                        if (c == ' ')
                                continue;
                        if (isDigit(c)) {
@@ -179,12 +180,12 @@ class Tokenizer {
                                }
                                i += numberLen - 1;
                                lastToken = new NumberToken(valueBuilder.toString());
-                       } else if (Character.isLetter(c) || c == '_' || c == '#') {
+                       } else if (Character.isLetter(c) || c == '_' || c == '$') {                             
                                // can be a variable or function
                                final StringBuilder nameBuilder = new StringBuilder();
                                nameBuilder.append(c);
                                int offset = 1;
-                               while (chars.length > i + offset && (Character.isLetter(chars[i + offset]) || Character.isDigit(chars[i + offset]) || chars[i + offset] == '_' || chars[i + offset] == '#')) {
+                               while (chars.length > i + offset && (Character.isLetter(chars[i + offset]) || Character.isDigit(chars[i + offset]) || chars[i + offset] == '_' || chars[i + offset] == '$')) {
                                        nameBuilder.append(chars[i + offset++]);
                                }
                                String name = nameBuilder.toString();
index 40b3d700c4a76686980b324a7ea845648ff89067..47a5dff1fcb98ed3eef8261910006e6d15e009cb 100644 (file)
@@ -204,7 +204,7 @@ public class CustomExpression implements Cloneable{
                        return false;
                
                // No bad characters
-               for (char c : "0123456789.,()[]{}<>:#@%^&* ".toCharArray())
+               for (char c : "0123456789.,()[]{}<>:#@%^&*$ ".toCharArray())
                        if (symbol.indexOf(c) != -1 )
                                return false;
                
@@ -230,7 +230,7 @@ public class CustomExpression implements Cloneable{
                        return false;
                
                // No characters that could mess things up saving etc
-               for (char c : ",()[]{}<>#".toCharArray())
+               for (char c : ",()[]{}<>#$".toCharArray())
                        if (name.indexOf(c) != -1 )
                                return false;
                
@@ -293,6 +293,7 @@ public class CustomExpression implements Cloneable{
                                        }
                                        else break;
                                case '#' : return false;
+                               case '$' : return false;
                                case '=' : return false;
                        }
                }
@@ -465,12 +466,12 @@ public class CustomExpression implements Cloneable{
        } 
        
        /*
-        * Returns a simple all upper case string hash code with a proceeding # mark.
+        * Returns a simple all upper case string hash code with a proceeding $ mark.
         * Used for temporary substitution when evaluating index and range expressions.
         */
        public String hash(){
                Integer hashint = new Integer(this.getExpressionString().hashCode());
-               String hash = "#";
+               String hash = "$";
                for (char c : hashint.toString().toCharArray()){
                        char newc = (char) (c + 17);
                        hash = hash + newc;