Skip to content

Commit ddc2c3a

Browse files
author
linzhijun
committed
fix
1 parent a47c7a8 commit ddc2c3a

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

csharp/ToolGood.Algorithm/Internals/Functions/String/Function_REPLACE.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Text;
44
using ToolGood.Algorithm.Enums;
@@ -26,6 +26,9 @@ public override Operand Evaluate(AlgorithmEngine engine, Func<AlgorithmEngine, s
2626

2727
var old = args22.TextValue;
2828
var newstr = args32.TextValue;
29+
if(old.Length == 0 || oldtext.IndexOf(old, StringComparison.Ordinal) < 0) {
30+
return args1;
31+
}
2932
return Operand.Create(oldtext.Replace(old, newstr));
3033
}
3134

csharp/ToolGood.Algorithm/Internals/Functions/String/Function_REPT.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ public override Operand Evaluate(AlgorithmEngine engine, Func<AlgorithmEngine, s
2828
if (length == 0) {
2929
return Operand.Create(string.Empty);
3030
}
31-
if (newtext.Length > 0 && length > 32767 / newtext.Length) {
31+
if (newtext.Length == 0) {
32+
return args1;
33+
}
34+
if (length > 32767 / newtext.Length) {
3235
return ParameterError(2);
3336
}
37+
if (length == 1) {
38+
return args1;
39+
}
3440
var sb = new StringBuilder(newtext.Length * length);
35-
for (int i = 0; i < length; i++) {
41+
for(int i = 0; i < length; i++) {
3642
sb.Append(newtext);
3743
}
3844
return Operand.Create(sb.ToString());

csharp/ToolGood.Algorithm/Internals/Functions/String/Function_TRIM.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Text.RegularExpressions;
44
using ToolGood.Algorithm.Enums;
@@ -21,6 +21,9 @@ public override Operand Evaluate(AlgorithmEngine engine, Func<AlgorithmEngine, s
2121
if (args1.IsErrorOrNone) { return args1; }
2222
var text = args1.TextValue.Trim();
2323
text = s_multipleSpaces.Replace(text, " ");
24+
if(text.Equals(args1.TextValue)) {
25+
return args1;
26+
}
2427
return Operand.Create(text);
2528
}
2629
public override OperandType GetResultType()

0 commit comments

Comments
 (0)