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

Adjust IndexOf Usage #1060

Merged
merged 2 commits into from
Apr 30, 2021
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
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