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 index from end expressions #1438

Merged
merged 1 commit into from
Feb 22, 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 @@ -127,7 +127,7 @@ string Convert(int number, bool isOrdinal, GrammaticalGender gender)
}
else if (isOrdinal)
{
parts[parts.Count - 1] += (number == 0 ? "" : "en") + (millionOrMore ? "te" : "de");
parts[^1] += (number == 0 ? "" : "en") + (millionOrMore ? "te" : "de");
}

var toWords = string.Concat(parts).Trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ string ConvertImpl(long number, bool isOrdinal)
if (number > 0)
parts.Add(GetTensValue(number, isOrdinal));
else if (isOrdinal)
parts[parts.Count - 1] += "வது";
parts[^1] += "வது";

var toWords = string.Join(" ", parts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public override string ConvertToOrdinal(int number)
}
}

if (word[word.Length - 1] == 't')
if (word[^1] == 't')
{
word = word.Substring(0, word.Length - 1) + 'd';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override string ConvertToOrdinal(int number)
return string.Empty;
}

var lastChar = word[word.Length - 1];
var lastChar = word[^1];
if (lastChar is 'и' or 'а')
{
i = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override string ConvertToOrdinal(int number)
return string.Empty;
}

var lastChar = word[word.Length - 1];
var lastChar = word[^1];
if (lastChar is 'i' or 'a')
{
i = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer/MetricNumeralExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static MetricNumeralExtensions()
public static double FromMetric(this string input)
{
input = CleanRepresentation(input);
return BuildNumber(input, input[input.Length - 1]);
return BuildNumber(input, input[^1]);
}

/// <summary>
Expand Down