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

Reduce some nesting from elses #1414

Merged
merged 2 commits into from
Feb 19, 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
24 changes: 8 additions & 16 deletions src/Humanizer/DateHumanizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ public static string Humanize(this DateTime? input, bool? utcDate = null, DateTi
{
return Humanize(input.Value, utcDate, dateToCompareAgainst, culture);
}
else
{
return Configurator.GetFormatter(culture).DateHumanize_Never();
}

return Configurator.GetFormatter(culture).DateHumanize_Never();
}

/// <summary>
Expand Down Expand Up @@ -69,10 +67,8 @@ public static string Humanize(this DateTimeOffset? input, DateTimeOffset? dateTo
{
return Humanize(input.Value, dateToCompareAgainst, culture);
}
else
{
return Configurator.GetFormatter(culture).DateHumanize_Never();
}

return Configurator.GetFormatter(culture).DateHumanize_Never();
}

#if NET6_0_OR_GREATER
Expand Down Expand Up @@ -102,10 +98,8 @@ public static string Humanize(this DateOnly? input, DateOnly? dateToCompareAgain
{
return Humanize(input.Value, dateToCompareAgainst, culture);
}
else
{
return Configurator.GetFormatter(culture).DateHumanize_Never();
}

return Configurator.GetFormatter(culture).DateHumanize_Never();
}

/// <summary>
Expand Down Expand Up @@ -137,10 +131,8 @@ public static string Humanize(this TimeOnly? input, TimeOnly? timeToCompareAgain
{
return Humanize(input.Value, timeToCompareAgainst, useUtc, culture);
}
else
{
return Configurator.GetFormatter(culture).DateHumanize_Never();
}

return Configurator.GetFormatter(culture).DateHumanize_Never();
}

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,15 @@ static string GetUnitValue(int number, bool isOrdinal)
{
return exceptionString;
}
else if (number > 19)

if (number > 19)
{
return TensMap[number / 10] + "ste";
}
else
{
return UnitsMap[number] + "de";
}
}
else
{
return UnitsMap[number];
return UnitsMap[number] + "de";
}

return UnitsMap[number];
}

static string RemoveOnePrefix(string toWords)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,8 @@ static string GetUnitValue(long number, bool isOrdinal)
{
return UnitsMap[number] + "երորդ";
}
else
{
return UnitsMap[number];
}

return UnitsMap[number];
}

static string RemoveOnePrefix(string toWords)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,14 @@ static string GetEndingForGender(GrammaticalGender gender, long input)
_ => throw new ArgumentOutOfRangeException(nameof(gender))
};
}
else

return gender switch
{
return gender switch
{
GrammaticalGender.Masculine => "ен",
GrammaticalGender.Feminine => "на",
GrammaticalGender.Neuter => "но",
_ => throw new ArgumentOutOfRangeException(nameof(gender))
};
}
GrammaticalGender.Masculine => "ен",
GrammaticalGender.Feminine => "на",
GrammaticalGender.Neuter => "но",
_ => throw new ArgumentOutOfRangeException(nameof(gender))
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public override string Convert(long number)
var sentence = string.Join(" و ", parts);
if (sentence.StartsWith("یەک هەزار"))
return sentence.Substring(" یەک".Length);
else
return sentence;
return sentence;
}

public override string ConvertToOrdinal(int number)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,11 @@ static string GetUnitValue(long number, bool isOrdinal)
{
return exceptionString;
}
else
{
return UnitsMap[number] + "th";
}
}
else
{
return UnitsMap[number];

return UnitsMap[number] + "th";
}

return UnitsMap[number];
}

static string RemoveOnePrefix(string toWords)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,24 @@ string ConvertImpl(long number, bool returnPluralized)
{
return ConvertIntB13(number, returnPluralized);
}
else if (number < 100)

if (number < 100)
{
return ConvertIntBH(number, returnPluralized);
}
else if (number < 1000)
if (number < 1000)
{
return ConvertIntBT(number, returnPluralized);
}
else if (number < 1000000)
if (number < 1000000)
{
return ConvertIntBM(number);
}
else if (number < 1000000000)
if (number < 1000000000)
{
return ConvertIntBB(number);
}
else if (number < 1000000000000)
if (number < 1000000000000)
{
return ConvertIntBTR(number);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,16 @@ static string GetUnitValue(int number, bool isOrdinal)
{
return exceptionString;
}
else if (number < 13)

if (number < 13)
{
return UnitsMap[number].TrimEnd('e') + "ende";
}
else
{
return UnitsMap[number] + "de";
}
}
else
{
return UnitsMap[number];

return UnitsMap[number] + "de";
}

return UnitsMap[number];
}

static bool ExceptionNumbersToWords(int number, out string words) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,11 @@ static string GetPartByGender(string multiGenderPart, GrammaticalGender gender)
{
return parts[2];
}
else
{
return parts[0];
}
}
else
{
return multiGenderPart;

return parts[0];
}

return multiGenderPart;
}

static bool IsAbove20(int number) =>
Expand All @@ -274,14 +270,13 @@ string HundredsToText(int hundreds)
{
return string.Empty;
}
else if (hundreds == 1)

if (hundreds == 1)
{
return _feminineSingular + " sută";
}
else
{
return GetPartByGender(_units[hundreds], GrammaticalGender.Feminine) + " sute";
}

return GetPartByGender(_units[hundreds], GrammaticalGender.Feminine) + " sute";
}

/// <summary>
Expand All @@ -305,14 +300,13 @@ string ThousandsConverter(int number, GrammaticalGender gender)
{
return string.Empty;
}
else if (number == 1)

if (number == 1)
{
return _feminineSingular + " mie";
}
else
{
return ThreeDigitSetConverter(number, GrammaticalGender.Feminine) + (IsAbove20(number) ? " " + _joinAbove20 : string.Empty) + " mii";
}

return ThreeDigitSetConverter(number, GrammaticalGender.Feminine) + (IsAbove20(number) ? " " + _joinAbove20 : string.Empty) + " mii";
}

// Large numbers (above 10^6) use a combined form of the long and short scales.
Expand All @@ -339,14 +333,13 @@ string MillionsConverter(int number, GrammaticalGender gender)
{
return string.Empty;
}
else if (number == 1)

if (number == 1)
{
return _masculineSingular + " milion";
}
else
{
return ThreeDigitSetConverter(number, GrammaticalGender.Feminine) + (IsAbove20(number) ? " " + _joinAbove20 : string.Empty) + " milioane";
}

return ThreeDigitSetConverter(number, GrammaticalGender.Feminine) + (IsAbove20(number) ? " " + _joinAbove20 : string.Empty) + " milioane";
}

/// <summary>
Expand All @@ -361,10 +354,8 @@ string BillionsConverter(int number, GrammaticalGender gender)
{
return _masculineSingular + " miliard";
}
else
{
return ThreeDigitSetConverter(number, GrammaticalGender.Feminine) + (IsAbove20(number) ? " " + _joinAbove20 : string.Empty) + " miliarde";
}

return ThreeDigitSetConverter(number, GrammaticalGender.Feminine) + (IsAbove20(number) ? " " + _joinAbove20 : string.Empty) + " miliarde";
}
}
}
Loading