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.