mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibUnicode: Replace NumberFormat::Plurality with Unicode::PluralCategory
To prepare for using plural rules within number & duration format, this removes the NumberFormat::Plurality enumeration. This also adds PluralCategory::ExactlyZero & PluralCategory::ExactlyOne. These are used in locales like French, where PluralCategory::One really means any value from 0.00 to 1.99. PluralCategory::ExactlyOne means only the value 1, as the name implies. These exact rules are not known by the general plural rules, they are explicitly for number / currency format.
This commit is contained in:
parent
cc5c707649
commit
232df4196b
3 changed files with 26 additions and 40 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibUnicode/Forward.h>
|
||||
#include <LibUnicode/PluralRules.h>
|
||||
|
||||
namespace Unicode {
|
||||
|
||||
|
@ -36,19 +37,9 @@ enum class CompactNumberFormatType : u8 {
|
|||
};
|
||||
|
||||
struct NumberFormat {
|
||||
enum class Plurality : u8 {
|
||||
Other,
|
||||
Zero,
|
||||
Single,
|
||||
One,
|
||||
Two,
|
||||
Few,
|
||||
Many,
|
||||
};
|
||||
|
||||
u8 magnitude { 0 };
|
||||
u8 exponent { 0 };
|
||||
Plurality plurality { Plurality::Other };
|
||||
PluralCategory plurality { PluralCategory::Other };
|
||||
StringView zero_format {};
|
||||
StringView positive_format {};
|
||||
StringView negative_format {};
|
||||
|
@ -94,20 +85,20 @@ Optional<FormatType> select_pattern_with_plurality(Vector<FormatType> const& for
|
|||
};
|
||||
|
||||
if (number == 0) {
|
||||
if (auto patterns = find_plurality(FormatType::Plurality::Zero); patterns.has_value())
|
||||
if (auto patterns = find_plurality(PluralCategory::Zero); patterns.has_value())
|
||||
return patterns;
|
||||
} else if (number == 1) {
|
||||
if (auto patterns = find_plurality(FormatType::Plurality::One); patterns.has_value())
|
||||
if (auto patterns = find_plurality(PluralCategory::One); patterns.has_value())
|
||||
return patterns;
|
||||
} else if (number == 2) {
|
||||
if (auto patterns = find_plurality(FormatType::Plurality::Two); patterns.has_value())
|
||||
if (auto patterns = find_plurality(PluralCategory::Two); patterns.has_value())
|
||||
return patterns;
|
||||
} else if (number > 2) {
|
||||
if (auto patterns = find_plurality(FormatType::Plurality::Many); patterns.has_value())
|
||||
if (auto patterns = find_plurality(PluralCategory::Many); patterns.has_value())
|
||||
return patterns;
|
||||
}
|
||||
|
||||
return find_plurality(FormatType::Plurality::Other);
|
||||
return find_plurality(PluralCategory::Other);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue