@@ -20,7 +20,6 @@ class MathVisitor : AbstractParseTreeVisitor<Operand>, ImathVisitor<Operand>
2020 private static readonly Regex bit_8 = new Regex ( "^[0-8]+$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
2121 private static readonly Regex bit_16 = new Regex ( "^[0-9a-f]+$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
2222 private static readonly Regex clearRegex = new Regex ( @"[\f\n\r\t\v]" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
23- private static readonly CultureInfo cultureInfo = CultureInfo . InvariantCulture ; // CultureInfo.GetCultureInfo("zh-cn");
2423 public event Func < string , Operand > GetParameter ;
2524 public event Func < string , List < Operand > , Operand > DiyFunction ;
2625 public int excelIndex ;
@@ -44,26 +43,26 @@ public virtual Operand VisitMulDiv_fun(mathParser.MulDiv_funContext context)
4443 var args2 = exprs [ 1 ] . Accept ( this ) ; if ( args2 . IsError ) { return args2 ; }
4544
4645 if ( args1 . Type == OperandType . TEXT ) {
47- if ( decimal . TryParse ( args1 . TextValue , NumberStyles . Any , cultureInfo , out decimal d ) ) {
46+ if ( decimal . TryParse ( args1 . TextValue , NumberStyles . Any , CultureInfo . InvariantCulture , out decimal d ) ) {
4847 args1 = Operand . Create ( d ) ;
4948 } else if ( bool . TryParse ( args1 . TextValue , out bool b ) ) {
5049 args1 = b ? Operand . One : Operand . Zero ;
51- } else if ( TimeSpan . TryParse ( args1 . TextValue , cultureInfo , out TimeSpan ts ) ) {
50+ } else if ( TimeSpan . TryParse ( args1 . TextValue , CultureInfo . InvariantCulture , out TimeSpan ts ) ) {
5251 args1 = Operand . Create ( ts ) ;
53- } else if ( DateTime . TryParse ( args1 . TextValue , cultureInfo , DateTimeStyles . None , out DateTime dt ) ) {
52+ } else if ( DateTime . TryParse ( args1 . TextValue , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateTime dt ) ) {
5453 args1 = Operand . Create ( new MyDate ( dt ) ) ;
5554 } else {
5655 return Operand . Error ( "Two types cannot be multiplied or divided." ) ;
5756 }
5857 }
5958 if ( args2 . Type == OperandType . TEXT ) {
60- if ( decimal . TryParse ( args2 . TextValue , NumberStyles . Any , cultureInfo , out decimal d ) ) {
59+ if ( decimal . TryParse ( args2 . TextValue , NumberStyles . Any , CultureInfo . InvariantCulture , out decimal d ) ) {
6160 args2 = Operand . Create ( d ) ;
6261 } else if ( bool . TryParse ( args2 . TextValue , out bool b ) ) {
6362 args2 = b ? Operand . One : Operand . Zero ;
64- } else if ( TimeSpan . TryParse ( args2 . TextValue , cultureInfo , out TimeSpan ts ) ) {
63+ } else if ( TimeSpan . TryParse ( args2 . TextValue , CultureInfo . InvariantCulture , out TimeSpan ts ) ) {
6564 args2 = Operand . Create ( ts ) ;
66- } else if ( DateTime . TryParse ( args2 . TextValue , cultureInfo , DateTimeStyles . None , out DateTime dt ) ) {
65+ } else if ( DateTime . TryParse ( args2 . TextValue , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateTime dt ) ) {
6766 args2 = Operand . Create ( new MyDate ( dt ) ) ;
6867 } else {
6968 return Operand . Error ( "Two types cannot be multiplied or divided." ) ;
@@ -125,26 +124,26 @@ public virtual Operand VisitAddSub_fun(mathParser.AddSub_funContext context)
125124 return Operand . Create ( args1 . TextValue + args2 . TextValue ) ;
126125 }
127126 if ( args1 . Type == OperandType . TEXT ) {
128- if ( decimal . TryParse ( args1 . TextValue , NumberStyles . Any , cultureInfo , out decimal d ) ) {
127+ if ( decimal . TryParse ( args1 . TextValue , NumberStyles . Any , CultureInfo . InvariantCulture , out decimal d ) ) {
129128 args1 = Operand . Create ( d ) ;
130129 } else if ( bool . TryParse ( args1 . TextValue , out bool b ) ) {
131130 args1 = b ? Operand . One : Operand . Zero ;
132- } else if ( TimeSpan . TryParse ( args1 . TextValue , cultureInfo , out TimeSpan ts ) ) {
131+ } else if ( TimeSpan . TryParse ( args1 . TextValue , CultureInfo . InvariantCulture , out TimeSpan ts ) ) {
133132 args1 = Operand . Create ( ts ) ;
134- } else if ( DateTime . TryParse ( args1 . TextValue , cultureInfo , DateTimeStyles . None , out DateTime dt ) ) {
133+ } else if ( DateTime . TryParse ( args1 . TextValue , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateTime dt ) ) {
135134 args1 = Operand . Create ( new MyDate ( dt ) ) ;
136135 } else {
137136 return Operand . Error ( "Function '+' or '-' is error" ) ;
138137 }
139138 }
140139 if ( args2 . Type == OperandType . TEXT ) {
141- if ( decimal . TryParse ( args2 . TextValue , NumberStyles . Any , cultureInfo , out decimal d ) ) {
140+ if ( decimal . TryParse ( args2 . TextValue , NumberStyles . Any , CultureInfo . InvariantCulture , out decimal d ) ) {
142141 args2 = Operand . Create ( d ) ;
143142 } else if ( bool . TryParse ( args2 . TextValue , out bool b ) ) {
144143 args2 = b ? Operand . One : Operand . Zero ;
145- } else if ( TimeSpan . TryParse ( args2 . TextValue , cultureInfo , out TimeSpan ts ) ) {
144+ } else if ( TimeSpan . TryParse ( args2 . TextValue , CultureInfo . InvariantCulture , out TimeSpan ts ) ) {
146145 args2 = Operand . Create ( ts ) ;
147- } else if ( DateTime . TryParse ( args2 . TextValue , cultureInfo , DateTimeStyles . None , out DateTime dt ) ) {
146+ } else if ( DateTime . TryParse ( args2 . TextValue , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateTime dt ) ) {
148147 args2 = Operand . Create ( new MyDate ( dt ) ) ;
149148 } else {
150149 return Operand . Error ( "Function '+' or '-' is error" ) ;
@@ -826,9 +825,9 @@ public virtual Operand VisitFIXED_fun(mathParser.FIXED_funContext context)
826825 no = thirdValue . BooleanValue ;
827826 }
828827 if ( no == false ) {
829- return Operand . Create ( s . ToString ( 'N' + num . ToString ( ) , cultureInfo ) ) ;
828+ return Operand . Create ( s . ToString ( 'N' + num . ToString ( ) , CultureInfo . InvariantCulture ) ) ;
830829 }
831- return Operand . Create ( s . ToString ( cultureInfo ) ) ;
830+ return Operand . Create ( s . ToString ( CultureInfo . InvariantCulture ) ) ;
832831 }
833832
834833 #endregion
@@ -1666,7 +1665,7 @@ public virtual Operand VisitTEXT_fun(mathParser.TEXT_funContext context)
16661665 } else if ( firstValue . Type == OperandType . BOOLEAN ) {
16671666 return Operand . Create ( firstValue . BooleanValue ? "TRUE" : "FALSE" ) ;
16681667 } else if ( firstValue . Type == OperandType . NUMBER ) {
1669- return Operand . Create ( firstValue . NumberValue . ToString ( secondValue . TextValue , cultureInfo ) ) ;
1668+ return Operand . Create ( firstValue . NumberValue . ToString ( secondValue . TextValue , CultureInfo . InvariantCulture ) ) ;
16701669 } else if ( firstValue . Type == OperandType . DATE ) {
16711670 return Operand . Create ( firstValue . DateValue . ToString ( secondValue . TextValue ) ) ;
16721671 }
@@ -1691,7 +1690,7 @@ public virtual Operand VisitVALUE_fun(mathParser.VALUE_funContext context)
16911690 var firstValue = context . expr ( ) . Accept ( this ) . ToText ( "Function VALUE parameter is error!" ) ;
16921691 if ( firstValue . IsError ) { return firstValue ; }
16931692
1694- if ( decimal . TryParse ( firstValue . TextValue , NumberStyles . Any , cultureInfo , out decimal d ) ) {
1693+ if ( decimal . TryParse ( firstValue . TextValue , NumberStyles . Any , CultureInfo . InvariantCulture , out decimal d ) ) {
16951694 return Operand . Create ( d ) ;
16961695 }
16971696 return Operand . Error ( "Function VALUE parameter is error!" ) ;
@@ -1726,7 +1725,7 @@ private static String F_base_ToDBC(String input)
17261725 }
17271726 private static string F_base_ToChineseRMB ( decimal x )
17281727 {
1729- string s = x . ToString ( "#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A" , cultureInfo ) ;
1728+ string s = x . ToString ( "#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A" , CultureInfo . InvariantCulture ) ;
17301729 string d = Regex . Replace ( s , @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\.]|$))))" , "${b}${z}" , RegexOptions . Compiled ) ;
17311730 return Regex . Replace ( d , "." , m => "负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟万亿兆京垓秭穰" [ m . Value [ 0 ] - '-' ] . ToString ( ) , RegexOptions . Compiled ) ;
17321731 }
@@ -1747,7 +1746,7 @@ public virtual Operand VisitDATEVALUE_fun(mathParser.DATEVALUE_funContext contex
17471746 }
17481747 if ( type == 0 ) {
17491748 if ( args [ 0 ] . Type == OperandType . TEXT ) {
1750- if ( DateTime . TryParse ( args [ 0 ] . TextValue , cultureInfo , DateTimeStyles . None , out DateTime time ) ) {
1749+ if ( DateTime . TryParse ( args [ 0 ] . TextValue , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateTime time ) ) {
17511750 return Operand . Create ( time ) ;
17521751 }
17531752 }
@@ -1767,7 +1766,7 @@ public virtual Operand VisitDATEVALUE_fun(mathParser.DATEVALUE_funContext contex
17671766 } else if ( type == 1 ) {
17681767 var firstValue = args [ 0 ] . ToText ( "Function DATEVALUE parameter 1 is error!" ) ;
17691768 if ( firstValue . IsError ) { return firstValue ; }
1770- if ( DateTime . TryParse ( firstValue . TextValue , cultureInfo , DateTimeStyles . None , out DateTime dt ) ) {
1769+ if ( DateTime . TryParse ( firstValue . TextValue , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateTime dt ) ) {
17711770 return Operand . Create ( dt ) ;
17721771 }
17731772 } else if ( type == 2 ) {
@@ -1815,7 +1814,7 @@ public virtual Operand VisitTIMEVALUE_fun(mathParser.TIMEVALUE_funContext contex
18151814 var firstValue = context . expr ( ) . Accept ( this ) . ToText ( "Function TIMEVALUE parameter is error!" ) ;
18161815 if ( firstValue . IsError ) { return firstValue ; }
18171816
1818- if ( TimeSpan . TryParse ( firstValue . TextValue , cultureInfo , out TimeSpan dt ) ) {
1817+ if ( TimeSpan . TryParse ( firstValue . TextValue , CultureInfo . InvariantCulture , out TimeSpan dt ) ) {
18191818 return Operand . Create ( dt ) ;
18201819 }
18211820 return Operand . Error ( "Function TIMEVALUE parameter is error!" ) ;
@@ -2449,7 +2448,7 @@ public virtual Operand VisitAVERAGEIF_fun(mathParser.AVERAGEIF_funContext contex
24492448 count = MathVisitor . F_base_countif ( list , args [ 1 ] . NumberValue ) ;
24502449 sum = count * args [ 1 ] . NumberValue ;
24512450 } else {
2452- if ( decimal . TryParse ( args [ 1 ] . TextValue . Trim ( ) , NumberStyles . Any , cultureInfo , out decimal d ) ) {
2451+ if ( decimal . TryParse ( args [ 1 ] . TextValue . Trim ( ) , NumberStyles . Any , CultureInfo . InvariantCulture , out decimal d ) ) {
24532452 count = MathVisitor . F_base_countif ( list , d ) ;
24542453 sum = MathVisitor . F_base_sumif ( list , '=' + args [ 1 ] . TextValue . Trim ( ) , sumdbs ) ;
24552454 } else {
@@ -2525,7 +2524,7 @@ public virtual Operand VisitCOUNTIF_fun(mathParser.COUNTIF_funContext context)
25252524 if ( args [ 1 ] . Type == OperandType . NUMBER ) {
25262525 count = MathVisitor . F_base_countif ( list , args [ 1 ] . NumberValue ) ;
25272526 } else {
2528- if ( decimal . TryParse ( args [ 1 ] . TextValue . Trim ( ) , NumberStyles . Any , cultureInfo , out decimal d ) ) {
2527+ if ( decimal . TryParse ( args [ 1 ] . TextValue . Trim ( ) , NumberStyles . Any , CultureInfo . InvariantCulture , out decimal d ) ) {
25292528 count = MathVisitor . F_base_countif ( list , d ) ;
25302529 } else {
25312530 var sunif = args [ 1 ] . TextValue . Trim ( ) ;
@@ -2574,7 +2573,7 @@ public virtual Operand VisitSUMIF_fun(mathParser.SUMIF_funContext context)
25742573 if ( args [ 1 ] . Type == OperandType . NUMBER ) {
25752574 sum = MathVisitor . F_base_countif ( list , args [ 1 ] . NumberValue ) * args [ 1 ] . NumberValue ;
25762575 } else {
2577- if ( decimal . TryParse ( args [ 1 ] . TextValue . Trim ( ) , NumberStyles . Any , cultureInfo , out _ ) ) {
2576+ if ( decimal . TryParse ( args [ 1 ] . TextValue . Trim ( ) , NumberStyles . Any , CultureInfo . InvariantCulture , out _ ) ) {
25782577 sum = MathVisitor . F_base_sumif ( list , '=' + args [ 1 ] . TextValue . Trim ( ) , sumdbs ) ;
25792578 } else {
25802579 var sunif = args [ 1 ] . TextValue . Trim ( ) ;
@@ -3033,7 +3032,7 @@ private static int F_base_countif(List<decimal> dbs, decimal d)
30333032 private static int F_base_countif ( List < decimal > dbs , string s )
30343033 {
30353034 var m = sumifRegex . Match ( s ) ;
3036- var d = decimal . Parse ( m . Groups [ 2 ] . Value , NumberStyles . Any , cultureInfo ) ;
3035+ var d = decimal . Parse ( m . Groups [ 2 ] . Value , NumberStyles . Any , CultureInfo . InvariantCulture ) ;
30373036 var ss = m . Groups [ 1 ] . Value ;
30383037 int count = 0 ;
30393038
@@ -3048,7 +3047,7 @@ private static int F_base_countif(List<decimal> dbs, string s)
30483047 private static decimal F_base_sumif ( List < decimal > dbs , string s , List < decimal > sumdbs )
30493048 {
30503049 var m = sumifRegex . Match ( s ) ;
3051- var d = decimal . Parse ( m . Groups [ 2 ] . Value , NumberStyles . Any , cultureInfo ) ;
3050+ var d = decimal . Parse ( m . Groups [ 2 ] . Value , NumberStyles . Any , CultureInfo . InvariantCulture ) ;
30523051 var ss = m . Groups [ 1 ] . Value ;
30533052 decimal sum = 0 ;
30543053
@@ -3853,7 +3852,7 @@ public virtual Operand VisitBracket_fun(mathParser.Bracket_funContext context)
38533852
38543853 public virtual Operand VisitNUM_fun ( mathParser . NUM_funContext context )
38553854 {
3856- var d = decimal . Parse ( context . num ( ) . GetText ( ) , NumberStyles . Any , cultureInfo ) ;
3855+ var d = decimal . Parse ( context . num ( ) . GetText ( ) , NumberStyles . Any , CultureInfo . InvariantCulture ) ;
38573856 if ( context . unit ( ) == null ) { return Operand . Create ( d ) ; }
38583857
38593858 var unit = context . unit ( ) . GetText ( ) ;
@@ -3863,7 +3862,7 @@ public virtual Operand VisitNUM_fun(mathParser.NUM_funContext context)
38633862 }
38643863 public Operand VisitNum ( mathParser . NumContext context )
38653864 {
3866- var d = decimal . Parse ( context . GetText ( ) , NumberStyles . Any , cultureInfo ) ;
3865+ var d = decimal . Parse ( context . GetText ( ) , NumberStyles . Any , CultureInfo . InvariantCulture ) ;
38673866 return Operand . Create ( d ) ;
38683867 }
38693868 public Operand VisitUnit ( mathParser . UnitContext context )
0 commit comments