diff options
author | gareth | 2007-05-08 00:10:04 +0000 |
---|---|---|
committer | gareth | 2007-05-08 00:10:04 +0000 |
commit | 5b6afeafbc249ba88dcc20d1fbc98ce12418b21b (patch) | |
tree | 78861e5f6ae871d63c83b4ab1cc4c55ea184ed6d /ExportBot/Parsing.cs | |
parent | ZOMG! (diff) | |
download | opensim-SC-5b6afeafbc249ba88dcc20d1fbc98ce12418b21b.zip opensim-SC-5b6afeafbc249ba88dcc20d1fbc98ce12418b21b.tar.gz opensim-SC-5b6afeafbc249ba88dcc20d1fbc98ce12418b21b.tar.bz2 opensim-SC-5b6afeafbc249ba88dcc20d1fbc98ce12418b21b.tar.xz |
Brought in TestClient code for teh fork
Diffstat (limited to '')
-rw-r--r-- | ExportBot/Parsing.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ExportBot/Parsing.cs b/ExportBot/Parsing.cs new file mode 100644 index 0000000..1e081c1 --- /dev/null +++ b/ExportBot/Parsing.cs | |||
@@ -0,0 +1,61 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace libsecondlife.TestClient { | ||
6 | class Parsing { | ||
7 | public static string[] ParseArguments(string str) { | ||
8 | List<string> list = new List<string>(); | ||
9 | string current = ""; | ||
10 | string trimmed = null; | ||
11 | bool withinQuote = false; | ||
12 | bool escaped = false; | ||
13 | foreach (char c in str) { | ||
14 | if (c == '"') { | ||
15 | if (escaped) { | ||
16 | current += '"'; | ||
17 | escaped = false; | ||
18 | } else { | ||
19 | current += '"'; | ||
20 | withinQuote = !withinQuote; | ||
21 | } | ||
22 | } else if (c == ' ' || c == '\t') { | ||
23 | if (escaped || withinQuote) { | ||
24 | current += c; | ||
25 | escaped = false; | ||
26 | } else { | ||
27 | trimmed = current.Trim(); | ||
28 | if (trimmed.StartsWith("\"") && trimmed.EndsWith("\"")) { | ||
29 | trimmed = trimmed.Remove(0, 1); | ||
30 | trimmed = trimmed.Remove(trimmed.Length - 1); | ||
31 | trimmed = trimmed.Trim(); | ||
32 | } | ||
33 | if (trimmed.Length > 0) | ||
34 | list.Add(trimmed); | ||
35 | current = ""; | ||
36 | } | ||
37 | } else if (c == '\\') { | ||
38 | if (escaped) { | ||
39 | current += '\\'; | ||
40 | escaped = false; | ||
41 | } else { | ||
42 | escaped = true; | ||
43 | } | ||
44 | } else { | ||
45 | if (escaped) | ||
46 | throw new FormatException(c.ToString() + " is not an escapable character."); | ||
47 | current += c; | ||
48 | } | ||
49 | } | ||
50 | trimmed = current.Trim(); | ||
51 | if (trimmed.StartsWith("\"") && trimmed.EndsWith("\"")) { | ||
52 | trimmed = trimmed.Remove(0, 1); | ||
53 | trimmed = trimmed.Remove(trimmed.Length - 1); | ||
54 | trimmed = trimmed.Trim(); | ||
55 | } | ||
56 | if (trimmed.Length > 0) | ||
57 | list.Add(trimmed); | ||
58 | return list.ToArray(); | ||
59 | } | ||
60 | } | ||
61 | } | ||