Skip to content

🚧 ICU-23424 MF2: Allow registered functions to override standards#4038

Closed
srl295 wants to merge 2 commits into
unicode-org:mainfrom
srl295:srl295/mf2-override-c
Closed

🚧 ICU-23424 MF2: Allow registered functions to override standards#4038
srl295 wants to merge 2 commits into
unicode-org:mainfrom
srl295:srl295/mf2-override-c

Conversation

@srl295

@srl295 srl295 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Alternate to PR #4021
For discussion.

  • allows registered functions to override standard ones

  • add a test for overriding standard functions

  • A number of "TODO ICU-23424" mark places where the API was insufficient for overriding:

  1. was not able to call the built-in functions. Rather than expose them directly, it would be sufficient to have some kind of const MFFunctionRegistry& getDefaultFunctionRegistry() where I could call getFunction("date")… etc
  2. was not able to mutate or construct the FunctionContext. Add a builder for it.

Note: seems this fails on Windows due to linkage.

Checklist

  • Required: Issue filed: ICU-23424
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable
  • Approver: Feel free to merge on my behalf

@srl295 srl295 self-assigned this Jun 24, 2026
@srl295 srl295 changed the title ICU-23424 MF2: Allow registered functions to override standard onces 🚧 ICU-23424 MF2: Allow registered functions to override standards Jun 24, 2026
@srl295 srl295 assigned catamorphism and unassigned srl295 and catamorphism Jun 24, 2026
Comment on lines 283 to +293

if (isBuiltInFunction(functionName)) {
return standardMFFunctionRegistry.getFunction(functionName);
}
if (hasCustomMFFunctionRegistry()) {
const MFFunctionRegistry& customMFFunctionRegistry = getCustomMFFunctionRegistry();
Function* function = customMFFunctionRegistry.getFunction(functionName);
if (function != nullptr) {
return function;
}
}
if (isBuiltInFunction(functionName)) {
return standardMFFunctionRegistry.getFunction(functionName);
}

@srl295 srl295 Jun 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the only strictly necessary change, for overriding.

UnicodeString id;

public: // TODO ICU-23424 had to make this public so FunctionContext is constructable
FunctionContext(const Locale& loc, UMFBidiOption d, UnicodeString i)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than making the constructor public, I would prefer to add a public method that takes a FunctionContext and returns a new FunctionContext with a different locale, like:

FunctionContext withLocale(const Locale& loc)

because I don't see a use case for custom functions creating a FunctionContext with a different directionality or ID.

@srl295

srl295 commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

See #4041 instead

@srl295 srl295 closed this Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants