From 2924638246dcd58fa96aac162bf9652ae75c223d Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 16 Feb 2024 23:11:21 +1100 Subject: [PATCH] use some pattern matching --- .../DateTimeHumanizeAlgorithms.cs | 2 +- src/Humanizer/Localisation/Formatters/ArabicFormatter.cs | 2 +- .../Localisation/Formatters/CzechSlovakPolishFormatter.cs | 2 +- src/Humanizer/Localisation/Formatters/HebrewFormatter.cs | 2 +- src/Humanizer/Localisation/Formatters/SerbianFormatter.cs | 2 +- .../GrammaticalNumber/RussianGrammaticalNumberDetector.cs | 2 +- .../NumberToWords/ArabicNumberToWordsConverter.cs | 4 ++-- .../NumberToWords/ChineseNumberToWordsConverter.cs | 2 +- .../NumberToWords/CzechNumberToWordsConverter.cs | 2 +- .../NumberToWords/FinnishNumberToWordsConverter.cs | 8 ++++---- .../NumberToWords/LatvianNumberToWordsConverter.cs | 8 ++++---- .../NumberToWords/MalteseNumberToWordsConvertor.cs | 2 +- .../NumberToWords/TamilNumberToWordsConverter.cs | 8 ++++---- .../Localisation/Ordinalizers/EnglishOrdinalizer.cs | 2 +- .../EsTimeOnlyToClockNotationConverter.cs | 6 +++--- 15 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs index d0ee79af7..112e7e6a4 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs @@ -216,7 +216,7 @@ private static string DefaultHumanize(TimeSpan ts, bool sameMonth, int days, Ten return formatter.DateHumanize(TimeUnit.Day, tense, ts.Days); } - if (ts.TotalDays >= 28 && ts.TotalDays < 30) + if (ts.TotalDays is >= 28 and < 30) { if (sameMonth) { diff --git a/src/Humanizer/Localisation/Formatters/ArabicFormatter.cs b/src/Humanizer/Localisation/Formatters/ArabicFormatter.cs index 30d813354..9b095a13a 100644 --- a/src/Humanizer/Localisation/Formatters/ArabicFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/ArabicFormatter.cs @@ -15,7 +15,7 @@ protected override string GetResourceKey(string resourceKey, int number) } //In Arabic pluralization entities where the count is between 3 and 10 gets a different word. - if (number >= 3 && number <= 10) + if (number is >= 3 and <= 10) { return resourceKey + PluralPostfix; } diff --git a/src/Humanizer/Localisation/Formatters/CzechSlovakPolishFormatter.cs b/src/Humanizer/Localisation/Formatters/CzechSlovakPolishFormatter.cs index 45b5b2f44..5020443a5 100644 --- a/src/Humanizer/Localisation/Formatters/CzechSlovakPolishFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/CzechSlovakPolishFormatter.cs @@ -7,7 +7,7 @@ class CzechSlovakPolishFormatter(string localeCode) : protected override string GetResourceKey(string resourceKey, int number) { - if (number > 1 && number < 5) + if (number is > 1 and < 5) { return resourceKey + PaucalPostfix; } diff --git a/src/Humanizer/Localisation/Formatters/HebrewFormatter.cs b/src/Humanizer/Localisation/Formatters/HebrewFormatter.cs index 3d6e02fbe..c65900240 100644 --- a/src/Humanizer/Localisation/Formatters/HebrewFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/HebrewFormatter.cs @@ -16,7 +16,7 @@ protected override string GetResourceKey(string resourceKey, int number) //In Hebrew pluralization entities where the count is between 3 and 10 gets a different word. //See http://lib.cet.ac.il/pages/item.asp?item=21585 for explanation - if (number >= 3 && number <= 10) + if (number is >= 3 and <= 10) { return resourceKey + PluralPostfix; } diff --git a/src/Humanizer/Localisation/Formatters/SerbianFormatter.cs b/src/Humanizer/Localisation/Formatters/SerbianFormatter.cs index 0a7b5a159..46ba2c224 100644 --- a/src/Humanizer/Localisation/Formatters/SerbianFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/SerbianFormatter.cs @@ -9,7 +9,7 @@ protected override string GetResourceKey(string resourceKey, int number) { var mod10 = number % 10; - if (mod10 > 1 && mod10 < 5) + if (mod10 is > 1 and < 5) { return resourceKey + PaucalPostfix; } diff --git a/src/Humanizer/Localisation/GrammaticalNumber/RussianGrammaticalNumberDetector.cs b/src/Humanizer/Localisation/GrammaticalNumber/RussianGrammaticalNumberDetector.cs index 64642cabb..2fe677b9c 100644 --- a/src/Humanizer/Localisation/GrammaticalNumber/RussianGrammaticalNumberDetector.cs +++ b/src/Humanizer/Localisation/GrammaticalNumber/RussianGrammaticalNumberDetector.cs @@ -14,7 +14,7 @@ public static RussianGrammaticalNumber Detect(long number) return RussianGrammaticalNumber.Singular; } - if (unity > 1 && unity < 5) // 2, 3, 4, 22, 23, 24 ... + if (unity is > 1 and < 5) // 2, 3, 4, 22, 23, 24 ... { return RussianGrammaticalNumber.Paucal; } diff --git a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs index 228c78f8b..2f6933e63 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs @@ -119,7 +119,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn { if (groupNumber % 100 != 1) { - if (groupNumber >= 3 && groupNumber <= 10) + if (groupNumber is >= 3 and <= 10) { result = $"{PluralGroups[groupLevel]} {result}"; } @@ -223,7 +223,7 @@ private static string ParseNumber(string word, int number, GrammaticalGender gen return word.Substring(0, word.Length - kv.Key.Length) + kv.Value; } } - else if (number > 10 && number < 100) + else if (number is > 10 and < 100) { var parts = word.Split(' '); var newParts = new string[parts.Length]; diff --git a/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs index 095234bc5..6ad8fc9ae 100644 --- a/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ChineseNumberToWordsConverter.cs @@ -10,7 +10,7 @@ public override string Convert(long number) => public override string ConvertToOrdinal(int number) => Convert(number, true, IsSpecial(number)); - private static bool IsSpecial(long number) => number > 10 && number < 20; + private static bool IsSpecial(long number) => number is > 10 and < 20; private static string Convert(long number, bool isOrdinal, bool isSpecial) { diff --git a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs index c6c4fc7ca..e020334f2 100644 --- a/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/CzechNumberToWordsConverter.cs @@ -95,7 +95,7 @@ private void CollectThousandAndAbove(List parts, ref long number, long d { parts.Add(map[0]); } - else if (units > 1 && units < 5) + else if (units is > 1 and < 5) { parts.Add(map[1]); } diff --git a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs index 52fc34517..2704bdc24 100644 --- a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs @@ -72,12 +72,12 @@ public override string Convert(long input) parts.Add($"{Convert(number / 10)}kymmentä"); number %= 10; } - else if (number > 10 && number < 20) + else if (number is > 10 and < 20) { parts.Add($"{UnitsMap[number % 10]}toista"); } - if (number > 0 && number <= 10) + if (number is > 0 and <= 10) { parts.Add(UnitsMap[number]); } @@ -133,12 +133,12 @@ private static string ToOrdinal(int number, bool useExceptions) parts.Add($"{ToOrdinal(number / 10, true)}kymmenes"); number %= 10; } - else if (number > 10 && number < 20) + else if (number is > 10 and < 20) { parts.Add($"{GetOrdinalUnit(number % 10, true)}toista"); } - if (number > 0 && number <= 10) + if (number is > 0 and <= 10) { parts.Add(GetOrdinalUnit(number, useExceptions)); } diff --git a/src/Humanizer/Localisation/NumberToWords/LatvianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/LatvianNumberToWordsConverter.cs index 3783388e8..9c2dab7e9 100644 --- a/src/Humanizer/Localisation/NumberToWords/LatvianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/LatvianNumberToWordsConverter.cs @@ -39,7 +39,7 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd { thousandsPart = "tūkstotis"; } - else if (number > 1000 && number < 2000) + else if (number is > 1000 and < 2000) { thousandsPart = "tūkstoš"; } @@ -58,7 +58,7 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd { hundredsPart = parts.Contains("tūkstoš") ? "viens simts" : "simts"; } - else if (number > 100 && number < 200) + else if (number is > 100 and < 200) { hundredsPart = "simtu"; } @@ -133,7 +133,7 @@ public override string ConvertToOrdinal(int input, GrammaticalGender gender) } else { - if (number > 1000 && number < 2000) + if (number is > 1000 and < 2000) { thousandsPart = "tūkstoš"; } @@ -155,7 +155,7 @@ public override string ConvertToOrdinal(int input, GrammaticalGender gender) } else { - if (number > 100 && number < 200) + if (number is > 100 and < 200) { hundredsPart = "simtu"; } diff --git a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs index 92b9bf186..5b35b0877 100644 --- a/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs +++ b/src/Humanizer/Localisation/NumberToWords/MalteseNumberToWordsConvertor.cs @@ -106,7 +106,7 @@ private static string GetTens(long value, bool usePrefixMap, bool usePrefixMapFo return HundredsMap[value]; } - if (value > 10 && value < 20 && usePrefixMap) + if (value is > 10 and < 20 && usePrefixMap) { return PrefixMap[value]; } diff --git a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs index a89c550c1..3f56dcae5 100644 --- a/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TamilNumberToWordsConverter.cs @@ -106,7 +106,7 @@ private static string GetTensValue(long number, bool isOrdinal, bool isThousand var local_word = ""; if (number < 20) local_word = GetUnitValue(number, isOrdinal); - else if (number >= 20 && number <= 99) + else if (number is >= 20 and <= 99) { var lastPart = TensMap[number / 10]; var quot = number / 10; @@ -172,18 +172,18 @@ private static string GetCroresValue(ref long number) var num_above_10 = number / 10000000; var str_crore = "கோடி"; - if (num_above_10 > 99999 && num_above_10 <= 9999999) + if (num_above_10 is > 99999 and <= 9999999) { local_word = GetLakhsValue(ref num_above_10, false); local_word += " "; } - if (num_above_10 > 999 && num_above_10 <= 99999) + if (num_above_10 is > 999 and <= 99999) { local_word += GetThousandsValue(ref num_above_10); local_word += " "; } - if (num_above_10 > 99 && num_above_10 <= 999) + if (num_above_10 is > 99 and <= 999) { local_word += GetHundredsValue(ref num_above_10); local_word += " "; diff --git a/src/Humanizer/Localisation/Ordinalizers/EnglishOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/EnglishOrdinalizer.cs index 900b8f1a2..d99829102 100644 --- a/src/Humanizer/Localisation/Ordinalizers/EnglishOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/EnglishOrdinalizer.cs @@ -6,7 +6,7 @@ public override string Convert(int number, string numberString) { var nMod100 = number % 100; - if (nMod100 >= 11 && nMod100 <= 20) + if (nMod100 is >= 11 and <= 20) { return numberString + "th"; } diff --git a/src/Humanizer/Localisation/TimeToClockNotation/EsTimeOnlyToClockNotationConverter.cs b/src/Humanizer/Localisation/TimeToClockNotation/EsTimeOnlyToClockNotationConverter.cs index bb900d7c7..ea931798b 100644 --- a/src/Humanizer/Localisation/TimeToClockNotation/EsTimeOnlyToClockNotationConverter.cs +++ b/src/Humanizer/Localisation/TimeToClockNotation/EsTimeOnlyToClockNotationConverter.cs @@ -75,13 +75,13 @@ private static string GetDayPeriod(TimeOnly time) } private static bool IsEarlyMorning(TimeOnly time) => - time.Hour >= 1 && time.Hour < MORNING; + time.Hour is >= 1 and < MORNING; private static bool IsMorning(TimeOnly time) => - time.Hour >= MORNING && time.Hour < NOON; + time.Hour is >= MORNING and < NOON; private static bool IsAfternoon(TimeOnly time) => - time.Hour >= NOON && time.Hour < AFTERNOON; + time.Hour is >= NOON and < AFTERNOON; } }