Tuple<string, List<string>> SplitCommandArgs(string command)
{
string com = command.Split(" ".ToArray(),
StringSplitOptions.RemoveEmptyEntries).First<string>();
com = com.Replace(MPDKeyWords.Response.LINEBREAK, "");
List<string> arguments = new List<string>();
if (!string.IsNullOrEmpty(com))
{
string tempsarg = string.Empty;
bool appro = false;
foreach (char c in command.Replace(com, "").ToCharArray())
{
if (c.Equals('"') && !appro) appro = true;
else if (c.Equals('"') && appro)
{
appro = false;
if (!string.IsNullOrEmpty(tempsarg) || !string.IsNullOrWhiteSpace(tempsarg)) arguments.Add(tempsarg);
tempsarg = string.Empty;
}
else if (c.Equals(' ') && !appro)
{
if (!string.IsNullOrEmpty(tempsarg) || !string.IsNullOrWhiteSpace(tempsarg)) arguments.Add(tempsarg);
tempsarg = string.Empty;
}
else if (!c.Equals('\n')) tempsarg += c;
else
{
if(!string.IsNullOrEmpty(tempsarg) || !string.IsNullOrWhiteSpace(tempsarg)) arguments.Add(tempsarg);
}
}
if (!string.IsNullOrEmpty(tempsarg) || !string.IsNullOrWhiteSpace(tempsarg)) arguments.Add(tempsarg);
}
return new Tuple<string,List<string>>(com, arguments);
}