Skip to content

Commit 18b355f

Browse files
committed
fix: argument parser not work case #1
1 parent b8ea56e commit 18b355f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Flucli/Utils/Extensions/ArgumentExtension.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Security;
4+
using System.Text;
45

56
namespace Flucli.Utils.Extensions;
67

@@ -9,7 +10,7 @@ public static class ArgumentExtension
910
public static IEnumerable<string> ToArguments(this string cli)
1011
{
1112
List<string> args = [];
12-
string currentArg = string.Empty;
13+
StringBuilder currentArg = new();
1314
bool inQuotes = false;
1415

1516
for (int i = 0; i < cli.Length; i++)
@@ -19,24 +20,25 @@ public static IEnumerable<string> ToArguments(this string cli)
1920
if (c == '"')
2021
{
2122
inQuotes = !inQuotes;
23+
currentArg.Append(c);
2224
}
2325
else if (c == ' ' && !inQuotes)
2426
{
25-
if (currentArg != string.Empty)
27+
if (currentArg.Length > 0)
2628
{
27-
args.Add(currentArg);
28-
currentArg = string.Empty;
29+
args.Add(currentArg.ToString());
30+
currentArg.Clear();
2931
}
3032
}
3133
else
3234
{
33-
currentArg += c;
35+
currentArg.Append(c);
3436
}
3537
}
3638

37-
if (currentArg != string.Empty)
39+
if (currentArg.Length > 0)
3840
{
39-
args.Add(currentArg);
41+
args.Add(currentArg.ToString());
4042
}
4143

4244
return args;

0 commit comments

Comments
 (0)