New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NumberFormatter: Fix the pattern default .nostyle pattern for ICU62+ #1736
Conversation
- When using NumberFormatter with .nostyle (UNUM_PATTERN_DECIMAL) the default pattern '#;#' omits the '-' symbol when formatting negative numbers using ICU versions 62 or later. - Use a default pattern of '#' which lets ICU automatically set the format for negative numbers. This pattern is the default used by ICU62. - Tested on Ubuntu14.04 with ICU 52 and Ubuntu18.04 with ICU 63.1.
@swift-ci test |
Looks reasonable, but should this be gated on |
I tested with older versions of ICU (52 on Ubuntu14.04) and it worked there. I was actually hoping that if apple/swift#19860 is merged soon we could make ICU62 (or some other recent version) a requirement for corelibs-foundation since a lot of the tests actually fail on older versions and they are just commented out to hide that fact. What do you think? I will add some more tests. |
That policy sounds reasonable. I'm still concerned about the necessity of this change though — I ended up checking this on a system with ICU 62 installed: #import <Foundation/Foundation.h>
#include <unicode/unum.h>
int main()
{
@autoreleasepool {
#define U_CHECK(status, message) if (U_FAILURE(status)) { NSLog(message @": %s", u_errorName(status)); exit(EXIT_FAILURE); }
UErrorCode status = U_ZERO_ERROR;
UNumberFormat *formatter = unum_open(UNUM_PATTERN_DECIMAL, u"#;#", -1, "en_US", NULL, &status);
U_CHECK(status, @"unum_open");
UChar result[BUFSIZ] = {0};
int32_t length = unum_format(formatter, -5, result, BUFSIZ, NULL, &status);
U_CHECK(status, @"unum_format");
NSLog(@"ICU %d.%d: %@", U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM, [[NSString alloc] initWithCharactersNoCopy:result length:length freeWhenDone:NO]);
}
} What do you see for the above? I get |
Running your test on Ubuntu18.04 gives the following: With the system supplied ICU: With the ICU compiled as as part of the swift build: I wonder if the difference is due to local changes made in Apple's fork? |
Here's a test program I wrote that retrieves the pattern after setting it and tests different patterns
Testing on Ubuntu18.04: System ICU
So when setting the pattern to ICU62 compiled as part of swift
I also tested my change on HighSierra and the corelibs-foundation tests ran ok. I haven't tested on Mojave as I don't have it installed, are you able to test this PR on Mojave? |
Given you checked, I'm going to take this, but we should investigate why the discrepancy. |
@swift-ci please test and merge |
After some internal discussion right now, I came to learn why this appeared unnecessary on Darwin: despite us having ICU-62, our internal fork did not take the number formatting changes there for stability at the time (so we continued getting away with (For anyone interested, see 46470466) |
When using NumberFormatter with .nostyle (UNUM_PATTERN_DECIMAL) the
default pattern '#;#' omits the '-' symbol when formatting negative
numbers using ICU versions 62 or later.
Use a default pattern of '#' which lets ICU automatically set the
format for negative numbers. This pattern is the default used by
ICU62.
Tested on Ubuntu14.04 with ICU 52 and Ubuntu18.04 with ICU 63.1.