Skip to content

Commit 97107ea

Browse files
committed
Fix EnumNameTransformers.UpperSnake does not handle underscore correctly.
1 parent 6f41a36 commit 97107ea

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/MsgPack/Serialization/KeyNameTransformers.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,20 @@ public static string ToUpperSnake( string mayBeUpperCamel )
5757
}
5858

5959
var buffer = new StringBuilder( mayBeUpperCamel.Length * 2 );
60+
char previous = '\0';
6061
int index = 0;
6162
for ( ; index < mayBeUpperCamel.Length; index++ )
6263
{
6364
var c = mayBeUpperCamel[ index ];
6465
if ( Char.IsUpper( c ) )
6566
{
6667
buffer.Append( c );
68+
previous = c;
6769
}
6870
else
6971
{
7072
buffer.Append( Char.ToUpperInvariant( c ) );
73+
previous = c;
7174
index++;
7275
break;
7376
}
@@ -78,12 +81,18 @@ public static string ToUpperSnake( string mayBeUpperCamel )
7881
var c = mayBeUpperCamel[ index ];
7982
if ( Char.IsUpper( c ) )
8083
{
81-
buffer.Append( '_' );
84+
if ( previous != '_' )
85+
{
86+
buffer.Append( '_' );
87+
}
88+
8289
buffer.Append( c );
90+
previous = c;
8391
}
8492
else
8593
{
8694
buffer.Append( Char.ToUpperInvariant( c ) );
95+
previous = c;
8796
}
8897
}
8998

0 commit comments

Comments
 (0)