|
1 | 1 | /****************************************************************************************************** |
2 | 2 | Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator) |
3 | | - Version : 1.3.4.0 |
| 3 | + Version : 1.3.5.0 |
4 | 4 | (if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable) |
5 | 5 |
|
6 | 6 | Author : Coding Seb |
@@ -31,7 +31,7 @@ public class ExpressionEvaluator |
31 | 31 | private const string diactitics = "áàâãåǎăāąæéèêëěēĕėęěìíîïīĭįijóôõöōŏőøðœùúûüǔũūŭůűųýþÿŷıćĉċčçďđĝğġģĥħĵķĺļľŀłńņňŋñŕŗřśŝşšţťŧŵźżžÁÀÂÃÅǍĂĀĄÆÉÈÊËĚĒĔĖĘĚÌÍÎÏĪĬĮIJÓÔÕÖŌŎŐØÐŒÙÚÛÜǓŨŪŬŮŰŲÝÞŸŶIĆĈĊČÇĎĐĜĞĠĢĤĦĴĶĹĻĽĿŁŃŅŇŊÑŔŖŘŚŜŞŠŢŤŦŴŹŻŽß"; |
32 | 32 | private const string diactiticsKeywordsRegexPattern = "a-zA-Z_" + diactitics; |
33 | 33 |
|
34 | | - private static readonly Regex varOrFunctionRegEx = new Regex($@"^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[{ diactiticsKeywordsRegexPattern }](?>[{ diactiticsKeywordsRegexPattern }0-9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![{ diactiticsKeywordsRegexPattern}0-9]))|((?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))", RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| 34 | + private static readonly Regex varOrFunctionRegEx = new Regex($@"^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<inObject>(?<nullConditional>[?])?\.)?)(?<name>[{ diactiticsKeywordsRegexPattern }](?>[{ diactiticsKeywordsRegexPattern }0-9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![{ diactiticsKeywordsRegexPattern}0-9]))|((?<isgeneric>[<](?>([{ diactiticsKeywordsRegexPattern }](?>[{ diactiticsKeywordsRegexPattern }0-9]*)|(?>\s+)|[,\.])+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))", RegexOptions.IgnoreCase | RegexOptions.Compiled); |
35 | 35 |
|
36 | 36 | private const string numberRegexOrigPattern = @"^(?<sign>[+-])?([0-9][0-9_{1}]*[0-9]|\d)(?<hasdecimal>{0}?([0-9][0-9_]*[0-9]|\d)(e[+-]?([0-9][0-9_]*[0-9]|\d))?)?(?<type>ul|[fdulm])?"; |
37 | 37 | private string numberRegexPattern = null; |
@@ -527,6 +527,13 @@ private StringComparer StringComparerForCasing |
527 | 527 | } |
528 | 528 | } |
529 | 529 |
|
| 530 | + /// <summary> |
| 531 | + /// If <c>true</c> all numbers without decimal and suffixes evaluations will be done as double |
| 532 | + /// If <c>false</c> Integers values without decimal and suffixes will be evaluate as int as in C# (Warning some operation can round values) |
| 533 | + /// By default = false |
| 534 | + /// </summary> |
| 535 | + public bool OptionForceIntegerNumbersEvaluationsAsDoubleByDefault { get; set; } = false; |
| 536 | + |
530 | 537 | private CultureInfo cultureInfoForNumberParsing = CultureInfo.InvariantCulture.Clone() as CultureInfo; |
531 | 538 |
|
532 | 539 | /// <summary> |
@@ -625,21 +632,12 @@ public string OptionNumberParsingThousandSeparator |
625 | 632 | /// </summary> |
626 | 633 | public bool OptionFluidPrefixingActive { get; set; } = true; |
627 | 634 |
|
628 | | - private bool optionInlineNamespacesEvaluationActive = true; |
629 | | - |
630 | 635 | /// <summary> |
631 | 636 | /// if <c>true</c> allow the use of inline namespace (Can be slow, and is less secure). |
632 | 637 | /// if <c>false</c> unactive inline namespace (only namespaces in Namespaces list are available). |
633 | 638 | /// By default : true |
634 | 639 | /// </summary> |
635 | | - public bool OptionInlineNamespacesEvaluationActive |
636 | | - { |
637 | | - get { return optionInlineNamespacesEvaluationActive; } |
638 | | - set |
639 | | - { |
640 | | - optionInlineNamespacesEvaluationActive = value; |
641 | | - } |
642 | | - } |
| 640 | + public bool OptionInlineNamespacesEvaluationActive { get; set; } = true; |
643 | 641 |
|
644 | 642 | private Func<ExpressionEvaluator, List<string>, object> newMethodMem; |
645 | 643 |
|
@@ -1514,12 +1512,13 @@ private bool EvaluateNumber(string restOfExpression, Stack<object> stack, ref in |
1514 | 1512 | } |
1515 | 1513 | else |
1516 | 1514 | { |
1517 | | - if (numberMatch.Groups["hasdecimal"].Success) |
| 1515 | + if (OptionForceIntegerNumbersEvaluationsAsDoubleByDefault || numberMatch.Groups["hasdecimal"].Success) |
1518 | 1516 | { |
1519 | 1517 | stack.Push(double.Parse(numberMatch.Value.Replace("_",""), NumberStyles.Any, CultureInfoForNumberParsing)); |
1520 | 1518 | } |
1521 | 1519 | else |
1522 | 1520 | { |
| 1521 | + |
1523 | 1522 | stack.Push(int.Parse(numberMatch.Value.Replace("_", ""), NumberStyles.Any, CultureInfoForNumberParsing)); |
1524 | 1523 | } |
1525 | 1524 | } |
@@ -2804,6 +2803,24 @@ private List<string> GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(s |
2804 | 2803 | s = expr.Substring(i, 1); |
2805 | 2804 |
|
2806 | 2805 | if (s.Equals(startChar)) bracketCount++; |
| 2806 | + else if (s.Equals("(")) |
| 2807 | + { |
| 2808 | + i++; |
| 2809 | + currentExpression += "(" + GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(expr, ref i, false, ",", "(", ")").SingleOrDefault() + ")"; |
| 2810 | + continue; |
| 2811 | + } |
| 2812 | + else if (s.Equals("{")) |
| 2813 | + { |
| 2814 | + i++; |
| 2815 | + currentExpression += "{" + GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(expr, ref i, false, ",", "{", "}").SingleOrDefault() + "}"; |
| 2816 | + continue; |
| 2817 | + } |
| 2818 | + else if (s.Equals("[")) |
| 2819 | + { |
| 2820 | + i++; |
| 2821 | + currentExpression += "[" + GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(expr, ref i, false, ",", "[", "]").SingleOrDefault() + "]"; |
| 2822 | + continue; |
| 2823 | + } |
2807 | 2824 |
|
2808 | 2825 | if (s.Equals(endChar)) |
2809 | 2826 | { |
|
0 commit comments