-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BREAKING: Added Rule-Based Number Format Static API #46
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… 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
…since we don't use any linked list functionality
…number formats using the .NET formatter as a replacement for DecimalFormat.
… that contains all state and accessors
…values that are matched with PatternProps.IsWhiteSpace() for use in Trim() method
… 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.
…instead of PluralRules, since PluralRules are culture data dependent.
…umerator): 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)
…state is equivalent between RuleBasedNumberFormat and NumberFormatRules with the same input string and fixed several bugs in the parser.
…cally so it doesn't have to be parsed on every request.
…t for Missing case
…nd to startIndex/length to match .NET conventions. Optimized to use ValueStringBuilder, where Span<T> is supported.
…sembly, bool) and LocaleID property visible internally (as well as protected)
… method to create an instance from UCultureInfo/NumberPresentation.
… Added functionality to load and cache resource data in UCultureData and integrated it with UCultureInfo and UNumberFormatInfo.
…cached copy of UCultureInfo when creating the culture list
…ce() that accepts cultureName (locale baseName) as a string
…ion, and NumberingSystem properties
… Changed the values to start with 0 instead of 1 so we have a reasonable default value in .NET.
…using ReadOnlySpan<char> where appropriate
…uilder parameter and fixed the insert operation of pluralization in NumberFormatRule to happen entirely on the stack (if possible).
…le based formatting to 128 chars to cover most cases on the stack.
…ufferSize constant
…se correct override values when formatting numbers (based on where the original DecimalFormat instances got their setting values)
…LLECTIONS to include IReadOnlyList<T>
…als, GetHashCode, ToString(), and DefaultRuleSetName
…) extension methods and build errors due the unsafe logic in PluralRules.
…method to quickly lookup the NumberingSystemRules instance for the current UNumberFormatInfo.
…p 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.
…ring equality on an enum
…) and TryFormat() overloads for every numeric data type.
…rked APIs internal that are not yet in use (such as properties for currency and percentage formatting). Implemented the missing ReadOnly() method.
…entations and added API documentation for NumberFormat, IsReadOnly, ReadOnly() and Clone() members.
… method. This is in .NET only to allow it to fetch culture settings that have changed in the underlying OS.
…ternal, 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.
…instance so we don't fill up the UCultureData cache with all cultures and non-culture resource names.
…ntextExtensions): 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
…ormat): 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.
…rrected jargon error from transient > transitive dependencies.
…he 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.
31 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #41.
This redesigns the
RuleBasedNumberFormat
andPluralFormat
classes into static methods that replace the former implementation. The mapping old-to-new is as follows:ICU4N.Text.RuleBasedNumberFormat
a. Rules Engine >
ICU4N.Globalization.NumberFormatRules
, an immutable class. The instances forSpellOut
,Ordinal
,Duration
, andNumberingSystem
are available as properties on theUNumberFormatInfo
class which is returned from theUCultureInfo.NumberFormat
property.b. Format method overloads > overloads of
ICU4N.FormatNumberRuleBased.ToString()
andICU4N.FormatNumberRuleBased.TryFormat()
, which are also also extension methods for all built-in .NET numeric data types.ICU4N.Text.DecimalFormatSymbols
>ICU4N.Globalization.UNumberFormatInfo
, which is available from theUCultureInfo.NumberFormat
property.ICU4N.Text.NFRule
>ICU4N.Globalization.NumberFormatRule
.ICU4N.Text.NFRuleSet
>ICU4N.Globalization.NumberFormatRuleSet
.ICU4N.Text.NFSubstitution
>ICU4N.Globalization.Substitution
. All subclasses have also been copied to theICU4N.Globalization
namespace with their original names to subclass the new base class.As a stand-in for
DecimalFormat
, we are using the custom formatting string feature in .NET. But since the .NET formatter doesn't support all of the settings thatDecimalFormat
has, these have been hidden from the public API until a complete implementation ofDecimalFormat
is constructed.PluralFormat
is also not available publicly as theMessagePattern
class will need some refactoring to avoid unnecessary heap allocations.This functionality is also currently only available on .NET 6+.
The old ICU4J APIs have been removed from the public API for NuGet releases. They can be enabled for custom builds by setting the MSBuild property
IncludeLegacyNumberFormat=true
in the build. Alternatively, this API is available in the https://www.nuget.org/packages/ICU4N/60.1.0-alpha.401 package. Do note there are known issues with rounding accuracy in this implementation ofDecimalFormat
.The .NET formatter does not follow the IEEE 754 spec for rounding - it rounds toward positive infinity rather than to the nearest even number. So there may be issues with rounding in this new formatter for floating point types which will be addressed when we replace
DecimalFormat
.