Skip to content

Commit 8c24a98

Browse files
author
Sébastien Geiser
committed
Correction of a bug when imbricate different brackets types with coma separators
version unstable
1 parent fb266a2 commit 8c24a98

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public void TypeTesting(string expression, Type type)
384384
[TestCase("5 + 10 * 2", TestOf = typeof(int), ExpectedResult = 25, Category = "DivAndMultiplyPriorityOverSubAndAdd")]
385385
#endregion
386386

387-
#region ParenthesisPriority
387+
#region Parenthesis Priority
388388
[TestCase("(5d - 10) / 2", TestOf = typeof(double), ExpectedResult = -2.5, Category = "ParenthesisPriority")]
389389
[TestCase("(5d + 10) / 2", TestOf = typeof(double), ExpectedResult = 7.5, Category = "ParenthesisPriority")]
390390
[TestCase("(5 - 10) * 2", TestOf = typeof(double), ExpectedResult = -10, Category = "ParenthesisPriority")]
@@ -971,6 +971,7 @@ public void TypeTesting(string expression, Type type)
971971
[TestCase("$\"https://www.google.com/search?q={System.Net.WebUtility.UrlEncode(\"test of request with url encode() ?\")}\"", ExpectedResult = "https://www.google.com/search?q=test+of+request+with+url+encode()+%3F", Category = "Complex expression,Inline namespace")]
972972
[TestCase("new System.Xml.XmlDocument().FluidLoadXml(\"<root><element id='MyElement'>Xml Content</element></root>\").SelectSingleNode(\"//element[@id='MyElement']\").InnerXml", ExpectedResult = "Xml Content", Category = "Complex expression,Inline namespace,Fluid")]
973973
[TestCase("new System.Xml.XmlDocument().FluidLoadXml(\"<root><element id='MyElement'>Xml Content</element></root>\").ChildNodes[0].Name", ExpectedResult = "root", Category = "Complex expression,Inline namespace,Fluid,Custom Indexer")]
974+
[TestCase("string.Join(\" - \", new string[]{\"Hello\", \"Bye\", \"Other\"})", ExpectedResult = "Hello - Bye - Other", Category = "Complex expression, Different brackets imbrication")]
974975

975976
#endregion
976977

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************************************
22
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3-
Version : 1.3.4.0
3+
Version : 1.3.4.1
44
(if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable)
55
66
Author : Coding Seb
@@ -2804,6 +2804,24 @@ private List<string> GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(s
28042804
s = expr.Substring(i, 1);
28052805

28062806
if (s.Equals(startChar)) bracketCount++;
2807+
else if (s.Equals("("))
2808+
{
2809+
i++;
2810+
currentExpression += "(" + GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(expr, ref i, false, ",", "(", ")").SingleOrDefault() + ")";
2811+
continue;
2812+
}
2813+
else if (s.Equals("{"))
2814+
{
2815+
i++;
2816+
currentExpression += "{" + GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(expr, ref i, false, ",", "{", "}").SingleOrDefault() + "}";
2817+
continue;
2818+
}
2819+
else if (s.Equals("["))
2820+
{
2821+
i++;
2822+
currentExpression += "[" + GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(expr, ref i, false, ",", "[", "]").SingleOrDefault() + "]";
2823+
continue;
2824+
}
28072825

28082826
if (s.Equals(endChar))
28092827
{

0 commit comments

Comments
 (0)