Skip to content

Commit

Permalink
fix(ios): parseDecimal() whitespace thousands sep handling
Browse files Browse the repository at this point in the history
- For locales using whitespace for thousands/group separators (such as French), all whitespace character types should be accepted.

Fixes TIMOB-27874
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Jul 16, 2020
1 parent 0cf1627 commit ed7bbe6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion iphone/Classes/LocaleModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ - (NSNumber *)parseDecimal:(NSString *)text withLocaleId:(id)localeId
}

// Remove localized thousands separators from string if they exist. NSScanner fails to parse them.
// Note: If locale uses whitespace separators (like French), then remove all whitespace character types.
NSString *thousandsSeparator = [locale objectForKey:NSLocaleGroupingSeparator];
text = [text stringByReplacingOccurrencesOfString:thousandsSeparator withString:@""];
NSCharacterSet *whitespaceCharSet = [NSCharacterSet whitespaceCharacterSet];
if ([thousandsSeparator rangeOfCharacterFromSet: whitespaceCharSet].location != NSNotFound) {
if ([text rangeOfCharacterFromSet: whitespaceCharSet].location != NSNotFound) {
text = [[text componentsSeparatedByCharactersInSet: whitespaceCharSet] componentsJoinedByString: @""];
}
} else {
text = [text stringByReplacingOccurrencesOfString:thousandsSeparator withString:@""];
}

// Attempt to parse a number from given text. Return not-a-number if failed.
NSScanner *scanner = [NSScanner localizedScannerWithString:text];
Expand Down

0 comments on commit ed7bbe6

Please sign in to comment.