Add minus sign rectification in output

This commit is contained in:
Said Achmiz 2016-05-10 04:02:36 -04:00
parent 8ef9920c62
commit d58f0748bd
3 changed files with 29 additions and 6 deletions

View File

@ -9,7 +9,7 @@
<key>SA_DB_VALID_OPERATOR_CHARACTERS</key> <key>SA_DB_VALID_OPERATOR_CHARACTERS</key>
<dict> <dict>
<key>SA_DB_OPERATOR_MINUS</key> <key>SA_DB_OPERATOR_MINUS</key>
<string>-</string> <string>-﹣-</string>
<key>SA_DB_OPERATOR_PLUS</key> <key>SA_DB_OPERATOR_PLUS</key>
<string>+</string> <string>+</string>
<key>SA_DB_OPERATOR_TIMES</key> <key>SA_DB_OPERATOR_TIMES</key>
@ -23,11 +23,11 @@
<key>SA_DB_CANONICAL_OPERATOR_REPRESENTATIONS</key> <key>SA_DB_CANONICAL_OPERATOR_REPRESENTATIONS</key>
<dict> <dict>
<key>SA_DB_OPERATOR_MINUS</key> <key>SA_DB_OPERATOR_MINUS</key>
<string>-</string> <string></string>
<key>SA_DB_OPERATOR_PLUS</key> <key>SA_DB_OPERATOR_PLUS</key>
<string>+</string> <string>+</string>
<key>SA_DB_OPERATOR_TIMES</key> <key>SA_DB_OPERATOR_TIMES</key>
<string>*</string> <string>×</string>
</dict> </dict>
<key>SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION</key> <key>SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION</key>
<string>d</string> <string>d</string>

View File

@ -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 - (NSString *)legacyStringFromIntermediaryExpression:(NSDictionary *)expression
@ -377,13 +379,34 @@ static NSDictionary *_stringFormatRules;
[formattedString appendFormat:@"ERROR"]; [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 #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 + (void)loadErrorDescriptions
{ {
NSString* errorDescriptionsPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"SA_DB_ErrorDescriptions" ofType:@"plist"]; NSString* errorDescriptionsPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"SA_DB_ErrorDescriptions" ofType:@"plist"];