ICU API Proposal (ICU4C MessageFormat): returning const Function pointers

20 views
Skip to first unread message

Tim Chevalier

unread,
Jul 8, 2026, 8:11:10 PMJul 8
to icu-d...@unicode.org, Icu Team
I would like to propose the following API for: ICU 79

Please provide feedback by: next Wednesday, 2026-07-15
Designated API reviewer: Markus
Ticket: https://unicode-org.atlassian.net/browse/ICU-23447
Pull request: https://github.com/unicode-org/icu/pull/4072

I would like to propose a change to the function registry API for
MessageFormat in ICU4C. (There is no accompanying change needed for
ICU4J, since Java does not have const declarations.)

In the message2::MFFunctionRegistry class:

- Function* getFunction(const FunctionName& functionName) const;
+ const Function* getFunction(const FunctionName& functionName)
const;

In the message2::Function class:

virtual LocalPointer<FunctionValue> call(const
FunctionContext& context,
const
FunctionValue& operand,
const
FunctionOptions& options,
- UErrorCode&
status) = 0;
+ UErrorCode&
status) const = 0;

This change makes all Function* pointers exposed to the user into const
pointers, which are called with a const call() method. When designing
the API, I originally made Function* non-const because Functions can
have internal state (for example, see the Counter test:
https://github.com/unicode-org/icu/blob/main/icu4c/source/test/intltest/messageformat2test.h#L264
-- this test subclasses Function with a class including a private member
tracking how many times the function was called.) However, Steven
pointed out that this can still be achieved using a layer of
indirection.

Steven R. Loomis

unread,
Jul 8, 2026, 8:22:39 PMJul 8
to Tim Chevalier, icu-d...@unicode.org, Icu Team
I support this.
I also will add two comments

- this can allow some better memory management, since the functions could be a singleton.
- this neither depends on nor is depended on by any of my other mf2 proposals.

--
Steven R. Loomis
Code Hive Tx, LLC



--
You received this message because you are subscribed to the Google Groups "ICU - Team" group.
To unsubscribe from this group and stop receiving emails from it, send an email to icu-team+u...@unicode.org.
To view this discussion visit https://groups.google.com/a/unicode.org/d/msgid/icu-team/e21f8034705c979b04185be1495a57dd%40igalia.com.

Rich Gillam

unread,
Jul 8, 2026, 8:45:43 PMJul 8
to Tim Chevalier, icu-d...@unicode.org, Icu Team
LOKTM

—Rich
> --
> You received this message because you are subscribed to the Google Groups "icu-design" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to icu-design+...@unicode.org.
> To view this discussion visit https://groups.google.com/a/unicode.org/d/msgid/icu-design/e21f8034705c979b04185be1495a57dd%40igalia.com.
> For more options, visit https://groups.google.com/a/unicode.org/d/optout.
Reply all
Reply to author
Forward
0 new messages