Permalink
Browse files

Merge pull request #7 from karl-/master

Check for non-alphanumeric characters on both right and left sides of equation
  • Loading branch information...
karl- committed Jun 6, 2012
2 parents a0b1cae + 3566bc9 commit 890b14c417c09dcfe933ca82e831269cf5520808
Showing with 16 additions and 14 deletions.
  1. +16 −14 DTMultiExpressionPatch.m
View
@@ -133,10 +133,11 @@ - (id)compileSourceOfType:(NSString *)sourceType
continue;
}
- NSString *resultVariable;
+ NSString *resultVariable, *rightSide;
{
resultVariable = [c objectAtIndex:0];
resultVariable = [resultVariable stringByTrimmingCharactersInSet:whitespaceCharacterSet];
+ rightSide = [[c objectAtIndex:1] stringByTrimmingCharactersInSet:whitespaceCharacterSet];
if( ![resultVariable length] )
{
@@ -149,22 +150,19 @@ - (id)compileSourceOfType:(NSString *)sourceType
continue;
}
- if([c count] > 1)
+ if( [resultVariable isEqualToString:rightSide] )
{
-// NSLog(@"first var `%@`, second var `%@`", resultVariable, [[c objectAtIndex:1] stringByTrimmingCharactersInSet:whitespaceCharacterSet]);
- if( [resultVariable isEqualToString:[[c objectAtIndex:1] stringByTrimmingCharactersInSet:whitespaceCharacterSet]] )
+ if([errors count] == 0)
{
- if([errors count] == 0)
- {
- [errors setObject:(id)kCFBooleanTrue forKey:@"error"];
- [errors setObject:@"Equation's left and right sides cannot match." forKey:@"message"];
- [errors setObject:[NSNumber numberWithUnsignedInt:lineNumber] forKey:@"line"];
- }
- continue;
+ [errors setObject:(id)kCFBooleanTrue forKey:@"error"];
+ [errors setObject:@"Equation's left and right sides cannot match." forKey:@"message"];
+ [errors setObject:[NSNumber numberWithUnsignedInt:lineNumber] forKey:@"line"];
}
+ continue;
}
-
- if( strspn([resultVariable UTF8String],"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") != [resultVariable length] )
+
+ if( strspn([resultVariable UTF8String],"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") != [resultVariable length] ||
+ strspn([rightSide UTF8String],"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789^!*%/()+-") != [rightSide length] )
{
if([errors count] == 0)
{
@@ -173,7 +171,7 @@ - (id)compileSourceOfType:(NSString *)sourceType
[errors setObject:[NSNumber numberWithUnsignedInt:lineNumber] forKey:@"line"];
}
continue;
- }
+ }
if([resultList objectForKey:resultVariable])
{
@@ -212,6 +210,7 @@ - (id)compileSourceOfType:(NSString *)sourceType
[resultList addObject:parameterInfo forKey:resultVariable];
[resultNameList addObject:line forKey:resultVariable];
}
+
NSString *exprString = [c objectAtIndex:1];
// parse
@@ -245,6 +244,9 @@ - (id)compileSourceOfType:(NSString *)sourceType
++lineNumber;
}
+ if([errors count] > 0)
+ return errors;
+
[self setParameterList:inputParams];
[self setResultList:resultList];

0 comments on commit 890b14c

Please sign in to comment.