Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
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.
  • Loading branch information
arturcic committed Aug 9, 2025
commit 133d7882b9e782448aa3b198ac5daaab88ceff2e
9 changes: 7 additions & 2 deletions src/GitVersion.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ public static bool IsEquivalentTo(this string self, string? other) =>
public static string WithPrefixIfNotNullOrEmpty(this string value, string prefix)
=> string.IsNullOrEmpty(value) ? value : prefix + value;

internal static string PascalCase(this string input, CultureInfo cultureInfo)
internal static string ToPascalCase(this TextInfo textInfo, string input)
{
if (string.IsNullOrEmpty(input))
{
return input;
}

var sb = new StringBuilder(input.Length);
var capitalizeNext = true;

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

sb.Append(capitalizeNext ? cultureInfo.TextInfo.ToUpper(c) : cultureInfo.TextInfo.ToLower(c));
sb.Append(capitalizeNext ? textInfo.ToUpper(c) : textInfo.ToLower(c));
capitalizeNext = false;
}

Expand Down
12 changes: 4 additions & 8 deletions src/GitVersion.Core/Formatting/StringFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ public override bool TryFormat(object? value, string format, CultureInfo culture
result = cultureInfo.TextInfo.ToTitleCase(cultureInfo.TextInfo.ToLower(stringValue));
return true;
case "s":
if (stringValue.Length == 1)
result = cultureInfo.TextInfo.ToUpper(stringValue);
else
{
result = cultureInfo.TextInfo.ToUpper(stringValue[0]) + cultureInfo.TextInfo.ToLower(stringValue[1..]);
}

result = stringValue.Length == 1
? cultureInfo.TextInfo.ToUpper(stringValue)
: cultureInfo.TextInfo.ToUpper(stringValue[0]) + cultureInfo.TextInfo.ToLower(stringValue[1..]);
return true;
case "c":
result = stringValue.PascalCase(cultureInfo);
result = cultureInfo.TextInfo.ToPascalCase(stringValue);
return true;
default:
result = string.Empty;
Expand Down