Skip to content

Commit

Permalink
Merge pull request #844 from mikependon/more-optimal-using-stings-2
Browse files Browse the repository at this point in the history
More optimal use of methods String.StartsWith and String.EndsWith
  • Loading branch information
mikependon authored Jul 1, 2021
2 parents e22685b + c8e702f commit f70b8a1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
13 changes: 7 additions & 6 deletions RepoDb.Core/RepoDb/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,18 @@ private static string AsQuotedForDatabaseSchemaTableInternal(this string value,
{
if (!string.IsNullOrWhiteSpace(current))
{
if (current.StartsWith(dbSetting.OpeningQuote) && item.EndsWith(dbSetting.ClosingQuote))
if (current.StartsWith(dbSetting.OpeningQuote, StringComparison.OrdinalIgnoreCase)
&& item.EndsWith(dbSetting.ClosingQuote, StringComparison.OrdinalIgnoreCase))
{
list.Add(string.Concat(current, StringConstant.Period, item));
current = null;
}
}
else
{
if (item.StartsWith(dbSetting.OpeningQuote))
if (item.StartsWith(dbSetting.OpeningQuote, StringComparison.OrdinalIgnoreCase))
{
if (item.EndsWith(dbSetting.ClosingQuote))
if (item.EndsWith(dbSetting.ClosingQuote, StringComparison.OrdinalIgnoreCase))
{
list.Add(item.AsQuotedInternal(dbSetting));
}
Expand Down Expand Up @@ -247,11 +248,11 @@ private static string AsQuotedForDatabaseSchemaTableInternal(this string value,
private static string AsQuotedInternal(this string value,
IDbSetting dbSetting)
{
if (!value.StartsWith(dbSetting.OpeningQuote))
if (!value.StartsWith(dbSetting.OpeningQuote, StringComparison.OrdinalIgnoreCase))
{
value = string.Concat(dbSetting.OpeningQuote, value);
}
if (!value.EndsWith(dbSetting.ClosingQuote))
if (!value.EndsWith(dbSetting.ClosingQuote, StringComparison.OrdinalIgnoreCase))
{
value = string.Concat(value, dbSetting.ClosingQuote);
}
Expand Down Expand Up @@ -292,7 +293,7 @@ public static string AsParameter(this string value,
if (dbSetting != null)
{
value = string.Concat(dbSetting.ParameterPrefix,
(value.StartsWith(dbSetting.ParameterPrefix) ? value.Substring(1) : value)
(value.StartsWith(dbSetting.ParameterPrefix, StringComparison.OrdinalIgnoreCase) ? value.Substring(1) : value)
.AsUnquoted(true, dbSetting).AsAlphaNumeric());
}
return index > 0 ? string.Concat(value, "_", index.ToString()) : value;
Expand Down
2 changes: 1 addition & 1 deletion RepoDb.Core/RepoDb/Extensions/TypeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static bool IsClassType(this Type type) =>
/// <param name="type">The current type.</param>
/// <returns>Returns true if the current type is an anonymous class.</returns>
public static bool IsAnonymousType(this Type type) =>
type.FullName.StartsWith("<>f__AnonymousType");
type.FullName.StartsWith("<>f__AnonymousType", StringComparison.OrdinalIgnoreCase);

/// <summary>
/// Checks whether the current type is of type <see cref="IDictionary{TKey, TValue}"/> (with string/object key-value-pair).
Expand Down
2 changes: 1 addition & 1 deletion RepoDb.Core/RepoDb/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Parameter(string name,
/// </summary>
internal void PrependAnUnderscore()
{
if (!Name.StartsWith("_"))
if (!Name.StartsWith("_", StringComparison.OrdinalIgnoreCase))
{
Name = string.Concat("_", Name);
}
Expand Down
8 changes: 4 additions & 4 deletions RepoDb.Core/RepoDb/QueryField/ParseExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ private static string ConvertToLikeableValue(string methodName,
{
if (methodName == "Contains")
{
value = value.StartsWith("%") ? value : string.Concat("%", value);
value = value.EndsWith("%") ? value : string.Concat(value, "%");
value = value.StartsWith("%", StringComparison.OrdinalIgnoreCase) ? value : string.Concat("%", value);
value = value.EndsWith("%", StringComparison.OrdinalIgnoreCase) ? value : string.Concat(value, "%");
}
else if (methodName == "StartsWith")
{
value = value.EndsWith("%") ? value : string.Concat(value, "%");
value = value.EndsWith("%", StringComparison.OrdinalIgnoreCase) ? value : string.Concat(value, "%");
}
else if (methodName == "EndsWith")
{
value = value.StartsWith("%") ? value : string.Concat("%", value);
value = value.StartsWith("%", StringComparison.OrdinalIgnoreCase) ? value : string.Concat("%", value);
}
return value;
}
Expand Down

0 comments on commit f70b8a1

Please sign in to comment.