-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Intl: Add a new IntlListFormatter class #18519
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
base: master
Are you sure you want to change the base?
Intl: Add a new IntlListFormatter class #18519
Conversation
I wouldn't need an RFC if this is a straight forward addition to the existing Intl API which just maps to ICU in a straight forward fashion. I would like to see some smaller improvements, though:
The prefix makes sense to me. Using the |
Hi @TimWolla! Thanks for the suggestions - great ideas! I've pushed a commit that makes the class final and enabled those flags. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more Stub nits. Please do not add PHPDoc comments, unless they allow you to express something that the types themselves cannot.
Thanks for the quick response! I'll make the changes tomorrow. :) |
windows CI failure is related otherwise |
RETURN_THROWS(); | ||
} | ||
|
||
if (locale_len > INTL_MAX_LOCALE_LEN) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think it makes more sense to check it before the check above it.
echo $exception->getMessage(); | ||
} | ||
|
||
echo PHP_EOL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just do echo $exception->getMessage(), PHP_EOL;
|
||
intl_convert_utf8_to_utf16(&ustr, &ustr_len, ZSTR_VAL(str_val), ZSTR_LEN(str_val), &status); | ||
if (U_FAILURE(status)) { | ||
efree(items); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory, items[index so and so] might have make it until this failure thus you re gonna get some leaks.
RETURN_FALSE; | ||
} | ||
|
||
RETURN_STR(ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think RETURN_NEW_STR can be used here.
UListFormatter* ulistfmt; | ||
} listformatter_data; | ||
|
||
void listformatter_data_init( listformatter_data* lf_data ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you foresee further/wider usage ? if not, it might not be useful to unnecessarily expose them and eventually put the implementations in listformatter_class, wdyt ?
LISTFORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; \ | ||
if (LISTFORMATTER_OBJECT(lfo) == NULL) \ | ||
{ \ | ||
zend_throw_error(NULL, "Found unconstructed ListFormatter"); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to have a test triggering that case ?
This PR adds support for ICU's ListFormatter implementation by implementing a new IntlListFormatter class in PHP.
The class supports ANDs, ORs and UNIT format types. However, they are only available if ICU version is 67 or above. On older versions of ICU, we only allow TYPE_AND and WIDTH_WIDE - we need this because, from what I've understood, the minimum version ICU supported is 57, which was bumped from 50 last year.
The class API is pretty simple:
will display
I have some questions here: