diff options
author | Adam Frisby | 2007-06-21 17:08:21 +0000 |
---|---|---|
committer | Adam Frisby | 2007-06-21 17:08:21 +0000 |
commit | e93869c7a785a4f375685ffa33c913033ed1c85a (patch) | |
tree | abb5e2c58f8750a1bc05acf58716b6b025da4d15 /tools/mass test client/Parsing.cs | |
parent | Fixed the struct and null compare bug. (diff) | |
download | opensim-SC-e93869c7a785a4f375685ffa33c913033ed1c85a.zip opensim-SC-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.gz opensim-SC-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.bz2 opensim-SC-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.xz |
* Importing Ming's mass test client
Diffstat (limited to '')
-rw-r--r-- | tools/mass test client/Parsing.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/mass test client/Parsing.cs b/tools/mass test client/Parsing.cs new file mode 100644 index 0000000..371c3cd --- /dev/null +++ b/tools/mass test client/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 | } | ||