Skip to content

Commit

Permalink
use string format (#1328)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 12, 2024
1 parent 6180844 commit 4b6234f
Show file tree
Hide file tree
Showing 31 changed files with 133 additions and 133 deletions.
4 changes: 2 additions & 2 deletions src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void HumanizeDefaultsToToString()
[Fact]
public void HumanizeUsesStringDisplayFormatter()
{
var humanized = _testCollection.Humanize(sc => string.Format("SomeObject #{0} - {1}", sc.SomeInt, sc.SomeString));
var humanized = _testCollection.Humanize(sc => $"SomeObject #{sc.SomeInt} - {sc.SomeString}");
Assert.Equal("SomeObject #1 - One, SomeObject #2 - Two, and SomeObject #3 - Three", humanized);
}

Expand All @@ -92,7 +92,7 @@ public void HumanizeUsesObjectDisplayFormatter()
[Fact]
public void HumanizeUsesStringDisplayFormatterWhenSeparatorIsProvided()
{
var humanized = _testCollection.Humanize(sc => string.Format("SomeObject #{0} - {1}", sc.SomeInt, sc.SomeString), "or");
var humanized = _testCollection.Humanize(sc => $"SomeObject #{sc.SomeInt} - {sc.SomeString}", "or");
Assert.Equal("SomeObject #1 - One, SomeObject #2 - Two, or SomeObject #3 - Three", humanized);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer/Bytes/ByteSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private string ToString(string format, IFormatProvider provider, bool toSymbol)
? "0"
: formattedLargeWholeNumberValue;

return string.Format("{0} {1}", formattedLargeWholeNumberValue, toSymbol ? GetLargestWholeNumberSymbol(provider) : GetLargestWholeNumberFullWord(provider));
return $"{formattedLargeWholeNumberValue} {(toSymbol ? GetLargestWholeNumberSymbol(provider) : GetLargestWholeNumberFullWord(provider))}";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,32 @@ private string Convert(int number, bool isOrdinal)

if (number < 0)
{
return string.Format("minus {0}", Convert(-number));
return $"minus {Convert(-number)}";
}

var parts = new List<string>();

if ((number / 1000000000) > 0)
{
parts.Add(string.Format("{0} miljard", Convert(number / 1000000000)));
parts.Add($"{Convert(number / 1000000000)} miljard");
number %= 1000000000;
}

if ((number / 1000000) > 0)
{
parts.Add(string.Format("{0} miljoen", Convert(number / 1000000)));
parts.Add($"{Convert(number / 1000000)} miljoen");
number %= 1000000;
}

if ((number / 1000) > 0)
{
parts.Add(string.Format("{0} duisend", Convert(number / 1000)));
parts.Add($"{Convert(number / 1000)} duisend");
number %= 1000;
}

if ((number / 100) > 0)
{
parts.Add(string.Format("{0} honderd", Convert(number / 100)));
parts.Add($"{Convert(number / 100)} honderd");
number %= 100;
}

Expand All @@ -94,11 +94,11 @@ private string Convert(int number, bool isOrdinal)
var lastPart = TensMap[number / 10];
if ((number % 10) > 0)
{
lastPart = string.Format("{0} en {1}", GetUnitValue(number % 10, false), isOrdinal ? GetUnitValue(lastPartValue, isOrdinal) : lastPart);
lastPart = $"{GetUnitValue(number % 10, false)} en {(isOrdinal ? GetUnitValue(lastPartValue, isOrdinal) : lastPart)}";
}
else if ((number % 10) == 0)
{
lastPart = string.Format("{0}{1}{2}", parts.Count > 0 ? "en " : "", lastPart, isOrdinal ? "ste" : "");
lastPart = $"{(parts.Count > 0 ? "en " : "")}{lastPart}{(isOrdinal ? "ste" : "")}";
}
else if (isOrdinal)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn

if (number < 0)
{
return string.Format("ناقص {0}", Convert(-number, gender));
return $"ناقص {Convert(-number, gender)}";
}

var result = string.Empty;
Expand Down Expand Up @@ -114,7 +114,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn
{
if (result != string.Empty)
{
result = string.Format("{0} {1}", "و", result);
result = $"{"و"} {result}";
}

if (groupNumber != 2)
Expand All @@ -123,21 +123,21 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn
{
if (groupNumber >= 3 && groupNumber <= 10)
{
result = string.Format("{0} {1}", PluralGroups[groupLevel], result);
result = $"{PluralGroups[groupLevel]} {result}";
}
else
{
result = string.Format("{0} {1}", result != string.Empty ? AppendedGroups[groupLevel] : Groups[groupLevel], result);
result = $"{(result != string.Empty ? AppendedGroups[groupLevel] : Groups[groupLevel])} {result}";
}
}
else
{
result = string.Format("{0} {1}", Groups[groupLevel], result);
result = $"{Groups[groupLevel]} {result}";
}
}
}

result = string.Format("{0} {1}", process, result);
result = $"{process} {result}";
}

