diff --git a/SA_DB_StringFormatRules.plist b/SA_DB_StringFormatRules.plist index 2597f6f..0c8591d 100644 --- a/SA_DB_StringFormatRules.plist +++ b/SA_DB_StringFormatRules.plist @@ -9,7 +9,7 @@ SA_DB_VALID_OPERATOR_CHARACTERS SA_DB_OPERATOR_MINUS - -–− + -–−﹣- SA_DB_OPERATOR_PLUS + SA_DB_OPERATOR_TIMES @@ -23,11 +23,11 @@ SA_DB_CANONICAL_OPERATOR_REPRESENTATIONS SA_DB_OPERATOR_MINUS - - + SA_DB_OPERATOR_PLUS + SA_DB_OPERATOR_TIMES - * + × SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION d diff --git a/SA_DiceExpressionStringConstants.h b/SA_DiceExpressionStringConstants.h index 2acccb1..2514e3d 100644 --- a/SA_DiceExpressionStringConstants.h +++ b/SA_DiceExpressionStringConstants.h @@ -160,4 +160,4 @@ extern NSString * const SA_DB_CANONICAL_OPERATOR_REPRESENTATIONS; // The value for the key SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION // is the canonical representation of the die roll command delimiter. -extern NSString * const SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION; \ No newline at end of file +extern NSString * const SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION; diff --git a/SA_DiceFormatter.m b/SA_DiceFormatter.m index dfdf2df..4c14fa5 100644 --- a/SA_DiceFormatter.m +++ b/SA_DiceFormatter.m @@ -197,7 +197,9 @@ static NSDictionary *_stringFormatRules; } } - return formattedString; + // Make all instances of the minus sign be represented with the proper, + // canonical minus sign. + return [self rectifyMinusSignInString:formattedString]; } - (NSString *)legacyStringFromIntermediaryExpression:(NSDictionary *)expression @@ -377,13 +379,34 @@ static NSDictionary *_stringFormatRules; [formattedString appendFormat:@"ERROR"]; } - return formattedString; + // Make all instances of the minus sign be represented with the proper, + // canonical minus sign. + return [self rectifyMinusSignInString:formattedString]; } /****************************/ #pragma mark - Helper methods /****************************/ +- (NSString *)rectifyMinusSignInString:(NSString *)aString +{ + __block NSMutableString* sameStringButMutable = aString.mutableCopy; + NSLog(@"%@", sameStringButMutable); + + NSString *validMinusSignCharacters = [SA_DiceFormatter stringFormatRules][SA_DB_VALID_CHARACTERS][SA_DB_VALID_OPERATOR_CHARACTERS][SA_DB_OPERATOR_MINUS]; + NSString *theRealMinusSign = [SA_DiceFormatter canonicalRepresentationForOperator:SA_DB_OPERATOR_MINUS]; + + [validMinusSignCharacters enumerateSubstringsInRange:NSMakeRange(0, validMinusSignCharacters.length) + options:NSStringEnumerationByComposedCharacterSequences + usingBlock:^(NSString *character, NSRange characterRange, NSRange enclosingRange, BOOL *stop) + { + [sameStringButMutable replaceOccurrencesOfString:character withString:theRealMinusSign options:NSLiteralSearch range:NSMakeRange(0, sameStringButMutable.length)]; + }]; + NSLog(@"%@", sameStringButMutable); + + return sameStringButMutable.copy; +} + + (void)loadErrorDescriptions { NSString* errorDescriptionsPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"SA_DB_ErrorDescriptions" ofType:@"plist"];