summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/CommandManager.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-08-01 11:07:29 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-08-01 11:07:29 -0400
commit60b41195778af33fd609eab66d9ae3f1d1165e8f (patch)
tree7128b906d40e94c56c34ed6058f27bc31c31a08b /src/SMAPI/Framework/CommandManager.cs
parentb9bc1a6d17cafa0a97b46ffecda432cfc2f23b51 (diff)
parent52cf953f685c65b2b6814e375ec9a5ffa03c440a (diff)
downloadSMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.tar.gz
SMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.tar.bz2
SMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/CommandManager.cs')
-rw-r--r--src/SMAPI/Framework/CommandManager.cs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/SMAPI/Framework/CommandManager.cs b/src/SMAPI/Framework/CommandManager.cs
index 79a23d03..f9651ed9 100644
--- a/src/SMAPI/Framework/CommandManager.cs
+++ b/src/SMAPI/Framework/CommandManager.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text;
namespace StardewModdingAPI.Framework
{
@@ -72,7 +73,7 @@ namespace StardewModdingAPI.Framework
if (string.IsNullOrWhiteSpace(input))
return false;
- string[] args = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] args = this.ParseArgs(input);
string name = args[0];
args = args.Skip(1).ToArray();
@@ -103,6 +104,31 @@ namespace StardewModdingAPI.Framework
/*********
** Private methods
*********/
+ /// <summary>Parse a string into command arguments.</summary>
+ /// <param name="input">The string to parse.</param>
+ private string[] ParseArgs(string input)
+ {
+ bool inQuotes = false;
+ IList<string> args = new List<string>();
+ StringBuilder currentArg = new StringBuilder();
+ foreach (char ch in input)
+ {
+ if (ch == '"')
+ inQuotes = !inQuotes;
+ else if (!inQuotes && char.IsWhiteSpace(ch))
+ {
+ args.Add(currentArg.ToString());
+ currentArg.Clear();
+ }
+ else
+ currentArg.Append(ch);
+ }
+
+ args.Add(currentArg.ToString());
+
+ return args.Where(item => !string.IsNullOrWhiteSpace(item)).ToArray();
+ }
+
/// <summary>Get a normalised command name.</summary>
/// <param name="name">The command name.</param>
private string GetNormalisedName(string name)