-
Notifications
You must be signed in to change notification settings - Fork 397
Fix overridden abbrev #833
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
8b01d68
a625c7f
bc5f8c4
5be4cf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,9 +276,11 @@ public string[] GetUnitAbbreviations(Type unitType, int unitValue, IFormatProvid | |
if(!TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var lookup)) | ||
return formatProvider != FallbackCulture ? GetUnitAbbreviations(unitType, unitValue, FallbackCulture) : new string[] { }; | ||
|
||
var abbreviations = lookup!.GetAbbreviationsForUnit(unitValue); | ||
if(abbreviations.Count == 0) | ||
return formatProvider != FallbackCulture ? GetUnitAbbreviations(unitType, unitValue, FallbackCulture) : new string[] { }; | ||
var abbreviations = new HashSet<string>(); | ||
abbreviations.UnionWith(lookup!.GetAbbreviationsForUnit(unitValue)); | ||
|
||
if(formatProvider != FallbackCulture) | ||
abbreviations.UnionWith(GetUnitAbbreviations(unitType, unitValue, FallbackCulture)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first glance, I'm not sure about this union. If you call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A good question :) Should it? Currently you can get English abbreviations from GetUnitAbbreviations, but only if no Russian ones exist. The parser obviously will not fall back without it. It's either that, or the parser logic will need to include the fallback logic. I wanted to keep everything contained. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm really not sure. How about adding a new parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think we should not do a union here indiscriminately. What do you think of my proposal of a new argument? |
||
|
||
return abbreviations.ToArray(); | ||
} | ||
|
@@ -297,10 +299,32 @@ public string[] GetAllUnitAbbreviationsForQuantity(Type unitEnumType, IFormatPro | |
if(!TryGetUnitValueAbbreviationLookup(unitEnumType, formatProvider, out var lookup)) | ||
return formatProvider != FallbackCulture ? GetAllUnitAbbreviationsForQuantity(unitEnumType, FallbackCulture) : new string[] { }; | ||
|
||
return lookup!.GetAllUnitAbbreviationsForQuantity(); | ||
var allAbbreviations = new HashSet<string>(); | ||
allAbbreviations.UnionWith(lookup!.GetAllUnitAbbreviationsForQuantity()); | ||
|
||
if(formatProvider != FallbackCulture) | ||
allAbbreviations.UnionWith(GetAllUnitAbbreviationsForQuantity(unitEnumType, FallbackCulture)); | ||
|
||
return allAbbreviations.ToArray(); | ||
} | ||
|
||
internal List<int> GetUnitsForAbbreviation(Type unitType, IFormatProvider? formatProvider, string abbreviation, bool ignoreCase) | ||
{ | ||
formatProvider = formatProvider ?? CultureInfo.CurrentUICulture; | ||
|
||
if(!TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var lookup)) | ||
return formatProvider != FallbackCulture ? GetUnitsForAbbreviation(unitType, FallbackCulture, abbreviation, ignoreCase) : new List<int>(); | ||
|
||
var units = new HashSet<int>(); | ||
units.UnionWith(lookup!.GetUnitsForAbbreviation(abbreviation, ignoreCase)); | ||
|
||
if(formatProvider != FallbackCulture) | ||
units.UnionWith(GetUnitsForAbbreviation(unitType, FallbackCulture, abbreviation, ignoreCase)); | ||
|
||
return units.ToList(); | ||
} | ||
|
||
internal bool TryGetUnitValueAbbreviationLookup(Type unitType, IFormatProvider? formatProvider, out UnitValueAbbreviationLookup? unitToAbbreviations) | ||
private bool TryGetUnitValueAbbreviationLookup(Type unitType, IFormatProvider? formatProvider, out UnitValueAbbreviationLookup? unitToAbbreviations) | ||
{ | ||
unitToAbbreviations = null; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.