Moving examples, mapgenerator, and VisualParamGenerator to Programs folder (SVN is seriously ruined still, don't check out yet)

git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@1961 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
John Hurliman
2008-07-22 23:21:49 +00:00
parent ef71c02528
commit f2dde3daae
153 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenMetaverse.TestClient
{
class Parsing
{
public static string[] ParseArguments(string str)
{
List<string> list = new List<string>();
string current = String.Empty;
string trimmed = null;
bool withinQuote = false;
bool escaped = false;
foreach (char c in str)
{
if (c == '"')
{
if (escaped)
{
current += '"';
escaped = false;
}
else
{
current += '"';
withinQuote = !withinQuote;
}
}
else if (c == ' ' || c == '\t')
{
if (escaped || withinQuote)
{
current += c;
escaped = false;
}
else
{
trimmed = current.Trim();
if (trimmed.StartsWith("\"") && trimmed.EndsWith("\""))
{
trimmed = trimmed.Remove(0, 1);
trimmed = trimmed.Remove(trimmed.Length - 1);
trimmed = trimmed.Trim();
}
if (trimmed.Length > 0)
list.Add(trimmed);
current = String.Empty;
}
}
else if (c == '\\')
{
if (escaped)
{
current += '\\';
escaped = false;
}
else
{
escaped = true;
}
}
else
{
if (escaped)
throw new FormatException(c.ToString() + " is not an escapable character.");
current += c;
}
}
trimmed = current.Trim();
if (trimmed.StartsWith("\"") && trimmed.EndsWith("\""))
{
trimmed = trimmed.Remove(0, 1);
trimmed = trimmed.Remove(trimmed.Length - 1);
trimmed = trimmed.Trim();
}
if (trimmed.Length > 0)
list.Add(trimmed);
return list.ToArray();
}
}
}