Skip to content

Commit 133d788

Browse files
committed
Renames and updates PascalCase extension method
Renames `PascalCase` to `ToPascalCase` and moves `TextInfo` parameter to improve clarity and usability. Refactors related calls to align with the updated method signature.
1 parent 16ff852 commit 133d788

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/GitVersion.Core/Extensions/StringExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ public static bool IsEquivalentTo(this string self, string? other) =>
3232
public static string WithPrefixIfNotNullOrEmpty(this string value, string prefix)
3333
=> string.IsNullOrEmpty(value) ? value : prefix + value;
3434

35-
internal static string PascalCase(this string input, CultureInfo cultureInfo)
35+
internal static string ToPascalCase(this TextInfo textInfo, string input)
3636
{
37+
if (string.IsNullOrEmpty(input))
38+
{
39+
return input;
40+
}
41+
3742
var sb = new StringBuilder(input.Length);
3843
var capitalizeNext = true;
3944

@@ -45,7 +50,7 @@ internal static string PascalCase(this string input, CultureInfo cultureInfo)
4550
continue;
4651
}
4752

48-
sb.Append(capitalizeNext ? cultureInfo.TextInfo.ToUpper(c) : cultureInfo.TextInfo.ToLower(c));
53+
sb.Append(capitalizeNext ? textInfo.ToUpper(c) : textInfo.ToLower(c));
4954
capitalizeNext = false;
5055
}
5156

src/GitVersion.Core/Formatting/StringFormatter.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ public override bool TryFormat(object? value, string format, CultureInfo culture
3333
result = cultureInfo.TextInfo.ToTitleCase(cultureInfo.TextInfo.ToLower(stringValue));
3434
return true;
3535
case "s":
36-
if (stringValue.Length == 1)
37-
result = cultureInfo.TextInfo.ToUpper(stringValue);
38-
else
39-
{
40-
result = cultureInfo.TextInfo.ToUpper(stringValue[0]) + cultureInfo.TextInfo.ToLower(stringValue[1..]);
41-
}
42-
36+
result = stringValue.Length == 1
37+
? cultureInfo.TextInfo.ToUpper(stringValue)
38+
: cultureInfo.TextInfo.ToUpper(stringValue[0]) + cultureInfo.TextInfo.ToLower(stringValue[1..]);
4339
return true;
4440
case "c":
45-
result = stringValue.PascalCase(cultureInfo);
41+
result = cultureInfo.TextInfo.ToPascalCase(stringValue);
4642
return true;
4743
default:
4844
result = string.Empty;

0 commit comments

Comments
 (0)