NAME
Locale::Unicode::RBNF::PluralFormat - Plural sub-messages in rule-based number formats
SYNOPSIS
use Locale::Unicode::RBNF::PluralFormat;
my $st;
my $pf = Locale::Unicode::RBNF::PluralFormat->new( $plural_rules, 'one{st}two{nd}few{rd}other{th}', undef, \$st );
die( $st ) if( $st );
say $pf->format( 22, \$st );
# nd
VERSION
v0.1.0
DESCRIPTION
Internal module. It handles the plural-only message patterns that rule-based number format rules embed between $( and )$, as ICU PluralFormat does for RuleBasedNumberFormat.
CONSTRUCTOR
new
my $pf = Locale::Unicode::RBNF::PluralFormat->new( $plural_rules, $pattern, $number_format, \$st );
Takes a Locale::Unicode::RBNF::PluralRules object, a plural-only message pattern, a Locale::Unicode::RBNF::DecimalFormat object used to replace # in a sub-message, which may be undef, and a scalar reference that receives an error status, and returns a new object.
The pattern may start with offset: followed by a number, and consists of selectors, either a plural keyword or an explicit value such as =0, each followed by its sub-message between braces. Apostrophe quoting follows the default ApostropheMode of ICU MessageFormat, DOUBLE_OPTIONAL.
The object is always returned. If the pattern is invalid, or has no other variant, the status is set to an error message, and the caller must check it.
METHODS
format
my $string = $pf->format( $number, \$st );
Returns the sub-message selected for the number: an explicit value matching the number takes precedence, then the keyword selected by the plural rules for the number minus the offset, then other. In the sub-message, # is replaced with the number minus the offset, formatted with the decimal format, and apostrophe quoting is resolved.
It returns an empty string if no variant matches.
parse_type
my( $begin, $end ) = $pf->parse_type( $source, $rule, $starting_at );
This is ICU PluralFormat::parseType(): it finds, in $source, at or after the position $starting_at, the longest sub-message of the pattern, and returns the positions of its beginning and of its end, or ( -1, -1 ) if none is found. When a sub-message is not found as is and a rule is given, the lenient matching of that rule, $rule, is tried. As in ICU, the sub-messages of explicit values, such as =1, are never matched.
This method is provided by Locale::Unicode::RBNF::PP, and used by the pure Perl parsing engine.
to_pattern
Returns the pattern given to "new".
SEE ALSO
Locale::Unicode::RBNF, Locale::Unicode::RBNF::PluralRules
AUTHOR
Jacques Deguest <jack@deguest.jp>
COPYRIGHT & LICENSE
Copyright(c) 2026 DEGUEST Pte. Ltd.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.