22using System . Collections ;
33using System . Collections . Generic ;
44using System . Linq ;
5+ using System . Text ;
56using System . Text . RegularExpressions ;
67
78namespace SqlKata
@@ -10,7 +11,7 @@ public static class Helper
1011 {
1112 public static bool IsArray ( object value )
1213 {
13- if ( value is string )
14+ if ( value is string )
1415 {
1516 return false ;
1617 }
@@ -88,8 +89,9 @@ public static string ReplaceAll(string subject, string match, Func<int, string>
8889 ) ;
8990
9091 return splitted . Skip ( 1 )
91- . Select ( ( item , index ) => callback ( index ) + item )
92- . Aggregate ( splitted . First ( ) , ( left , right ) => left + right ) ;
92+ . Select ( ( item , index ) => callback ( index ) + item )
93+ . Aggregate ( new StringBuilder ( splitted . First ( ) ) , ( prev , right ) => prev . Append ( right ) )
94+ . ToString ( ) ;
9395 }
9496
9597 public static string JoinArray ( string glue , IEnumerable array )
@@ -158,13 +160,13 @@ public static IEnumerable<string> Repeat(this string str, int count)
158160 {
159161 return Enumerable . Repeat ( str , count ) ;
160162 }
161-
163+
162164 public static string ReplaceIdentifierUnlessEscaped ( this string input , string escapeCharacter , string identifier , string newIdentifier )
163165 {
164166 //Replace standard, non-escaped identifiers first
165167 var nonEscapedRegex = new Regex ( $@ "(?<!{ Regex . Escape ( escapeCharacter ) } ){ Regex . Escape ( identifier ) } ") ;
166168 var nonEscapedReplace = nonEscapedRegex . Replace ( input , newIdentifier ) ;
167-
169+
168170 //Then replace escaped identifiers, by just removing the escape character
169171 var escapedRegex = new Regex ( $@ "{ Regex . Escape ( escapeCharacter ) } { Regex . Escape ( identifier ) } ") ;
170172 return escapedRegex . Replace ( nonEscapedReplace , identifier ) ;
0 commit comments