diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-04-25 12:16:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-25 12:16:44 -0400 |
commit | 68206e00478905960e2a1f37f974f088f56b5390 (patch) | |
tree | b73f363567dc9baa93fd1a822c42455c7547ca6c /src/SMAPI | |
parent | cd3dbc47aa6e112d8695bcb9ed81f0b422f21e5c (diff) | |
parent | f95c7f25f4447fd1a34400a273256b1e5b4df7b1 (diff) | |
download | SMAPI-68206e00478905960e2a1f37f974f088f56b5390.tar.gz SMAPI-68206e00478905960e2a1f37f974f088f56b5390.tar.bz2 SMAPI-68206e00478905960e2a1f37f974f088f56b5390.zip |
Merge pull request #474 from danvolchek/develop
Add overload to the player_add console command to add items by name
Diffstat (limited to 'src/SMAPI')
-rw-r--r-- | src/SMAPI/Framework/CommandManager.cs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/SMAPI/Framework/CommandManager.cs b/src/SMAPI/Framework/CommandManager.cs index 79a23d03..0c48d8ec 100644 --- a/src/SMAPI/Framework/CommandManager.cs +++ b/src/SMAPI/Framework/CommandManager.cs @@ -72,7 +72,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 +103,35 @@ namespace StardewModdingAPI.Framework /********* ** Private methods *********/ + /// <summary> + /// Parses a string into an array of arguments. + /// </summary> + /// <param name="input">The string to parse.</param> + private string[] ParseArgs(string input) + { + bool inQuotes = false; + IList<string> args = new List<string>(); + IList<char> currentArg = new List<char>(); + foreach (char c in input) + { + if (c == '"') + { + inQuotes = !inQuotes; + } + else if (!inQuotes && char.IsWhiteSpace(c)) + { + args.Add(string.Concat(currentArg)); + currentArg.Clear(); + } + else + currentArg.Add(c); + } + + args.Add(string.Concat(currentArg)); + + 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) |