Skip to content

Commit a930df1

Browse files
committed
Replaced ToUpper with ToUpperInvariant for internal funcions and methods (fix for issue #1995)
Removed usage of Compare(char, char) method on SqlLike string extension and replaced it for Compare(string, string)
1 parent d12ee99 commit a930df1

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

LiteDB/Document/Expression/BsonExpression.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,14 @@ internal static void SetParameters(BsonExpression expr, BsonDocument parameters)
414414
/// </summary>
415415
private static Dictionary<string, MethodInfo> _methods =
416416
typeof(BsonExpressionMethods).GetMethods(BindingFlags.Public | BindingFlags.Static)
417-
.ToDictionary(m => m.Name.ToUpper() + "~" + m.GetParameters().Where(p => p.ParameterType != typeof(Collation)).Count());
417+
.ToDictionary(m => m.Name.ToUpperInvariant() + "~" + m.GetParameters().Where(p => p.ParameterType != typeof(Collation)).Count());
418418

419419
/// <summary>
420420
/// Get expression method with same name and same parameter - return null if not found
421421
/// </summary>
422422
internal static MethodInfo GetMethod(string name, int parameterCount)
423423
{
424-
var key = name.ToUpper() + "~" + parameterCount;
424+
var key = name.ToUpperInvariant() + "~" + parameterCount;
425425

426426
return _methods.GetOrDefault(key);
427427
}
@@ -440,15 +440,15 @@ internal static MethodInfo GetMethod(string name, int parameterCount)
440440
/// </summary>
441441
private static Dictionary<string, MethodInfo> _functions =
442442
typeof(BsonExpressionFunctions).GetMethods(BindingFlags.Public | BindingFlags.Static)
443-
.ToDictionary(m => m.Name.ToUpper() + "~" + m.GetParameters()
443+
.ToDictionary(m => m.Name.ToUpperInvariant() + "~" + m.GetParameters()
444444
.Skip(5).Count());
445445

446446
/// <summary>
447447
/// Get expression function with same name and same parameter - return null if not found
448448
/// </summary>
449449
internal static MethodInfo GetFunction(string name, int parameterCount = 0)
450450
{
451-
var key = name.ToUpper() + "~" + parameterCount;
451+
var key = name.ToUpperInvariant() + "~" + parameterCount;
452452

453453
return _functions.GetOrDefault(key);
454454
}

LiteDB/Document/Expression/Parser/BsonExpressionParser.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static BsonExpression ParseFullExpression(Tokenizer tokenizer, Expression
121121
}
122122

123123
values.Add(expr);
124-
ops.Add(op.ToUpper());
124+
ops.Add(op.ToUpperInvariant());
125125
}
126126

127127
var order = 0;
@@ -888,7 +888,7 @@ private static BsonExpression TryParseMethodCall(Tokenizer tokenizer, Expression
888888
var useSource = false;
889889
var fields = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
890890

891-
src.Append(token.Value.ToUpper() + "(");
891+
src.Append(token.Value.ToUpperInvariant() + "(");
892892

893893
// method call with no parameters
894894
if (tokenizer.LookAhead().Type == TokenType.CloseParenthesis)
@@ -926,7 +926,7 @@ private static BsonExpression TryParseMethodCall(Tokenizer tokenizer, Expression
926926

927927
var method = BsonExpression.GetMethod(token.Value, pars.Count);
928928

929-
if (method == null) throw LiteException.UnexpectedToken($"Method '{token.Value.ToUpper()}' does not exist or contains invalid parameters", token);
929+
if (method == null) throw LiteException.UnexpectedToken($"Method '{token.Value.ToUpperInvariant()}' does not exist or contains invalid parameters", token);
930930

931931
// test if method are decorated with "Variable" (immutable = false)
932932
if (method.GetCustomAttribute<VolatileAttribute>() != null)
@@ -1170,7 +1170,7 @@ private static BsonExpression TryParseFunction(Tokenizer tokenizer, ExpressionCo
11701170
if (tokenizer.Current.Type != TokenType.Word) return null;
11711171
if (tokenizer.LookAhead().Type != TokenType.OpenParenthesis) return null;
11721172

1173-
var token = tokenizer.Current.Value.ToUpper();
1173+
var token = tokenizer.Current.Value.ToUpperInvariant();
11741174

11751175
switch (token)
11761176
{
@@ -1385,7 +1385,7 @@ private static string ReadOperant(Tokenizer tokenizer)
13851385

13861386
if (token.Is("ALL") || token.Is("ANY"))
13871387
{
1388-
var key = token.Value.ToUpper();
1388+
var key = token.Value.ToUpperInvariant();
13891389

13901390
tokenizer.ReadToken(); // consume operant
13911391

@@ -1474,7 +1474,7 @@ internal static BsonExpression CreateLogicExpression(BsonExpressionType type, Bs
14741474
Expression = Expression.New(ctor, expr),
14751475
Left = left,
14761476
Right = right,
1477-
Source = left.Source + " " + (type.ToString().ToUpper()) + " " + right.Source
1477+
Source = left.Source + " " + (type.ToString().ToUpperInvariant()) + " " + right.Source
14781478
};
14791479

14801480
return result;

LiteDB/Utils/Collation.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ public int Compare(string left, string right)
7070
return result < 0 ? -1 : result > 0 ? +1 : 0;
7171
}
7272

73-
/// <summary>
74-
/// Compare 2 chars values using current culture/compare options
75-
/// </summary>
76-
public int Compare(char left, char right)
77-
{
78-
//TODO implementar o compare corretamente
79-
return char.ToUpper(left) == char.ToUpper(right) ? 0 : 1;
80-
}
81-
8273
public int Compare(BsonValue left, BsonValue rigth)
8374
{
8475
return left.CompareTo(rigth, this);

LiteDB/Utils/Extensions/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static bool SqlLike(this string str, string pattern, Collation collation)
108108

109109
if (isWildCardOn)
110110
{
111-
if (char.ToUpper(c) == char.ToUpper(p))
111+
if (collation.Compare(c.ToString(), p.ToString()) == 0)
112112
{
113113
isWildCardOn = false;
114114
patternIndex++;
@@ -140,7 +140,7 @@ public static bool SqlLike(this string str, string pattern, Collation collation)
140140
}
141141
else
142142
{
143-
if (collation.Compare(c, p) == 0)
143+
if (collation.Compare(c.ToString(), p.ToString()) == 0)
144144
{
145145
patternIndex++;
146146
}

0 commit comments

Comments
 (0)