diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-07-07 09:44:17 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-08 11:51:54 +0200 |
commit | ea78bac36db527abe0e80dce17dc03372e4f7065 (patch) | |
tree | bb134174d3d3a0e027c7877b49a81b96e97cd20e /Userland/Libraries/LibUnicode/Forward.h | |
parent | 8de395694d39c4b12efbc3b3598be5c1cc80cdb0 (diff) | |
download | serenity-ea78bac36db527abe0e80dce17dc03372e4f7065.zip |
LibUnicode: Parse and generate per-locale plural rules from the CLDR
Plural rules in the CLDR are of the form:
"cs": {
"pluralRule-count-one": "i = 1 and v = 0 @integer 1",
"pluralRule-count-few": "i = 2..4 and v = 0 @integer 2~4",
"pluralRule-count-many": "v != 0 @decimal 0.0~1.5, 10.0, 100.0 ...",
"pluralRule-count-other": "@integer 0, 5~19, 100, 1000, 10000 ..."
}
The syntax is described here:
https://unicode.org/reports/tr35/tr35-numbers.html#Plural_rules_syntax
There are up to 2 sets of rules for each locale, a cardinal set and an
ordinal set. The approach here is to generate a C++ function for each
set of rules. Each condition in the rules (e.g. "i = 1 and v = 0") is
transpiled to a C++ if-statement within its function. Then lookup tables
are generated to match locales to their generated functions.
NOTE: -Wno-parentheses-equality is added to the LibUnicodeData compile
flags because the generated plural rules have lots of extra parentheses
(because e.g. we need to selectively negate and combine rules). The code
to generate only exactly the right number of parentheses is quite hairy,
so this just tells the compiler to ignore the extras.
Diffstat (limited to 'Userland/Libraries/LibUnicode/Forward.h')
-rw-r--r-- | Userland/Libraries/LibUnicode/Forward.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Userland/Libraries/LibUnicode/Forward.h b/Userland/Libraries/LibUnicode/Forward.h index 4edea7b0f5..252da3bab5 100644 --- a/Userland/Libraries/LibUnicode/Forward.h +++ b/Userland/Libraries/LibUnicode/Forward.h @@ -38,6 +38,7 @@ enum class Locale : u16; enum class MinimumDaysRegion : u8; enum class Month : u8; enum class NumericSymbol : u8; +enum class PluralCategory : u8; enum class Property : u8; enum class Script : u8; enum class ScriptTag : u8; @@ -62,6 +63,7 @@ struct LocaleID; struct NumberFormat; struct NumberGroupings; struct OtherExtension; +struct PluralOperands; struct SpecialCasing; struct TransformedExtension; struct TransformedField; |