Skip to content

Commit

Permalink
Fixed SnakeCase
Browse files Browse the repository at this point in the history
  • Loading branch information
tbm0115 committed Apr 11, 2023
1 parent 61ebb43 commit 09e5a0c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion MtconnectTranspiler.Sinks.CSharp/Models/ScribanHelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using MtconnectTranspiler.Xmi.UML;
using MtconnectTranspiler.Contracts;
using System.Text;

namespace MtconnectTranspiler.Sinks.CSharp.Models
{
Expand Down Expand Up @@ -173,7 +174,39 @@ public static string ToSummary(string markdown)
/// <summary></summary>
/// <param name="input"></param>
/// <returns><c>"The Quick Brown Fox"</c> => <c>"the_quick_brown_fox"</c></returns>
public static string ToSnakeCase(string input) => CaseExtensions.StringExtensions.ToSnakeCase(input);
public static string ToSnakeCase(string input)
{
if (string.IsNullOrEmpty(input))
{
return input;
}

var result = new StringBuilder();
var lastCharWasUpper = false;
var lastCharWasLetterOrDigit = false;

for (int i = 0; i < input.Length; i++)
{
char c = input[i];
if (char.IsUpper(c))
{
if (i > 0 && lastCharWasLetterOrDigit && !lastCharWasUpper)
{
result.Append('_');
}
result.Append(char.ToLower(c));
lastCharWasUpper = true;
}
else
{
result.Append(c);
lastCharWasUpper = false;
}
lastCharWasLetterOrDigit = char.IsLetterOrDigit(c);
}

return result.ToString();
}

/// <inheritdoc cref="ToSnakeCase(string)" />
/// <remarks><inheritdoc cref="ToCodeSafe(string, string)" path="/summary"/></remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>MTConnect Transpiler Sink for C#</Title>
<Version>1.0.7</Version>
<Version>1.0.8</Version>
<Authors>mtconnect, tbm0115</Authors>
<Company>MTConnect Institute; TAMS;</Company>
<Description>An implementation of `ITranspilerSink` from the `MtconnectTranspiler` library. This libary makes it possible to transpile the MTConnect Standard SysML model into C# code.</Description>
Expand Down

0 comments on commit 09e5a0c

Please sign in to comment.