From ed7bbe6e1924996f8d173bd757b564f291c24c66 Mon Sep 17 00:00:00 2001 From: Joshua Quick Date: Wed, 15 Jul 2020 15:57:43 -0700 Subject: [PATCH] fix(ios): parseDecimal() whitespace thousands sep handling - For locales using whitespace for thousands/group separators (such as French), all whitespace character types should be accepted. Fixes TIMOB-27874 --- iphone/Classes/LocaleModule.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/iphone/Classes/LocaleModule.m b/iphone/Classes/LocaleModule.m index 1241c43cc59..18b377f87d5 100644 --- a/iphone/Classes/LocaleModule.m +++ b/iphone/Classes/LocaleModule.m @@ -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];