@@ -33,7 +33,7 @@ public class ExpressionEvaluator
33
33
34
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 ) ;
35
35
36
- private string numberRegexPattern = @"^(?<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])?" ;
36
+ private readonly string numberRegexPattern = @"^(?<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 Regex numberRegex = null ;
38
38
39
39
private static readonly Regex otherBasesNumberRegex = new Regex ( @"^(?<sign>[+-])?(?<value>0(?<type>x)([0-9a-f][0-9a-f_]*[0-9a-f]|[0-9a-f])|0(?<type>b)([01][01_]*[01]|[01]))" , RegexOptions . IgnoreCase ) ;
@@ -534,8 +534,6 @@ private StringComparer StringComparerForCasing
534
534
535
535
private CultureInfo cultureInfoForNumberParsing = CultureInfo . InvariantCulture . Clone ( ) as CultureInfo ;
536
536
537
- private string optionNumberParsingDecimalSeparator = "." ;
538
-
539
537
/// <summary>
540
538
/// The culture used to evaluate numbers
541
539
/// Synchronized with OptionNumberParsingDecimalSeparator and OptionNumberParsingThousandSeparator.
@@ -558,6 +556,8 @@ public CultureInfo CultureInfoForNumberParsing
558
556
}
559
557
}
560
558
559
+ private string optionNumberParsingDecimalSeparator = "." ;
560
+
561
561
/// <summary>
562
562
/// Allow to change the decimal separator of numbers when parsing expressions.
563
563
/// By default "."
@@ -567,17 +567,22 @@ public CultureInfo CultureInfoForNumberParsing
567
567
public string OptionNumberParsingDecimalSeparator
568
568
{
569
569
570
- get => optionNumberParsingDecimalSeparator ;
570
+ get
571
+ {
572
+ return optionNumberParsingDecimalSeparator ;
573
+ }
571
574
572
575
set
573
576
{
574
- optionNumberParsingDecimalSeparator = value ;
575
- CultureInfoForNumberParsing . NumberFormat . NumberDecimalSeparator = value ;
577
+ optionNumberParsingDecimalSeparator = value ?? "." ;
578
+ CultureInfoForNumberParsing . NumberFormat . NumberDecimalSeparator = optionNumberParsingDecimalSeparator ;
576
579
577
580
numberRegex = new Regex ( string . Format ( numberRegexPattern , Regex . Escape ( optionNumberParsingDecimalSeparator ) , Regex . Escape ( optionNumberParsingThousandSeparator ) ) , RegexOptions . IgnoreCase ) ;
578
581
}
579
582
}
580
583
584
+ private string optionNumberParsingThousandSeparator = string . Empty ;
585
+
581
586
/// <summary>
582
587
/// Allow to change the thousand separator of numbers when parsing expressions.
583
588
/// By default string.Empty
@@ -593,7 +598,7 @@ public string OptionNumberParsingThousandSeparator
593
598
594
599
set
595
600
{
596
- optionNumberParsingThousandSeparator = value ;
601
+ optionNumberParsingThousandSeparator = value ?? string . Empty ;
597
602
CultureInfoForNumberParsing . NumberFormat . NumberGroupSeparator = value ;
598
603
599
604
numberRegex = new Regex ( string . Format ( numberRegexPattern , Regex . Escape ( optionNumberParsingDecimalSeparator ) , Regex . Escape ( optionNumberParsingThousandSeparator ) ) , RegexOptions . IgnoreCase ) ;
@@ -832,7 +837,7 @@ public ExpressionEvaluator()
832
837
{
833
838
Assemblies . AddRange ( AppDomain . CurrentDomain . GetAssemblies ( ) ) ;
834
839
instanceCreationWithNewKeywordRegex = new Regex ( InstanceCreationWithNewKeywordRegexPattern ) ;
835
- numberRegex = new Regex ( string . Format ( numberRegexPattern , @"\." ) , RegexOptions . IgnoreCase ) ;
840
+ numberRegex = new Regex ( string . Format ( numberRegexPattern , @"\." , string . Empty ) , RegexOptions . IgnoreCase ) ;
836
841
CultureInfoForNumberParsing . NumberFormat . NumberDecimalSeparator = "." ;
837
842
castRegex = new Regex ( CastRegexPattern ) ;
838
843
}
@@ -851,7 +856,6 @@ public ExpressionEvaluator(Dictionary<string, object> variables) : this()
851
856
#region Main evaluate methods (Expressions and scripts ==> public)
852
857
853
858
private bool inScript = false ;
854
- private string optionNumberParsingThousandSeparator ;
855
859
856
860
/// <summary>
857
861
/// Evaluate a script (multiple expressions separated by semicolon)
@@ -1653,7 +1657,6 @@ void Init(object element, List<string> initArgs)
1653
1657
i += initInNewBeginningMatch . Length ;
1654
1658
1655
1659
List < string > arrayElements = GetExpressionsBetweenParenthesesOrOtherImbricableBrackets ( expr , ref i , true , OptionInitializersSeparator , "{" , "}" ) ;
1656
- i ++ ;
1657
1660
1658
1661
if ( array == null )
1659
1662
array = Array . CreateInstance ( type , arrayElements . Count ) ;
@@ -2790,13 +2793,13 @@ private List<string> GetExpressionsBetweenParenthesesOrOtherImbricableBrackets(s
2790
2793
Match internalStringMatch = stringBeginningRegex . Match ( subExpr ) ;
2791
2794
Match internalCharMatch = internalCharRegex . Match ( subExpr ) ;
2792
2795
2793
- if ( internalStringMatch . Success )
2796
+ if ( OptionStringEvaluationActive && internalStringMatch . Success )
2794
2797
{
2795
2798
string innerString = internalStringMatch . Value + GetCodeUntilEndOfString ( expr . Substring ( i + internalStringMatch . Length ) , internalStringMatch ) ;
2796
2799
currentExpression += innerString ;
2797
2800
i += innerString . Length - 1 ;
2798
2801
}
2799
- else if ( internalCharMatch . Success )
2802
+ else if ( OptionCharEvaluationActive && internalCharMatch . Success )
2800
2803
{
2801
2804
currentExpression += internalCharMatch . Value ;
2802
2805
i += internalCharMatch . Length - 1 ;
0 commit comments