File tree Expand file tree Collapse file tree
src/MsgPack/Serialization Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments