Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing string concatenation with StringBuilder.Append in Helper.ReplaceAll #342

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions QueryBuilder/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace SqlKata
Expand All @@ -10,7 +11,7 @@ public static class Helper
{
public static bool IsArray(object value)
{
if(value is string)
if (value is string)
{
return false;
}
Expand Down Expand Up @@ -88,8 +89,9 @@ public static string ReplaceAll(string subject, string match, Func<int, string>
);

return splitted.Skip(1)
.Select((item, index) => callback(index) + item)
.Aggregate(splitted.First(), (left, right) => left + right);
.Select((item, index) => callback(index) + item)
.Aggregate(new StringBuilder(splitted.First()), (prev, right) => prev.Append(right))
.ToString();
}

public static string JoinArray(string glue, IEnumerable array)
Expand Down Expand Up @@ -158,13 +160,13 @@ public static IEnumerable<string> Repeat(this string str, int count)
{
return Enumerable.Repeat(str, count);
}

public static string ReplaceIdentifierUnlessEscaped(this string input, string escapeCharacter, string identifier, string newIdentifier)
{
//Replace standard, non-escaped identifiers first
var nonEscapedRegex = new Regex($@"(?<!{Regex.Escape(escapeCharacter)}){Regex.Escape(identifier)}");
var nonEscapedReplace = nonEscapedRegex.Replace(input, newIdentifier);

//Then replace escaped identifiers, by just removing the escape character
var escapedRegex = new Regex($@"{Regex.Escape(escapeCharacter)}{Regex.Escape(identifier)}");
return escapedRegex.Replace(nonEscapedReplace, identifier);
Expand Down