Skip to content

Commit

Permalink
Merge pull request #1060 from dahlbyk/IndexOf
Browse files Browse the repository at this point in the history
Adjust `IndexOf` Usage
  • Loading branch information
clairernovotny authored Apr 30, 2021
2 parents 858b7c5 + 9a6f1f7 commit 1285835
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Humanizer/Bytes/ByteSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ public string ToString(string format, IFormatProvider provider)

format = format.Replace("#.##", "0.##");

bool has(string s) => format.IndexOf(s, StringComparison.CurrentCultureIgnoreCase) != -1;
var culture = provider as CultureInfo ?? CultureInfo.CurrentCulture;

bool has(string s) => culture.CompareInfo.IndexOf(format, s, CompareOptions.IgnoreCase) != -1;
string output(double n) => n.ToString(format, provider);

if (has(TerabyteSymbol))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private static string GetUnitValue(int number, bool isOrdinal)
private static string RemoveOnePrefix(string toWords)
{
// one hundred => hundredth
if (toWords.IndexOf("een", StringComparison.Ordinal) == 0)
if (toWords.StartsWith("een", StringComparison.Ordinal))
{
if (toWords.IndexOf("een en", StringComparison.Ordinal) != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private static string GetUnitValue(long number, bool isOrdinal)
private static string RemoveOnePrefix(string toWords)
{
// one hundred => hundredth
if (toWords.IndexOf("մեկ", StringComparison.Ordinal) == 0)
if (toWords.StartsWith("մեկ", StringComparison.Ordinal))
{
toWords = toWords.Remove(0, 4);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static string GetUnitValue(long number, bool isOrdinal)
private static string RemoveOnePrefix(string toWords)
{
// one hundred => hundredth
if (toWords.IndexOf("one", StringComparison.Ordinal) == 0)
if (toWords.StartsWith("one", StringComparison.Ordinal))
{
toWords = toWords.Remove(0, 4);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private static string GetHundredsValue(ref long number)
private static string RemoveOnePrefix(string toWords)
{
// one hundred => hundredth
if (toWords.IndexOf("one", StringComparison.Ordinal) == 0)
if (toWords.StartsWith("one", StringComparison.Ordinal))
toWords = toWords.Remove(0, 4);

return toWords;
Expand Down

0 comments on commit 1285835

Please sign in to comment.