Commit 1545efb
authored
BREAKING: Added Rule-Based Number Format Static API (#46)
* ICU4N.Text.NFRuleSet: Changed casing of private constants to match .NET conventions
* ICU4N.Text.NFRule: Changed casing of private constants to match .NET conventions
* ICU4N.Text (NFRule + NFRuleSet + NFSubstitution + PluralRules): Added note about using Math.Round() instead of Math.Ceiling() because the Java default is ToPositiveInfinity (the equivalent of Math.Ceiling), but the tests only pass with this configuration
* ICU4N.Text.NFRule: Corrected casing of RULE_PREFIXES array
* ICU4N.Text.NFRuleSet: Changed fractionRules from LinkedList to List, since we don't use any linked list functionality
* ICU4N.Numerics.NumberPropertyMapper: Added note about locale not being referenced
* RbnfTest: Added proof of concept test for how to format all built-in number formats using the .NET formatter as a replacement for DecimalFormat.
* ICU4N.Text.NFRuleSet: Converted the documentation comments
* ICU4N.Text.NFRule: Converted the documentation comments
* ICU4N.Text.SameValueSubstitution: Updated doc comments
* ICU4N.Text.RuleBasedNumberFormat::FindRuleSet(): Converted doc comments
* Added skeleton for NumberFormatRules (an immutable RBNF rules engine) that contains all state and accessors
* ICU4N.Impl.PatternProps: Added WhiteSpace static field with the same values that are matched with PatternProps.IsWhiteSpace() for use in Trim() method
* ICU4N.Globalization: Added RuleBasedNumberFormat methods to parse the rule text into rule/rule set/substitution objects. Also sealed all non-inheritable classes, enabled nullable reference type support, and added guard clauses, where appropriate.
* ICU4N.Globalization.NumberFormatRule: Re-wired to use MessagePattern instead of PluralRules, since PluralRules are culture data dependent.
* ICU4N.Text (SplitTokenizerEnumerator + MultiDelimiterSplitTokenizerEnumerator): Added features to control delimiter length to exclude from the token and trim behavior for start/end/both (or specify no trimChars for no trimming)
* ICU4N.Impl.PatternProps: Fixed initialization order issue with WhiteSpace field.
* ICU4N.Globalization: Added tests for NumberFormatRules to ensure the state is equivalent between RuleBasedNumberFormat and NumberFormatRules with the same input string and fixed several bugs in the parser.
* PERFORMANCE: ICU4N.Globalization.UCultureInfo.Name: Cache the name locally so it doesn't have to be parsed on every request.
* ICU4N.Globalization.UCultureInfo::Canonicalize(): Added null guard clause
* ICU4N.Util.ResourceBundle::SetRootType(): Fixed fallthrough to default for Missing case
* BREAKING: ICU4N.Impl.ResourceKey::Substring(): Converted from start/end to startIndex/length to match .NET conventions. Optimized to use ValueStringBuilder, where Span<T> is supported.
* ICU4N.Impl.ICUResourceBundle: Added TODO for API rework
* ICU4N.Util.UResourceBundle: Made GetBundleInstance(string, string, Assembly, bool) and LocaleID property visible internally (as well as protected)
* ICU4N.Globalization.NumberFormatRules: Added cache and static factory method to create an instance from UCultureInfo/NumberPresentation.
* ICU4N.Globalization.NumberFormatRules: Marked class public
* ICU4N.Globalization: (UCultureData, UCultureInfo, UNumberFormatInfo): Added functionality to load and cache resource data in UCultureData and integrated it with UCultureInfo and UNumberFormatInfo.
* ICU4N.Impl.ICUResourceBundle.CreateUCultureList: Use a read-only non-cached copy of UCultureInfo when creating the culture list
* ICU4N.Globalization.NumberFormatRules: Added overload of CreateInstance() that accepts cultureName (locale baseName) as a string
* ICU4N.Globalization.UNumberFormatInfo: Added SpellOut, Ordinal, Duration, and NumberingSystem properties
* BREAKING: ICU4N.Impl.PluralRulesLoader + ICU4N.Text.PluralRules: Renamed ForLocale() > GetInstance(). Added overload to pass localeName as a string to decouple from UCultureInfo.
* ICU4N.Text.BreakIterator: Added GetSentenceInstance() overload that accepts strings so we are decoupled from any UCultureInfo instance.
* ICU4N.Globalization (UCultureData + UCultureInfo): Refactored to remove the UCultureInfo reference from UCultureData so it is allowed to go out of scope.
* ICU4N.Globalization.NumberFormatRulesTest: Added test to measure string and object sizes (commented out)
* ICU4N.Globalization.UNumberFormatInfoTest: Added tests to verify all cultures load decimal format settings correctly (we still have some way to go for currency data)
* ICU4N.Globalization.UNumberFormatInfo: Added Capitalization property (DisplayContext in ICU4J).
* ICU4N.Globalization.UNumberFormatInfo: Added NumberGroupSizes property
* ICU4N.Globalization:UNumberFormatInfo: Added NativeDigitsLocal, NumberGroupSizesLocal, and DigitSubstitution properties.
* ValueStringBuilder: Added TODO
* ICU4N.IcuNumber: Added formatters for long and double to output native digits + tests to confirm that they are the same as the DecimalFormat instance that backs RuleBasedNumberFormat.
* ICU4N.Text.ValueStringBuilder: Added Insert() overload to handle ReadOnlySpan<char>
* ICU4N.Globalization (NumberFormatRules + NumberFormatRuleSet + NumberFormatRule + NumberFormatSubstitution): Added Format() method for double type (minus the plural format)
* ICU4N.Support.IcuNumber: Added FormatPlural() method + tests.
* ICU4N.Globalization:NumberFormattingRule: Added plural formatting call
* ICU4N.Numerics: Added NumberPatternStringProperties struct to store only the info required to rebuild a pattern string
* Implemented RuleBasedNumberFormat method overloads for long data type and integrated NumberPatternStringProperties for the business logic that depends on them.
* ValueStringBuilder: Added Insert() method to add a single char and optimized Insert() overloads to exit early if count is 0
* ICU4N.Globalization (FractionalPartSubstitution + NumeratorSubstitution): Added missing DoSubstitution overrides
* ICU4N.Globalization.NumberFormatRule: Pass in the PluralType so we know which set of plural rules to fetch when formatting.
* ICU4N.Globalization.NumberFormatRuleSet: Fixed callers of GetBestFractionRule() to correctly use the constants from NumberFormatRule to lookup fraction rules
* ICU4N.Globalization.NumberFormatRules: Redesigned private Format() methods from RBNF to be the entry point into NumberFormatRules and accept a ValueStringBuilder from the caller.
* ICU4N.Globalization.NumberFormatRules: Added missing StripWhiteSpace method that is used to pre-process the rules. Made FindRuleSet() internal so we can utilize it from IcuNumber.
* ICU4N.Text.NumberPresentationExtensions: Added IsDefined() method so we can quickly check for valid values in guard clauses.
* ICU4N.IcuNumber: Added format methods for BigInteger and RuleBased long, double, and BigInteger
* RbnfTest: Created an RbnfFormatterSettings class with the same constructors as RuleBasedNumberFormat that stores the state and creation logic to test our IcuNumber rule based format methods. Added an overload of doTest() that accepts this new class as a parameter in place of RuleBasedNumberFormat and added test logic.
* RbnfRoundTripTest: Adapted RbnfFormatterSettings class so it can be used from both RbnfTest and RbnfRoundTripTest classes to test the static RBNF formatter
* ICU4N.IcuNumber: Added AdjustForContext method to capitalize the output of rule-based format methods.
* Moved NumberPresentation enum from ICU4N.Text to ICU4N.Globalization. Changed the values to start with 0 instead of 1 so we have a reasonable default value in .NET.
* Fixed some build warnings
* ICU4N.Numerics.DecimalQuantity_AbstractBCD: Optimized number parsing using ReadOnlySpan<char> where appropriate
* ICU4N.Globalization: Refactored FormatPlural to accept a ValueStringBuilder parameter and fixed the insert operation of pluralization in NumberFormatRule to happen entirely on the stack (if possible).
* ICU4N.IcuNumber: Increased the default stack buffer allocation for rule based formatting to 128 chars to cover most cases on the stack.
* ICU4N.Globalization.NumberFormatRules: Removed unnecessary CharStackBufferSize constant
* ICU4N.Globalization (NumberFormatRules + NumberFormatSubstitution): Use correct override values when formatting numbers (based on where the original DecimalFormat instances got their setting values)
* ICU4N.Globalization.Capitialization: Updated docs
* Changed the name of FEATURE_READONLYDICTIONARY to FEATURE_IREADONLYCOLLECTIONS to include IReadOnlyList<T>
* ICU4N.Globalization.NumberFormatRules: Implemented public members Equals, GetHashCode, ToString(), and DefaultRuleSetName
* Added target for .NET 7.0. Fixed conflicts due to the new AsReadOnly() extension methods and build errors due the unsafe logic in PluralRules.
* ICU4N.Globalization.NumberFormatRules: Added RuleSetNames property.
* ICU4N.Globalization.NumberPresentationExtensions: Added an extension method to quickly lookup the NumberingSystemRules instance for the current UNumberFormatInfo.
* BUG: ICU4N.Globalization.NumberFormatRuleSet: Fixed master rule lookup for current context. We no longer store these rules in the nonNumericalRules array, they are in the fractionRules field instead. We get them using the GetBestFractionRule() method and supplying the fraction rule index from NumberFormatRule.
* ICU4N.Globalization.NumberFormatRules::Equals(): Don't box when comparing equality on an enum
* ICU4N.Globalization.NumberFormatRuleSet: Removed TODO that is already finished
* ICU4N: Added FormatNumberRuleBased static class with public ToString() and TryFormat() overloads for every numeric data type.
* ICU4N.Globalization.UNumberFormatInfo: Added API documentation and marked APIs internal that are not yet in use (such as properties for currency and percentage formatting). Implemented the missing ReadOnly() method.
* ICU4N.Globalization.UCultureInfo: Added ReadOnly() and Clone() implementations and added API documentation for NumberFormat, IsReadOnly, ReadOnly() and Clone() members.
* BREAKING: ICU4N.Globalization.UCultureInfo: Removed ClearCachedData() method. This is in .NET only to allow it to fetch culture settings that have changed in the underlying OS.
* ICU4N.Globalization.NumberFormatRules: Marked GetInstance() method internal, for now. This won't be very useful until after we have public overloads of the format/parse operations that accept an instance of this.
* ICU4N.Impl.ICUResourceBundle.WholeBundle: Lazy-load the UCultureInfo instance so we don't fill up the UCultureData cache with all cultures and non-culture resource names.
* ICU4N.Globalization.NumberFormatRules::IsDefaultCandidateRule(): Marked private
* BREAKING: ICU4N.Text (DisplayContext + DisplayContextType + DisplayContextExtensions): Removed from the public API since they had been previously refactored in the Globalization namespace as Capitalization, DialectHandling, DisplayLength, and DisplayLength enums and the DisplayContextOptions class
* BREAKING: ICU4N.Text (NumberFormat + DecimalFormat + RuleBasedNumberFormat): Removed from the public API and added an IncludeLegacyNumberFormat build property so they can be optionally compiled for those who need these features. The plan is to port them into static APIs later.
* ICU4N.FormatNumberRuleBased: Added missing support for System.UInt128
* README.md: Added info about RuleBasedNumberFormat being a feature. Corrected jargon error from transient > transitive dependencies.
* BREAKING: ICU4N.Globalization.Capitalization: Added "For" prefix to the names as they were in ICU4J, since this adds clarity to their intended purpose. Also explicitly specified numeric values of all DisplayContext enums in ICU4N.Globalization to match ICU4J.1 parent 172205e commit 1545efb
100 files changed
Lines changed: 14844 additions & 1038 deletions
File tree
- src
- ICU4N.Collation/Text
- ICU4N.CurrencyData/Impl
- ICU4N
- Impl
- Locale
- Number
- Number
- Support
- Globalization
- LocaleDisplayNames
- DisplayContext
- RuleBasedNumberFormat
- Text
- Text
- Util
- tests
- ICU4N.Tests.Collation/Dev/Test/Util
- ICU4N.Tests
- Dev/Test
- Format
- Util
- Support
- Globalization
- RuleBasedNumberFormat
- Text
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
7 | 16 | | |
8 | 17 | | |
9 | 18 | | |
| |||
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
19 | 35 | | |
20 | 36 | | |
21 | 37 | | |
| |||
46 | 62 | | |
47 | 63 | | |
48 | 64 | | |
49 | | - | |
| 65 | + | |
50 | 66 | | |
51 | 67 | | |
52 | 68 | | |
| |||
70 | 86 | | |
71 | 87 | | |
72 | 88 | | |
73 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
74 | 93 | | |
75 | 94 | | |
76 | 95 | | |
| |||
93 | 112 | | |
94 | 113 | | |
95 | 114 | | |
96 | | - | |
| 115 | + | |
97 | 116 | | |
98 | 117 | | |
99 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
| 98 | + | |
98 | 99 | | |
99 | | - | |
| 100 | + | |
100 | 101 | | |
101 | | - | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
17 | 40 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1084 | 1084 | | |
1085 | 1085 | | |
1086 | 1086 | | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
1087 | 1090 | | |
| 1091 | + | |
1088 | 1092 | | |
1089 | 1093 | | |
1090 | 1094 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
225 | 228 | | |
| 229 | + | |
226 | 230 | | |
227 | 231 | | |
228 | 232 | | |
| |||
241 | 245 | | |
242 | 246 | | |
243 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
244 | 251 | | |
| 252 | + | |
245 | 253 | | |
246 | 254 | | |
247 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
539 | 544 | | |
540 | 545 | | |
541 | 546 | | |
| |||
701 | 706 | | |
702 | 707 | | |
703 | 708 | | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
704 | 713 | | |
705 | 714 | | |
706 | 715 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
148 | | - | |
149 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
150 | 160 | | |
151 | 161 | | |
152 | 162 | | |
| |||
155 | 165 | | |
156 | 166 | | |
157 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
158 | 171 | | |
| 172 | + | |
159 | 173 | | |
160 | 174 | | |
161 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
94 | 124 | | |
95 | 125 | | |
96 | 126 | | |
| |||
277 | 307 | | |
278 | 308 | | |
279 | 309 | | |
280 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
281 | 321 | | |
282 | 322 | | |
283 | 323 | | |
284 | | - | |
| 324 | + | |
285 | 325 | | |
286 | 326 | | |
287 | 327 | | |
| |||
0 commit comments