Skip to content
Open
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
10 changes: 4 additions & 6 deletions src/Refit/SeparatedCaseFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Text;

namespace Refit;

/// <summary>Converts PascalCase/camelCase identifiers into a lower-case, separator-delimited form (e.g. snake_case or kebab-case).</summary>
Expand All @@ -23,22 +21,22 @@ internal static string Format(string key, char separator)
return key;
}

var builder = new StringBuilder(key.Length + SeparatorCapacityHeadroom);
var builder = new ValueStringBuilder(key.Length + SeparatorCapacityHeadroom);
for (var i = 0; i < key.Length; i++)
{
var current = key[i];
if (char.IsUpper(current))
{
if (i > 0 && NeedsSeparatorBefore(key, i))
{
_ = builder.Append(separator);
builder.Append(separator);
}

_ = builder.Append(char.ToLowerInvariant(current));
builder.Append(char.ToLowerInvariant(current));
}
else
{
_ = builder.Append(current);
builder.Append(current);
}
}

Expand Down
Loading