diff --git a/LiteDB/Document/Expression/BsonExpression.cs b/LiteDB/Document/Expression/BsonExpression.cs index 45793ab4e..eb52a77a1 100644 --- a/LiteDB/Document/Expression/BsonExpression.cs +++ b/LiteDB/Document/Expression/BsonExpression.cs @@ -414,14 +414,14 @@ internal static void SetParameters(BsonExpression expr, BsonDocument parameters) /// private static Dictionary _methods = typeof(BsonExpressionMethods).GetMethods(BindingFlags.Public | BindingFlags.Static) - .ToDictionary(m => m.Name.ToUpper() + "~" + m.GetParameters().Where(p => p.ParameterType != typeof(Collation)).Count()); + .ToDictionary(m => m.Name.ToUpperInvariant() + "~" + m.GetParameters().Where(p => p.ParameterType != typeof(Collation)).Count()); /// /// Get expression method with same name and same parameter - return null if not found /// internal static MethodInfo GetMethod(string name, int parameterCount) { - var key = name.ToUpper() + "~" + parameterCount; + var key = name.ToUpperInvariant() + "~" + parameterCount; return _methods.GetOrDefault(key); } @@ -440,7 +440,7 @@ internal static MethodInfo GetMethod(string name, int parameterCount) /// private static Dictionary _functions = typeof(BsonExpressionFunctions).GetMethods(BindingFlags.Public | BindingFlags.Static) - .ToDictionary(m => m.Name.ToUpper() + "~" + m.GetParameters() + .ToDictionary(m => m.Name.ToUpperInvariant() + "~" + m.GetParameters() .Skip(5).Count()); /// @@ -448,7 +448,7 @@ internal static MethodInfo GetMethod(string name, int parameterCount) /// internal static MethodInfo GetFunction(string name, int parameterCount = 0) { - var key = name.ToUpper() + "~" + parameterCount; + var key = name.ToUpperInvariant() + "~" + parameterCount; return _functions.GetOrDefault(key); } diff --git a/LiteDB/Document/Expression/Parser/BsonExpressionParser.cs b/LiteDB/Document/Expression/Parser/BsonExpressionParser.cs index 6817d7180..77ca4afe5 100644 --- a/LiteDB/Document/Expression/Parser/BsonExpressionParser.cs +++ b/LiteDB/Document/Expression/Parser/BsonExpressionParser.cs @@ -121,7 +121,7 @@ public static BsonExpression ParseFullExpression(Tokenizer tokenizer, Expression } values.Add(expr); - ops.Add(op.ToUpper()); + ops.Add(op.ToUpperInvariant()); } var order = 0; @@ -888,7 +888,7 @@ private static BsonExpression TryParseMethodCall(Tokenizer tokenizer, Expression var useSource = false; var fields = new HashSet(StringComparer.OrdinalIgnoreCase); - src.Append(token.Value.ToUpper() + "("); + src.Append(token.Value.ToUpperInvariant() + "("); // method call with no parameters if (tokenizer.LookAhead().Type == TokenType.CloseParenthesis) @@ -926,7 +926,7 @@ private static BsonExpression TryParseMethodCall(Tokenizer tokenizer, Expression var method = BsonExpression.GetMethod(token.Value, pars.Count); - if (method == null) throw LiteException.UnexpectedToken($"Method '{token.Value.ToUpper()}' does not exist or contains invalid parameters", token); + if (method == null) throw LiteException.UnexpectedToken($"Method '{token.Value.ToUpperInvariant()}' does not exist or contains invalid parameters", token); // test if method are decorated with "Variable" (immutable = false) if (method.GetCustomAttribute() != null) @@ -1170,7 +1170,7 @@ private static BsonExpression TryParseFunction(Tokenizer tokenizer, ExpressionCo if (tokenizer.Current.Type != TokenType.Word) return null; if (tokenizer.LookAhead().Type != TokenType.OpenParenthesis) return null; - var token = tokenizer.Current.Value.ToUpper(); + var token = tokenizer.Current.Value.ToUpperInvariant(); switch (token) { @@ -1385,7 +1385,7 @@ private static string ReadOperant(Tokenizer tokenizer) if (token.Is("ALL") || token.Is("ANY")) { - var key = token.Value.ToUpper(); + var key = token.Value.ToUpperInvariant(); tokenizer.ReadToken(); // consume operant @@ -1474,7 +1474,7 @@ internal static BsonExpression CreateLogicExpression(BsonExpressionType type, Bs Expression = Expression.New(ctor, expr), Left = left, Right = right, - Source = left.Source + " " + (type.ToString().ToUpper()) + " " + right.Source + Source = left.Source + " " + (type.ToString().ToUpperInvariant()) + " " + right.Source }; return result; diff --git a/LiteDB/Utils/Collation.cs b/LiteDB/Utils/Collation.cs index 844737632..0ccc29e79 100644 --- a/LiteDB/Utils/Collation.cs +++ b/LiteDB/Utils/Collation.cs @@ -70,15 +70,6 @@ public int Compare(string left, string right) return result < 0 ? -1 : result > 0 ? +1 : 0; } - /// - /// Compare 2 chars values using current culture/compare options - /// - public int Compare(char left, char right) - { - //TODO implementar o compare corretamente - return char.ToUpper(left) == char.ToUpper(right) ? 0 : 1; - } - public int Compare(BsonValue left, BsonValue rigth) { return left.CompareTo(rigth, this); diff --git a/LiteDB/Utils/Extensions/StringExtensions.cs b/LiteDB/Utils/Extensions/StringExtensions.cs index 468dcd3c4..12270ee39 100644 --- a/LiteDB/Utils/Extensions/StringExtensions.cs +++ b/LiteDB/Utils/Extensions/StringExtensions.cs @@ -108,7 +108,7 @@ public static bool SqlLike(this string str, string pattern, Collation collation) if (isWildCardOn) { - if (char.ToUpper(c) == char.ToUpper(p)) + if (collation.Compare(c.ToString(), p.ToString()) == 0) { isWildCardOn = false; patternIndex++; @@ -140,7 +140,7 @@ public static bool SqlLike(this string str, string pattern, Collation collation) } else { - if (collation.Compare(c, p) == 0) + if (collation.Compare(c.ToString(), p.ToString()) == 0) { patternIndex++; }