groupLevel++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,39 @@ private string ConvertImpl(long number, bool isOrdinal)

if (number < 0)
{
return string.Format("մինուս {0}", ConvertImpl(-number, isOrdinal));
return $"մինուս {ConvertImpl(-number, isOrdinal)}";
}

var parts = new List<string>();

if ((number / 1000000000000000000) > 0)
{
parts.Add(string.Format("{0} քվինտիլիոն", Convert(number / 1000000000000000000)));
parts.Add($"{Convert(number / 1000000000000000000)} քվինտիլիոն");
number %= 1000000000000000000;
}

if ((number / 1000000000000000) > 0)
{
parts.Add(string.Format("{0} կվադրիլիոն", Convert(number / 1000000000000000)));
parts.Add($"{Convert(number / 1000000000000000)} կվադրիլիոն");
number %= 1000000000000000;
}

if ((number / 1000000000000) > 0)

{
parts.Add(string.Format("{0} տրիլիոն", Convert(number / 1000000000000)));
parts.Add($"{Convert(number / 1000000000000)} տրիլիոն");
number %= 1000000000000;
}

if ((number / 1000000000) > 0)
{
parts.Add(string.Format("{0} միլիարդ", Convert(number / 1000000000)));
parts.Add($"{Convert(number / 1000000000)} միլիարդ");
number %= 1000000000;
}

if ((number / 1000000) > 0)
{
parts.Add(string.Format("{0} միլիոն", Convert(number / 1000000)));
parts.Add($"{Convert(number / 1000000)} միլիոն");
number %= 1000000;
}

Expand All @@ -96,7 +96,7 @@ private string ConvertImpl(long number, bool isOrdinal)
}
else
{
parts.Add(string.Format("{0} հազար", Convert(number / 1000)));
parts.Add($"{Convert(number / 1000)} հազար");
}

number %= 1000;
Expand All @@ -110,7 +110,7 @@ private string ConvertImpl(long number, bool isOrdinal)
}
else
{
parts.Add(string.Format("{0} հարյուր", Convert(number / 100)));
parts.Add($"{Convert(number / 100)} հարյուր");
}

number %= 100;
Expand All @@ -127,7 +127,7 @@ private string ConvertImpl(long number, bool isOrdinal)
var lastPart = TensMap[number / 10];
if ((number % 10) > 0)
{
lastPart += string.Format("{0}", GetUnitValue(number % 10, isOrdinal));
lastPart += $"{GetUnitValue(number % 10, isOrdinal)}";
}
else if (isOrdinal)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,34 @@ public override string Convert(long input)

if (number < 0)
{
return string.Format("mənfi {0}", Convert(-number));
return $"mənfi {Convert(-number)}";
}

var parts = new List<string>();

if ((number / 1000000000) > 0)
{
parts.Add(string.Format("{0} milyard", Convert(number / 1000000000)));
parts.Add($"{Convert(number / 1000000000)} milyard");
number %= 1000000000;
}

if ((number / 1000000) > 0)
{
parts.Add(string.Format("{0} milyon", Convert(number / 1000000)));
parts.Add($"{Convert(number / 1000000)} milyon");
number %= 1000000;
}

var thousand = (number / 1000);
if (thousand > 0)
{
parts.Add(string.Format("{0} min", thousand > 1 ? Convert(thousand) : "").Trim());
parts.Add($"{(thousand > 1 ? Convert(thousand) : "")} min".Trim());
number %= 1000;
}

var hundred = (number / 100);
if (hundred > 0)
{
parts.Add(string.Format("{0} yüz", hundred > 1 ? Convert(hundred) : "").Trim());
parts.Add($"{(hundred > 1 ? Convert(hundred) : "")} yüz".Trim());
number %= 100;
}

Expand Down Expand Up @@ -107,7 +107,7 @@ public override string ConvertToOrdinal(int number)
word = word.Substring(0, word.Length - 1);
}

return string.Format("{0}{1}", word, wordSuffix);
return $"{word}{wordSuffix}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,32 @@ public override string Convert(long input)

if (number < 0)
{
return string.Format("ঋণাত্মক {0}", Convert(-number));
return $"ঋণাত্মক {Convert(-number)}";
}

var parts = new List<string>();

if ((number / 10000000) > 0)
{
parts.Add(string.Format("{0} কোটি", Convert(number / 10000000)));
parts.Add($"{Convert(number / 10000000)} কোটি");
number %= 10000000;
}

if ((number / 100000) > 0)
{
parts.Add(string.Format("{0} লক্ষ", Convert(number / 100000)));
parts.Add($"{Convert(number / 100000)} লক্ষ");
number %= 100000;
}

if ((number / 1000) > 0)
{
parts.Add(string.Format("{0} হাজার", Convert(number / 1000)));
parts.Add($"{Convert(number / 1000)} হাজার");
number %= 1000;
}

