summaryrefslogtreecommitdiff
path: root/Meta/CMake
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-07-07 09:44:17 -0400
committerLinus Groh <mail@linusgroh.de>2022-07-08 11:51:54 +0200
commitea78bac36db527abe0e80dce17dc03372e4f7065 (patch)
treebb134174d3d3a0e027c7877b49a81b96e97cd20e /Meta/CMake
parent8de395694d39c4b12efbc3b3598be5c1cc80cdb0 (diff)
downloadserenity-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 'Meta/CMake')
-rw-r--r--Meta/CMake/unicode_data.cmake17
1 files changed, 17 insertions, 0 deletions
diff --git a/Meta/CMake/unicode_data.cmake b/Meta/CMake/unicode_data.cmake
index b0c66d4edc..0adbed2d50 100644
--- a/Meta/CMake/unicode_data.cmake
+++ b/Meta/CMake/unicode_data.cmake
@@ -141,6 +141,9 @@ if (ENABLE_UNICODE_DATABASE_DOWNLOAD)
set(UNICODE_NUMBER_FORMAT_HEADER LibUnicode/UnicodeNumberFormat.h)
set(UNICODE_NUMBER_FORMAT_IMPLEMENTATION LibUnicode/UnicodeNumberFormat.cpp)
+ set(UNICODE_PLURAL_RULES_HEADER LibUnicode/UnicodePluralRules.h)
+ set(UNICODE_PLURAL_RULES_IMPLEMENTATION LibUnicode/UnicodePluralRules.cpp)
+
set(UNICODE_RELATIVE_TIME_FORMAT_HEADER LibUnicode/UnicodeRelativeTimeFormat.h)
set(UNICODE_RELATIVE_TIME_FORMAT_IMPLEMENTATION LibUnicode/UnicodeRelativeTimeFormat.cpp)
@@ -159,6 +162,9 @@ if (ENABLE_UNICODE_DATABASE_DOWNLOAD)
set(UNICODE_NUMBER_FORMAT_HEADER UnicodeNumberFormat.h)
set(UNICODE_NUMBER_FORMAT_IMPLEMENTATION UnicodeNumberFormat.cpp)
+ set(UNICODE_PLURAL_RULES_HEADER UnicodePluralRules.h)
+ set(UNICODE_PLURAL_RULES_IMPLEMENTATION UnicodePluralRules.cpp)
+
set(UNICODE_RELATIVE_TIME_FORMAT_HEADER UnicodeRelativeTimeFormat.h)
set(UNICODE_RELATIVE_TIME_FORMAT_IMPLEMENTATION UnicodeRelativeTimeFormat.cpp)
@@ -202,6 +208,15 @@ if (ENABLE_UNICODE_DATABASE_DOWNLOAD)
arguments -r "${CLDR_CORE_PATH}" -n "${CLDR_NUMBERS_PATH}" -u "${CLDR_UNITS_PATH}"
)
invoke_generator(
+ "UnicodePluralRules"
+ Lagom::GenerateUnicodePluralRules
+ "${CLDR_VERSION_FILE}"
+ "${UNICODE_META_TARGET_PREFIX}"
+ "${UNICODE_PLURAL_RULES_HEADER}"
+ "${UNICODE_PLURAL_RULES_IMPLEMENTATION}"
+ arguments -r "${CLDR_CORE_PATH}" -l "${CLDR_LOCALES_PATH}"
+ )
+ invoke_generator(
"UnicodeRelativeTimeFormat"
Lagom::GenerateUnicodeRelativeTimeFormat
"${CLDR_VERSION_FILE}"
@@ -220,6 +235,8 @@ if (ENABLE_UNICODE_DATABASE_DOWNLOAD)
${UNICODE_LOCALE_IMPLEMENTATION}
${UNICODE_NUMBER_FORMAT_HEADER}
${UNICODE_NUMBER_FORMAT_IMPLEMENTATION}
+ ${UNICODE_PLURAL_RULES_HEADER}
+ ${UNICODE_PLURAL_RULES_IMPLEMENTATION}
${UNICODE_RELATIVE_TIME_FORMAT_HEADER}
${UNICODE_RELATIVE_TIME_FORMAT_IMPLEMENTATION}
)