Repository navigation
[core] Add number-format expression - #14840
Conversation
|
The number-format/currency test is still disabled because there are differences in the output between GL-JS and GL-Native: Original Roundtripped through serialize() |
e4186c8 to
eaf5d02
Compare
31fa02e to
fbde1db
Compare
|
I disabled also the remaining tests. The CI test system doesn't have "en-US" locale installed, which is expected by the GL-JS tests. This causes tests to fail since the outputs don't match. Serialized
Roundtripped through serialize()
Original Roundtripped through serialize()
|
a700d8c to
44bd11f
Compare
There was a problem hiding this comment.
options seem to have just a few items, looks like std::unordered_map is an overkill, better use std::map
|
There is a quite significant binary size increase with the patch, removal of unneeded |
44bd11f to
ef6b53b
Compare
|
Use of the platforms’ built-in internationalization functionality will result in much less binary size increase compared to the current implementation in this PR. |
ef6b53b to
807f62a
Compare
1ec5
left a comment
There was a problem hiding this comment.
Thanks for implementing the iOS/macOS side of things! We’re close, but we do need to figure out the right way to manage these formatter objects, as @julianrex points out.
| uint8_t minFractionDigits, | ||
| uint8_t maxFractionDigits) { | ||
| NSNumberFormatter *_numberFormatter; | ||
| _numberFormatter = [[NSNumberFormatter alloc] init]; |
There was a problem hiding this comment.
Does this method always get called on the same thread? If so, we can initialize the object just once using dispatch_once, hold onto it statically, and modify the options each time the method is called. Otherwise, we’ll need to lazily create a different formatter for each combination of options.
Alternatively, we can drop down to CFNumberFormatter, which might not have the same overhead.
There was a problem hiding this comment.
Previously, I had suggest _numberFormatter as the variable name with the assumption that the variable would be global rather than local. The underscore is unnecessary for a local variable.
(Also, you can combine a local variable declaration and definition on the same line.)
There was a problem hiding this comment.
Thank you for the comments. Now the object is initialized just once using dispatch_once.
| uint8_t maxFractionDigits) { | ||
| NSNumberFormatter *_numberFormatter; | ||
| _numberFormatter = [[NSNumberFormatter alloc] init]; | ||
| _numberFormatter.locale = !localeId.empty() ? [NSLocale localeWithLocaleIdentifier:@(localeId.c_str())] : nil; |
There was a problem hiding this comment.
We should make sure the default locale matches the default locale of the comparison expression operators as well as the number formatter in GL JS. nil results in either the application’s current locale or the system preferred locale; can’t remember which off the top of my head.
There was a problem hiding this comment.
I checked the NSNumberFormatter documentation, but couldn't find what's the default locale in case of nil.
807f62a to
7027e47
Compare
f4fa5bd to
855e48f
Compare
855e48f to
cffc1fb
Compare
141a46b to
252658f
Compare
252658f to
a543cf8
Compare
tmpsantos
left a comment
There was a problem hiding this comment.
LGTM, just concerned about adding a dependency on QML for Qt.
| optional<std::unique_ptr<Expression>> locale_, | ||
| optional<std::unique_ptr<Expression>> currency_, | ||
| optional<std::unique_ptr<Expression>> minFractionDigits_, | ||
| optional<std::unique_ptr<Expression>> maxFractionDigits_) |
There was a problem hiding this comment.
why not just std::unique_ptr<Expression> maxFractionDigits_ , maxFractionDigits(std::move(maxFractionDigits_)); (same for others) ?
| optional<std::unique_ptr<Expression>> locale_, | ||
| optional<std::unique_ptr<Expression>> currency_, | ||
| optional<std::unique_ptr<Expression>> minFractionDigits_, | ||
| optional<std::unique_ptr<Expression>> maxFractionDigits_); |
There was a problem hiding this comment.
complex class needs not-inlined destructor
a543cf8 to
0d6c3bd
Compare
0d6c3bd to
50bdbea
Compare
pozdnyakov
left a comment
There was a problem hiding this comment.
lgtm, thanks for following
|
|
||
| QString formatted; | ||
| // Qt Locale::toString() API takes only one precision argument | ||
| (void)minFractionDigits; |
There was a problem hiding this comment.
nit: you don't need to do this, you can just remove minFractionDigits from the function signature.
Fixes: #13632