Skip to content

ext/intl: Migrate formatter, listformatter, and rangeformatter from I…#21378

Merged
devnexen merged 3 commits into
php:masterfrom
devnexen:intl_to_cxx_internals_1
May 16, 2026
Merged

ext/intl: Migrate formatter, listformatter, and rangeformatter from I…#21378
devnexen merged 3 commits into
php:masterfrom
devnexen:intl_to_cxx_internals_1

Conversation

@devnexen
Copy link
Copy Markdown
Member

@devnexen devnexen commented Mar 7, 2026

…CU C API to C++ API.

  • formatter: Replace intl_convert_utf8_to_utf16/uloc_getISO3Language with intl_stringFromChar/icu::Locale, use UnicodeString for pattern handling
  • listformatter: Replace ulistfmt_open/ulistfmt_openForType/ulistfmt_close/ ulistfmt_format with ListFormatter C++ equivalents, use UnicodeString array and intl_stringFromChar/intl_charFromString for string conversions
  • rangeformatter: Replace uloc_getISO3Language with icu::Locale::getISO3Language

…CU C API to C++ API.

- formatter: Replace intl_convert_utf8_to_utf16/uloc_getISO3Language with
  intl_stringFromChar/icu::Locale, use UnicodeString for pattern handling
- listformatter: Replace ulistfmt_open/ulistfmt_openForType/ulistfmt_close/
  ulistfmt_format with ListFormatter C++ equivalents, use UnicodeString array
  and intl_stringFromChar/intl_charFromString for string conversions
- rangeformatter: Replace uloc_getISO3Language with icu::Locale::getISO3Language
Replace UNumberFormat*/unum_* with icu::NumberFormat C++ equivalents.
Attribute get/set still use reinterpret_cast<UNumberFormat*> for now.

Note: formatter_fail.phpt expectation updated because
NumberFormat::createInstance() returns U_ILLEGAL_ARGUMENT_ERROR for
out-of-range styles (style < 0), whereas unum_open() returned
U_UNSUPPORTED_ERROR via its default switch case.
@devnexen devnexen force-pushed the intl_to_cxx_internals_1 branch from d812f7c to e6e5a66 Compare March 7, 2026 20:10
@devnexen devnexen marked this pull request as ready for review March 7, 2026 20:45
@devnexen devnexen requested a review from Girgias May 10, 2026 14:29
@Girgias Girgias removed their request for review May 11, 2026 10:54
@Girgias
Copy link
Copy Markdown
Member

Girgias commented May 11, 2026

I don't know C++, someone else will need to review this.

@devnexen
Copy link
Copy Markdown
Member Author

I don't know C++, someone else will need to review this.

@TimWolla to the rescue then :)

@TimWolla TimWolla self-requested a review May 13, 2026 07:56
Copy link
Copy Markdown
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remarks. I can't yet say that I fully understand the changes.

Comment thread ext/intl/listformatter/listformatter_class.cpp Outdated
Comment thread ext/intl/formatter/formatter_format.cpp
formatted = eumalloc(formatted_len);
unum_formatDoubleCurrency(FORMATTER_OBJECT(nfo), number, scurrency, formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo));
/* Format using CurrencyAmount. */
icu::CurrencyAmount *currAmt = new icu::CurrencyAmount(number, ucurrency.getTerminatedBuffer(), INTL_DATA_ERROR_CODE(nfo));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a smart pointer / stack allocated or does this cause issues with adoptObject()?

Comment thread ext/intl/formatter/formatter_parse.cpp
Comment thread ext/intl/formatter/formatter_parse.cpp Outdated
Comment thread ext/intl/formatter/formatter_attr.cpp
Copy link
Copy Markdown
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't check the usage of the ICU API in detail. Given that the tests still pass, I trust you on that. From what I can tell the “C++ usage” seems correct and I'm not seeing any more obvious issues.

@devnexen devnexen merged commit 3ed80a1 into php:master May 16, 2026
18 of 19 checks passed
@devnexen devnexen deleted the intl_to_cxx_internals_1 branch May 16, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants