Skip to content

Commit 307be21

Browse files
author
linzhijun
committed
fix
1 parent 07ad523 commit 307be21

File tree

8 files changed

+133
-53
lines changed

8 files changed

+133
-53
lines changed

csharp/ToolGood.Algorithm.Test/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Antlr4.Runtime.Misc;
2+
using System;
23
using System.Globalization;
34
using System.Text;
45
using System.Threading;
@@ -10,8 +11,9 @@ internal class Program
1011
{
1112
private static void Main(string[] args)
1213
{
14+
var t222 = Convert.ToString(122223, 16);
1315
AlgorithmEngine engine = new AlgorithmEngine();
14-
16+
1517
var b = engine.TryEvaluate("1=1 && 1<2 and 7-8>1", 0);// Support(支持) && || and or
1618
var c = engine.TryEvaluate("2+3", 0);
1719
var d = engine.TryEvaluate("count(array(1,2,3,4))", 0);//{} represents array, return: 4 {}代表数组,返回:4

csharp/ToolGood.Algorithm/Internals/ConditionTree.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class ConditionTree
1313
/// <summary>
1414
/// 子节点
1515
/// </summary>
16-
public IList<ConditionTree> Nodes { get; internal set; }
16+
public List<ConditionTree> Nodes { get; internal set; }
1717

1818
/// <summary>
1919
/// 开始位置

csharp/ToolGood.Algorithm/Internals/Functions/FunctionBase.math.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
611611
{
612612
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter {1} is error!", "BIN2OCT", 1); if (args1.IsError) { return args1; } }
613613

614-
if (FunctionUtil.BinRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "BIN2OCT", 1); }
614+
if (RegexHelper.BinRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "BIN2OCT", 1); }
615615
var num = Convert.ToString(Convert.ToInt32(args1.TextValue, 2), 8);
616616
if (func2 != null) {
617617
var args2 = func2.Evaluate(work, tempParameter); if (args2.IsNotNumber) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "BIN2OCT", 2); if (args2.IsError) { return args2; } }
@@ -638,7 +638,7 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
638638
{
639639
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter is error!", "BIN2DEC"); if (args1.IsError) { return args1; } }
640640

641-
if (FunctionUtil.BinRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter is error!", "BIN2DEC"); }
641+
if (RegexHelper.BinRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter is error!", "BIN2DEC"); }
642642
var num = Convert.ToInt32(args1.TextValue, 2);
643643
return Operand.Create(num);
644644
}
@@ -658,7 +658,7 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
658658
{
659659
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter {1} is error!", "BIN2HEX", 1); if (args1.IsError) { return args1; } }
660660

661-
if (FunctionUtil.BinRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "BIN2HEX", 1); }
661+
if (RegexHelper.BinRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "BIN2HEX", 1); }
662662
var num = Convert.ToString(Convert.ToInt32(args1.TextValue, 2), 16).ToUpper();
663663
if (func2 != null) {
664664
var args2 = func2.Evaluate(work, tempParameter); if (args2.IsNotNumber) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "BIN2HEX", 2); if (args2.IsError) { return args2; } }
@@ -685,7 +685,7 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
685685
{
686686
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter {1} is error!", "OCT2BIN", 1); if (args1.IsError) { return args1; } }
687687

688-
if (FunctionUtil.OctRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "OCT2BIN", 1); }
688+
if (RegexHelper.OctRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "OCT2BIN", 1); }
689689
var num = Convert.ToString(Convert.ToInt32(args1.TextValue, 8), 2);
690690
if (func2 != null) {
691691
var args2 = func2.Evaluate(work, tempParameter); if (args2.IsNotNumber) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "OCT2BIN", 2); if (args2.IsError) { return args2; } }
@@ -712,7 +712,7 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
712712
{
713713
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter is error!", "OCT2DEC"); if (args1.IsError) { return args1; } }
714714

715-
if (FunctionUtil.OctRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter is error!", "OCT2DEC"); }
715+
if (RegexHelper.OctRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter is error!", "OCT2DEC"); }
716716
var num = Convert.ToInt32(args1.TextValue, 8);
717717
return Operand.Create(num);
718718
}
@@ -732,7 +732,7 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
732732
{
733733
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter {1} is error!", "OCT2HEX", 1); if (args1.IsError) { return args1; } }
734734

735-
if (FunctionUtil.OctRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "OCT2HEX", 1); }
735+
if (RegexHelper.OctRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "OCT2HEX", 1); }
736736
var num = Convert.ToString(Convert.ToInt32(args1.TextValue, 8), 16).ToUpper();
737737
if (func2 != null) {
738738
var args2 = func2.Evaluate(work, tempParameter); if (args2.IsNotNumber) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "OCT2HEX", 2); if (args2.IsError) { return args2; } }
@@ -759,7 +759,7 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
759759
{
760760
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter {1} is error!", "HEX2BIN", 1); if (args1.IsError) { return args1; } }
761761

762-
if (FunctionUtil.HexRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "HEX2BIN", 1); }
762+
if (RegexHelper.HexRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "HEX2BIN", 1); }
763763
var num = Convert.ToString(Convert.ToInt32(args1.TextValue, 16), 2);
764764
if (func2 != null) {
765765
var args2 = func2.Evaluate(work, tempParameter); if (args2.IsNotNumber) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "HEX2BIN", 2); if (args2.IsError) { return args2; } }
@@ -786,7 +786,7 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
786786
{
787787
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter is error!", "HEX2DEC"); if (args1.IsError) { return args1; } }
788788

789-
if (FunctionUtil.HexRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter is error!", "HEX2DEC"); }
789+
if (RegexHelper.HexRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter is error!", "HEX2DEC"); }
790790
var num = Convert.ToInt32(args1.TextValue, 16);
791791
return Operand.Create(num);
792792
}
@@ -805,7 +805,7 @@ public Function_HEX2OCT(FunctionBase func1, FunctionBase func2) : base(func1, fu
805805
public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tempParameter)
806806
{
807807
var args1 = func1.Evaluate(work, tempParameter); if (args1.IsNotText) { args1 = args1.ToText("Function '{0}' parameter {1} is error!", "HEX2OCT", 1); if (args1.IsError) { return args1; } }
808-
if (FunctionUtil.HexRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "HEX2OCT", 1); }
808+
if (RegexHelper.HexRegex.IsMatch(args1.TextValue) == false) { return Operand.Error("Function '{0}' parameter {1} is error!", "HEX2OCT", 1); }
809809
var num = Convert.ToString(Convert.ToInt32(args1.TextValue, 16), 8);
810810
if (func2 != null) {
811811
var args2 = func2.Evaluate(work, tempParameter); if (args2.IsNotNumber) { args2 = args2.ToNumber("Function '{0}' parameter {1} is error!", "HEX2OCT", 2); if (args2.IsError) { return args2; } }

csharp/ToolGood.Algorithm/Internals/Functions/FunctionBase.string.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ public override Operand Evaluate(AlgorithmEngine work, Func<string, Operand> tem
414414
private static string F_base_ToChineseRMB(decimal x)
415415
{
416416
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);
417-
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);
418-
return Regex.Replace(d, ".", m => "负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟万亿兆京垓秭穰"[m.Value[0] - '-'].ToString(), RegexOptions.Compiled);
417+
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}");
418+
return Regex.Replace(d, ".", m => "负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟万亿兆京垓秭穰"[m.Value[0] - '-'].ToString());
419419
}
420420
public override void ToString(StringBuilder stringBuilder, bool addBrackets)
421421
{

csharp/ToolGood.Algorithm/Internals/Functions/FunctionUtil.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@ namespace ToolGood.Algorithm.Internals.Functions
88
{
99
internal class FunctionUtil
1010
{
11-
/// <summary>
12-
/// new Regex("^[0-9A-Fa-f]+$", RegexOptions.Compiled);
13-
/// </summary>
14-
public static Regex HexRegex = new Regex("^[0-9A-Fa-f]+$", RegexOptions.Compiled);
15-
/// <summary>
16-
/// new Regex("^[0-7]+$", RegexOptions.Compiled);
17-
/// </summary>
18-
public static Regex OctRegex = new Regex("^[0-7]+$", RegexOptions.Compiled);
19-
/// <summary>
20-
/// new Regex("^[01]+$", RegexOptions.Compiled);
21-
/// </summary>
22-
public static Regex BinRegex = new Regex("^[01]+$", RegexOptions.Compiled);
23-
24-
2511
public static bool F_base_GetList(List<Operand> args, List<decimal> list)
2612
{
2713
foreach (var item in args) {
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Text.RegularExpressions;
5+
6+
namespace ToolGood.Algorithm.Internals
7+
{
8+
internal partial class RegexHelper
9+
{
10+
#if NETSTANDARD2_1
11+
/// <summary>
12+
/// new Regex("^[0-9A-Fa-f]+$", RegexOptions.Compiled);
13+
/// </summary>
14+
public static Regex HexRegex = new Regex("^[0-9A-Fa-f]+$", RegexOptions.Compiled);
15+
/// <summary>
16+
/// new Regex("^[0-7]+$", RegexOptions.Compiled);
17+
/// </summary>
18+
public static Regex OctRegex = new Regex("^[0-7]+$", RegexOptions.Compiled);
19+
/// <summary>
20+
/// new Regex("^[01]+$", RegexOptions.Compiled);
21+
/// </summary>
22+
public static Regex BinRegex = new Regex("^[01]+$", RegexOptions.Compiled);
23+
#else
24+
/// <summary>
25+
/// new Regex("^[0-9A-Fa-f]+$", RegexOptions.Compiled);
26+
/// </summary>
27+
public static Regex HexRegex = HexRegex_();
28+
/// <summary>
29+
/// new Regex("^[0-7]+$", RegexOptions.Compiled);
30+
/// </summary>
31+
public static Regex OctRegex = OctRegex_();
32+
/// <summary>
33+
/// new Regex("^[01]+$", RegexOptions.Compiled);
34+
/// </summary>
35+
public static Regex BinRegex = BinRegex_();
36+
37+
38+
[GeneratedRegex("^[0-9A-Fa-f]+$", RegexOptions.Compiled)]
39+
private static partial Regex HexRegex_();
40+
[GeneratedRegex("^[0-7]+$", RegexOptions.Compiled)]
41+
private static partial Regex OctRegex_();
42+
[GeneratedRegex("^[01]+$", RegexOptions.Compiled)]
43+
private static partial Regex BinRegex_();
44+
#endif
45+
46+
#if NETSTANDARD2_1
47+
public static readonly Regex dateTimeRegex = new Regex("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
48+
public static readonly Regex dateTimeRegex2 = new Regex("^(\\d{4})/(1[012]|0?\\d)/(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
49+
public static readonly Regex dateTimeRegex3 = new Regex("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d)$", RegexOptions.Compiled);
50+
public static readonly Regex dateTimeRegex4 = new Regex("^(\\d{4})/(1[012]|0?\\d)/(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d)$", RegexOptions.Compiled);
51+
52+
public static readonly Regex dateRegex = new Regex("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d)$", RegexOptions.Compiled);
53+
public static readonly Regex dateRegex2 = new Regex("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d)$", RegexOptions.Compiled);
54+
55+
public static readonly Regex dayTimeRegex = new Regex("^(\\d+) (2[0123]|[01]?\\d):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
56+
public static readonly Regex dayTimeRegex2 = new Regex("^(\\d+) (2[0123]|[01]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
57+
58+
public static readonly Regex timeRegex = new Regex("^(2[0123]|[01]?\\d):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
59+
public static readonly Regex timeRegex2 = new Regex("^(2[0123]|[01]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
60+
#else
61+
public static readonly Regex dateTimeRegex = dateTimeRegex_();
62+
public static readonly Regex dateTimeRegex2 = dateTimeRegex2_();
63+
public static readonly Regex dateTimeRegex3 = dateTimeRegex3_();
64+
public static readonly Regex dateTimeRegex4 = dateTimeRegex4_();
65+
66+
public static readonly Regex dateRegex = dateRegex_();
67+
public static readonly Regex dateRegex2 = dateRegex2_();
68+
69+
public static readonly Regex dayTimeRegex = dayTimeRegex_();
70+
public static readonly Regex dayTimeRegex2 = dayTimeRegex2_();
71+
72+
public static readonly Regex timeRegex = timeRegex_();
73+
public static readonly Regex timeRegex2 = timeRegex2_();
74+
75+
[GeneratedRegex("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled)]
76+
private static partial Regex dateTimeRegex_();
77+
[GeneratedRegex("^(\\d{4})/(1[012]|0?\\d)/(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled)]
78+
private static partial Regex dateTimeRegex2_();
79+
[GeneratedRegex("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d)$", RegexOptions.Compiled)]
80+
private static partial Regex dateTimeRegex3_();
81+
[GeneratedRegex("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d)$", RegexOptions.Compiled)]
82+
private static partial Regex dateRegex_();
83+
[GeneratedRegex("^(\\d{4})/(1[012]|0?\\d)/(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d)$", RegexOptions.Compiled)]
84+
private static partial Regex dateTimeRegex4_();
85+
[GeneratedRegex("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d)$", RegexOptions.Compiled)]
86+
private static partial Regex dateRegex2_();
87+
[GeneratedRegex("^(\\d+) (2[0123]|[01]?\\d):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled)]
88+
private static partial Regex dayTimeRegex_();
89+
[GeneratedRegex("^(\\d+) (2[0123]|[01]?\\d):([012345]?\\d)$", RegexOptions.Compiled)]
90+
private static partial Regex dayTimeRegex2_();
91+
[GeneratedRegex("^(2[0123]|[01]?\\d):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled)]
92+
private static partial Regex timeRegex_();
93+
[GeneratedRegex("^(2[0123]|[01]?\\d):([012345]?\\d)$", RegexOptions.Compiled)]
94+
private static partial Regex timeRegex2_();
95+
96+
#endif
97+
98+
99+
100+
101+
102+
103+
}
104+
}

0 commit comments

Comments
 (0)