♻️ Extract the Storage service to DysonNetwork.Drive microservice

This commit is contained in:
2025-07-06 17:29:26 +08:00
parent 6a3d04af3d
commit 14b79f16f4
71 changed files with 2629 additions and 346 deletions

View File

@ -0,0 +1,43 @@
using System.Text;
using System.Text.RegularExpressions;
namespace DysonNetwork.Drive.Extensions;
public static class StringExtensions
{
private static readonly Regex _matchFirstCap = new(@"(.)([A-Z][a-z])");
private static readonly Regex _matchAllCap = new(@"([a-z0-9])([A-Z])");
public static string ToSnakeCase(this string input)
{
if (string.IsNullOrEmpty(input))
return input;
// Handle the first character
var result = new StringBuilder();
result.Append(char.ToLowerInvariant(input[0]));
// Process the rest of the string
for (int i = 1; i < input.Length; i++)
{
if (char.IsUpper(input[i]))
{
result.Append('_');
result.Append(char.ToLowerInvariant(input[i]));
}
else
{
result.Append(input[i]);
}
}
// Replace any remaining uppercase letters with lowercase
var output = result.ToString().ToLowerInvariant();
// Handle special cases (acronyms)
output = _matchFirstCap.Replace(output, "$1_$2");
output = _matchAllCap.Replace(output, "$1_$2");
return output.ToLowerInvariant();
}
}