if ((number / 100) > 0)
{
parts.Add(string.Format("{0}", HundredsMap[number / 100]));
parts.Add($"{HundredsMap[number / 100]}");
number %= 100;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd

if (number < 0)
{
return string.Format("menos {0}", Convert(Math.Abs(number), gender));
return $"menos {Convert(Math.Abs(number), gender)}";
}

var parts = new List<string>();
Expand All @@ -38,8 +38,8 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd
{
// gender is not applied for billions
parts.Add(number / 1000000000 >= 2
? string.Format("{0} bilhões", Convert(number / 1000000000, GrammaticalGender.Masculine))
: string.Format("{0} bilhão", Convert(number / 1000000000, GrammaticalGender.Masculine)));
? $"{Convert(number / 1000000000, GrammaticalGender.Masculine)} bilhões"
: $"{Convert(number / 1000000000, GrammaticalGender.Masculine)} bilhão");

number %= 1000000000;
}
Expand All @@ -48,16 +48,16 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd
{
// gender is not applied for millions
parts.Add(number / 1000000 >= 2
? string.Format("{0} milhões", Convert(number / 1000000, GrammaticalGender.Masculine))
: string.Format("{0} milhão", Convert(number / 1000000, GrammaticalGender.Masculine)));
? $"{Convert(number / 1000000, GrammaticalGender.Masculine)} milhões"
: $"{Convert(number / 1000000, GrammaticalGender.Masculine)} milhão");

number %= 1000000;
}

if ((number / 1000) > 0)
{
// gender is not applied for thousands
parts.Add(number / 1000 == 1 ? "mil" : string.Format("{0} mil", Convert(number / 1000, GrammaticalGender.Masculine)));
parts.Add(number / 1000 == 1 ? "mil" : $"{Convert(number / 1000, GrammaticalGender.Masculine)} mil");
number %= 1000;
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public override string Convert(long input, GrammaticalGender gender, bool addAnd
var lastPart = PortugueseTensMap[number / 10];
if ((number % 10) > 0)
{
lastPart += string.Format(" e {0}", ApplyGender(PortugueseUnitsMap[number % 10], gender));
lastPart += $" e {ApplyGender(PortugueseUnitsMap[number % 10], gender)}";
}

parts.Add(lastPart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override string Convert(long number)

if (number < 0)
{
return string.Format("نێگەتیڤ {0}", Convert(-number));
return $"نێگەتیڤ {Convert(-number)}";
}

if (number == 0)
Expand All @@ -29,11 +29,11 @@ public override string Convert(long number)

var kurdishGroupsMap = new Dictionary<long, Func<long, string>>
{
{(long)Math.Pow(10, 15), n => string.Format("{0} کوادریلیۆن", Convert(n)) },
{(long)Math.Pow(10, 12), n => string.Format("{0} تریلیۆن", Convert(n)) },
{(long)Math.Pow(10, 9), n => string.Format("{0} میلیارد", Convert(n)) },
{(long)Math.Pow(10, 6), n => string.Format("{0} میلیۆن", Convert(n)) },
{(long)Math.Pow(10, 3), n => string.Format("{0} هەزار", Convert(n)) },
{(long)Math.Pow(10, 15), n => $"{Convert(n)} کوادریلیۆن"},
{(long)Math.Pow(10, 12), n => $"{Convert(n)} تریلیۆن"},
{(long)Math.Pow(10, 9), n => $"{Convert(n)} میلیارد"},
{(long)Math.Pow(10, 6), n => $"{Convert(n)} میلیۆن"},
{(long)Math.Pow(10, 3), n => $"{Convert(n)} هەزار"},
{(long)Math.Pow(10, 2), n => KurdishHundredsMap[n]}
};

Expand Down Expand Up @@ -68,7 +68,7 @@ public override string Convert(long number)
public override string ConvertToOrdinal(int number)
{
var word = Convert(number);
return string.Format("{0}{1}", word, IsVowel(word[word.Length - 1]) ? "یەم" : "ەم");
return $"{word}{(IsVowel(word[word.Length - 1]) ? "یەم" : "ەم")}";
}

private bool IsVowel(char c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private string Convert(long number, bool isOrdinal, bool isSpecial)

if (number < 0)
{
return string.Format("负 {0}", Convert(-number, false, false));
return $"负 {Convert(-number, false, false)}";
}

var parts = new List<string>();
Expand Down Expand Up @@ -100,10 +100,10 @@ private string Convert(long number, bool isOrdinal, bool isSpecial)
}
else
{
var lastPart = string.Format("{0}十", UnitsMap[number / 10]);
var lastPart = $"{UnitsMap[number / 10]}十";
if ((number % 10) > 0)
{
lastPart += string.Format("{0}", UnitsMap[number % 10]);
lastPart += $"{UnitsMap[number % 10]}";
}

parts.Add(lastPart);
Expand All @@ -119,7 +119,7 @@ private string Convert(long number, bool isOrdinal, bool isSpecial)

if (isOrdinal)
{
toWords = string.Format("第 {0}", toWords);
toWords = $"第 {toWords}";
}

return toWords;
Expand Down
Loading

0 comments on commit 4b6234f

Please sign in to comment.