Skip to content
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

use some pattern matching #1375

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer/Localisation/Formatters/ArabicFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer/Localisation/Formatters/HebrewFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer/Localisation/Formatters/SerbianFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void CollectThousandAndAbove(List<string> 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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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š";
}
Expand All @@ -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";
}
Expand Down Expand Up @@ -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š";
}
Expand All @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 += " ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down