deepseek-computer-use 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +16 -3
- package/lib/index.js +7 -0
- package/lib/update-client.js +426 -0
- package/native/Driver.cs +1906 -1906
- package/native/Json.cs +274 -274
- package/native/Overlay.cs +732 -732
- package/native/Program.cs +160 -160
- package/native/audio/Program.cs +95 -95
- package/native/wgcfw/Program.cs +249 -249
- package/package.json +20 -6
package/native/Json.cs
CHANGED
|
@@ -1,274 +1,274 @@
|
|
|
1
|
-
|
|
2
|
-
using System;
|
|
3
|
-
using System.Collections;
|
|
4
|
-
using System.Collections.Generic;
|
|
5
|
-
using System.Globalization;
|
|
6
|
-
using System.Text;
|
|
7
|
-
|
|
8
|
-
public static class Json
|
|
9
|
-
{
|
|
10
|
-
public static string ToJson(object value)
|
|
11
|
-
{
|
|
12
|
-
StringBuilder sb = new StringBuilder(256);
|
|
13
|
-
Write(sb, value);
|
|
14
|
-
return sb.ToString();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static void WriteString(StringBuilder sb, string s)
|
|
18
|
-
{
|
|
19
|
-
sb.Append('"');
|
|
20
|
-
for (int i = 0; i < s.Length; i++)
|
|
21
|
-
{
|
|
22
|
-
char c = s[i];
|
|
23
|
-
switch (c)
|
|
24
|
-
{
|
|
25
|
-
case '"': sb.Append("\\\""); break;
|
|
26
|
-
case '\\': sb.Append("\\\\"); break;
|
|
27
|
-
case '\n': sb.Append("\\n"); break;
|
|
28
|
-
case '\r': sb.Append("\\r"); break;
|
|
29
|
-
case '\t': sb.Append("\\t"); break;
|
|
30
|
-
case '\b': sb.Append("\\b"); break;
|
|
31
|
-
case '\f': sb.Append("\\f"); break;
|
|
32
|
-
default:
|
|
33
|
-
if (c < 0x20 || c == 0x7f)
|
|
34
|
-
{
|
|
35
|
-
sb.Append("\\u");
|
|
36
|
-
sb.Append(((int)c).ToString("x4", CultureInfo.InvariantCulture));
|
|
37
|
-
}
|
|
38
|
-
else sb.Append(c);
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
sb.Append('"');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static void Write(StringBuilder sb, object v)
|
|
46
|
-
{
|
|
47
|
-
if (v == null) { sb.Append("null"); return; }
|
|
48
|
-
string s = v as string;
|
|
49
|
-
if (s != null) { WriteString(sb, s); return; }
|
|
50
|
-
if (v is bool) { sb.Append(((bool)v) ? "true" : "false"); return; }
|
|
51
|
-
if (v is int || v is long || v is short || v is byte) { sb.Append(Convert.ToInt64(v).ToString(CultureInfo.InvariantCulture)); return; }
|
|
52
|
-
if (v is decimal) { sb.Append(((decimal)v).ToString(CultureInfo.InvariantCulture)); return; }
|
|
53
|
-
if (v is double || v is float)
|
|
54
|
-
{
|
|
55
|
-
double d = Convert.ToDouble(v);
|
|
56
|
-
if (double.IsNaN(d) || double.IsInfinity(d)) { sb.Append("null"); return; }
|
|
57
|
-
sb.Append(d.ToString("R", CultureInfo.InvariantCulture));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
IDictionary dict = v as IDictionary;
|
|
61
|
-
if (dict != null)
|
|
62
|
-
{
|
|
63
|
-
sb.Append('{');
|
|
64
|
-
bool first = true;
|
|
65
|
-
foreach (DictionaryEntry e in dict)
|
|
66
|
-
{
|
|
67
|
-
if (!first) sb.Append(',');
|
|
68
|
-
first = false;
|
|
69
|
-
WriteString(sb, Convert.ToString(e.Key, CultureInfo.InvariantCulture));
|
|
70
|
-
sb.Append(':');
|
|
71
|
-
Write(sb, e.Value);
|
|
72
|
-
}
|
|
73
|
-
sb.Append('}');
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
IEnumerable list = v as IEnumerable;
|
|
77
|
-
if (list != null)
|
|
78
|
-
{
|
|
79
|
-
sb.Append('[');
|
|
80
|
-
bool first = true;
|
|
81
|
-
foreach (object item in list)
|
|
82
|
-
{
|
|
83
|
-
if (!first) sb.Append(',');
|
|
84
|
-
first = false;
|
|
85
|
-
Write(sb, item);
|
|
86
|
-
}
|
|
87
|
-
sb.Append(']');
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
WriteString(sb, Convert.ToString(v, CultureInfo.InvariantCulture));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public static object Parse(string text)
|
|
94
|
-
{
|
|
95
|
-
Parser p = new Parser(text);
|
|
96
|
-
object v = p.ParseValue();
|
|
97
|
-
p.SkipWs();
|
|
98
|
-
return v;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
class Parser
|
|
102
|
-
{
|
|
103
|
-
readonly string _s;
|
|
104
|
-
int _i;
|
|
105
|
-
|
|
106
|
-
public Parser(string s) { _s = s; _i = 0; }
|
|
107
|
-
|
|
108
|
-
public void SkipWs()
|
|
109
|
-
{
|
|
110
|
-
while (_i < _s.Length)
|
|
111
|
-
{
|
|
112
|
-
char c = _s[_i];
|
|
113
|
-
if (c == ' ' || c == '\t' || c == '\r' || c == '\n') _i++;
|
|
114
|
-
else break;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public object ParseValue()
|
|
119
|
-
{
|
|
120
|
-
SkipWs();
|
|
121
|
-
if (_i >= _s.Length) throw new FormatException("unexpected end of json");
|
|
122
|
-
char c = _s[_i];
|
|
123
|
-
if (c == '{') return ParseObject();
|
|
124
|
-
if (c == '[') return ParseArray();
|
|
125
|
-
if (c == '"') return ParseString();
|
|
126
|
-
if (c == 't') { Expect("true"); return true; }
|
|
127
|
-
if (c == 'f') { Expect("false"); return false; }
|
|
128
|
-
if (c == 'n') { Expect("null"); return null; }
|
|
129
|
-
return ParseNumber();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
void Expect(string lit)
|
|
133
|
-
{
|
|
134
|
-
if (string.CompareOrdinal(_s, _i, lit, 0, lit.Length) != 0) throw new FormatException("bad literal at " + _i);
|
|
135
|
-
_i += lit.Length;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
Dictionary<string, object> ParseObject()
|
|
139
|
-
{
|
|
140
|
-
Dictionary<string, object> d = new Dictionary<string, object>();
|
|
141
|
-
_i++;
|
|
142
|
-
SkipWs();
|
|
143
|
-
if (_i < _s.Length && _s[_i] == '}') { _i++; return d; }
|
|
144
|
-
while (true)
|
|
145
|
-
{
|
|
146
|
-
SkipWs();
|
|
147
|
-
string key = ParseString();
|
|
148
|
-
SkipWs();
|
|
149
|
-
if (_s[_i] != ':') throw new FormatException("expected : at " + _i);
|
|
150
|
-
_i++;
|
|
151
|
-
object val = ParseValue();
|
|
152
|
-
d[key] = val;
|
|
153
|
-
SkipWs();
|
|
154
|
-
if (_i >= _s.Length) throw new FormatException("unterminated object");
|
|
155
|
-
char c = _s[_i];
|
|
156
|
-
if (c == ',') { _i++; continue; }
|
|
157
|
-
if (c == '}') { _i++; break; }
|
|
158
|
-
throw new FormatException("expected , or } at " + _i);
|
|
159
|
-
}
|
|
160
|
-
return d;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
List<object> ParseArray()
|
|
164
|
-
{
|
|
165
|
-
List<object> list = new List<object>();
|
|
166
|
-
_i++;
|
|
167
|
-
SkipWs();
|
|
168
|
-
if (_i < _s.Length && _s[_i] == ']') { _i++; return list; }
|
|
169
|
-
while (true)
|
|
170
|
-
{
|
|
171
|
-
list.Add(ParseValue());
|
|
172
|
-
SkipWs();
|
|
173
|
-
if (_i >= _s.Length) throw new FormatException("unterminated array");
|
|
174
|
-
char c = _s[_i];
|
|
175
|
-
if (c == ',') { _i++; continue; }
|
|
176
|
-
if (c == ']') { _i++; break; }
|
|
177
|
-
throw new FormatException("expected , or ] at " + _i);
|
|
178
|
-
}
|
|
179
|
-
return list;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
string ParseString()
|
|
183
|
-
{
|
|
184
|
-
if (_s[_i] != '"') throw new FormatException("expected string at " + _i);
|
|
185
|
-
_i++;
|
|
186
|
-
StringBuilder sb = new StringBuilder();
|
|
187
|
-
while (true)
|
|
188
|
-
{
|
|
189
|
-
if (_i >= _s.Length) throw new FormatException("unterminated string");
|
|
190
|
-
char c = _s[_i++];
|
|
191
|
-
if (c == '"') break;
|
|
192
|
-
if (c != '\\') { sb.Append(c); continue; }
|
|
193
|
-
if (_i >= _s.Length) throw new FormatException("bad escape");
|
|
194
|
-
char e = _s[_i++];
|
|
195
|
-
switch (e)
|
|
196
|
-
{
|
|
197
|
-
case '"': sb.Append('"'); break;
|
|
198
|
-
case '\\': sb.Append('\\'); break;
|
|
199
|
-
case '/': sb.Append('/'); break;
|
|
200
|
-
case 'b': sb.Append('\b'); break;
|
|
201
|
-
case 'f': sb.Append('\f'); break;
|
|
202
|
-
case 'n': sb.Append('\n'); break;
|
|
203
|
-
case 'r': sb.Append('\r'); break;
|
|
204
|
-
case 't': sb.Append('\t'); break;
|
|
205
|
-
case 'u':
|
|
206
|
-
if (_i + 4 > _s.Length) throw new FormatException("bad unicode escape");
|
|
207
|
-
sb.Append((char)int.Parse(_s.Substring(_i, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture));
|
|
208
|
-
_i += 4;
|
|
209
|
-
break;
|
|
210
|
-
default: throw new FormatException("bad escape char " + e);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return sb.ToString();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
object ParseNumber()
|
|
217
|
-
{
|
|
218
|
-
int start = _i;
|
|
219
|
-
while (_i < _s.Length)
|
|
220
|
-
{
|
|
221
|
-
char c = _s[_i];
|
|
222
|
-
if ((c >= '0' && c <= '9') || c == '-' || c == '+' || c == '.' || c == 'e' || c == 'E') _i++;
|
|
223
|
-
else break;
|
|
224
|
-
}
|
|
225
|
-
string raw = _s.Substring(start, _i - start);
|
|
226
|
-
long l;
|
|
227
|
-
if (long.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out l)) return l;
|
|
228
|
-
double d;
|
|
229
|
-
if (double.TryParse(raw, NumberStyles.Float, CultureInfo.InvariantCulture, out d)) return d;
|
|
230
|
-
throw new FormatException("bad number '" + raw + "'");
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
public static Dictionary<string, object> AsObject(object v) { return v as Dictionary<string, object>; }
|
|
235
|
-
|
|
236
|
-
public static object Get(Dictionary<string, object> d, string key)
|
|
237
|
-
{
|
|
238
|
-
if (d == null) return null;
|
|
239
|
-
object v;
|
|
240
|
-
if (d.TryGetValue(key, out v)) return v;
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
public static string GetString(Dictionary<string, object> d, string key)
|
|
245
|
-
{
|
|
246
|
-
object v = Get(d, key);
|
|
247
|
-
if (v == null) return null;
|
|
248
|
-
return Convert.ToString(v, CultureInfo.InvariantCulture);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
public static long GetLong(Dictionary<string, object> d, string key, long fallback)
|
|
252
|
-
{
|
|
253
|
-
object v = Get(d, key);
|
|
254
|
-
if (v == null) return fallback;
|
|
255
|
-
try { return Convert.ToInt64(v, CultureInfo.InvariantCulture); } catch { return fallback; }
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
public static double GetDouble(Dictionary<string, object> d, string key, double fallback)
|
|
259
|
-
{
|
|
260
|
-
object v = Get(d, key);
|
|
261
|
-
if (v == null) return fallback;
|
|
262
|
-
try { return Convert.ToDouble(v, CultureInfo.InvariantCulture); } catch { return fallback; }
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
public static bool GetBool(Dictionary<string, object> d, string key, bool fallback)
|
|
266
|
-
{
|
|
267
|
-
object v = Get(d, key);
|
|
268
|
-
if (v == null) return fallback;
|
|
269
|
-
if (v is bool) return (bool)v;
|
|
270
|
-
string s = v as string;
|
|
271
|
-
if (s != null) return string.Equals(s, "true", StringComparison.OrdinalIgnoreCase);
|
|
272
|
-
return fallback;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
1
|
+
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using System.Globalization;
|
|
6
|
+
using System.Text;
|
|
7
|
+
|
|
8
|
+
public static class Json
|
|
9
|
+
{
|
|
10
|
+
public static string ToJson(object value)
|
|
11
|
+
{
|
|
12
|
+
StringBuilder sb = new StringBuilder(256);
|
|
13
|
+
Write(sb, value);
|
|
14
|
+
return sb.ToString();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static void WriteString(StringBuilder sb, string s)
|
|
18
|
+
{
|
|
19
|
+
sb.Append('"');
|
|
20
|
+
for (int i = 0; i < s.Length; i++)
|
|
21
|
+
{
|
|
22
|
+
char c = s[i];
|
|
23
|
+
switch (c)
|
|
24
|
+
{
|
|
25
|
+
case '"': sb.Append("\\\""); break;
|
|
26
|
+
case '\\': sb.Append("\\\\"); break;
|
|
27
|
+
case '\n': sb.Append("\\n"); break;
|
|
28
|
+
case '\r': sb.Append("\\r"); break;
|
|
29
|
+
case '\t': sb.Append("\\t"); break;
|
|
30
|
+
case '\b': sb.Append("\\b"); break;
|
|
31
|
+
case '\f': sb.Append("\\f"); break;
|
|
32
|
+
default:
|
|
33
|
+
if (c < 0x20 || c == 0x7f)
|
|
34
|
+
{
|
|
35
|
+
sb.Append("\\u");
|
|
36
|
+
sb.Append(((int)c).ToString("x4", CultureInfo.InvariantCulture));
|
|
37
|
+
}
|
|
38
|
+
else sb.Append(c);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
sb.Append('"');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static void Write(StringBuilder sb, object v)
|
|
46
|
+
{
|
|
47
|
+
if (v == null) { sb.Append("null"); return; }
|
|
48
|
+
string s = v as string;
|
|
49
|
+
if (s != null) { WriteString(sb, s); return; }
|
|
50
|
+
if (v is bool) { sb.Append(((bool)v) ? "true" : "false"); return; }
|
|
51
|
+
if (v is int || v is long || v is short || v is byte) { sb.Append(Convert.ToInt64(v).ToString(CultureInfo.InvariantCulture)); return; }
|
|
52
|
+
if (v is decimal) { sb.Append(((decimal)v).ToString(CultureInfo.InvariantCulture)); return; }
|
|
53
|
+
if (v is double || v is float)
|
|
54
|
+
{
|
|
55
|
+
double d = Convert.ToDouble(v);
|
|
56
|
+
if (double.IsNaN(d) || double.IsInfinity(d)) { sb.Append("null"); return; }
|
|
57
|
+
sb.Append(d.ToString("R", CultureInfo.InvariantCulture));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
IDictionary dict = v as IDictionary;
|
|
61
|
+
if (dict != null)
|
|
62
|
+
{
|
|
63
|
+
sb.Append('{');
|
|
64
|
+
bool first = true;
|
|
65
|
+
foreach (DictionaryEntry e in dict)
|
|
66
|
+
{
|
|
67
|
+
if (!first) sb.Append(',');
|
|
68
|
+
first = false;
|
|
69
|
+
WriteString(sb, Convert.ToString(e.Key, CultureInfo.InvariantCulture));
|
|
70
|
+
sb.Append(':');
|
|
71
|
+
Write(sb, e.Value);
|
|
72
|
+
}
|
|
73
|
+
sb.Append('}');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
IEnumerable list = v as IEnumerable;
|
|
77
|
+
if (list != null)
|
|
78
|
+
{
|
|
79
|
+
sb.Append('[');
|
|
80
|
+
bool first = true;
|
|
81
|
+
foreach (object item in list)
|
|
82
|
+
{
|
|
83
|
+
if (!first) sb.Append(',');
|
|
84
|
+
first = false;
|
|
85
|
+
Write(sb, item);
|
|
86
|
+
}
|
|
87
|
+
sb.Append(']');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
WriteString(sb, Convert.ToString(v, CultureInfo.InvariantCulture));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public static object Parse(string text)
|
|
94
|
+
{
|
|
95
|
+
Parser p = new Parser(text);
|
|
96
|
+
object v = p.ParseValue();
|
|
97
|
+
p.SkipWs();
|
|
98
|
+
return v;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class Parser
|
|
102
|
+
{
|
|
103
|
+
readonly string _s;
|
|
104
|
+
int _i;
|
|
105
|
+
|
|
106
|
+
public Parser(string s) { _s = s; _i = 0; }
|
|
107
|
+
|
|
108
|
+
public void SkipWs()
|
|
109
|
+
{
|
|
110
|
+
while (_i < _s.Length)
|
|
111
|
+
{
|
|
112
|
+
char c = _s[_i];
|
|
113
|
+
if (c == ' ' || c == '\t' || c == '\r' || c == '\n') _i++;
|
|
114
|
+
else break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public object ParseValue()
|
|
119
|
+
{
|
|
120
|
+
SkipWs();
|
|
121
|
+
if (_i >= _s.Length) throw new FormatException("unexpected end of json");
|
|
122
|
+
char c = _s[_i];
|
|
123
|
+
if (c == '{') return ParseObject();
|
|
124
|
+
if (c == '[') return ParseArray();
|
|
125
|
+
if (c == '"') return ParseString();
|
|
126
|
+
if (c == 't') { Expect("true"); return true; }
|
|
127
|
+
if (c == 'f') { Expect("false"); return false; }
|
|
128
|
+
if (c == 'n') { Expect("null"); return null; }
|
|
129
|
+
return ParseNumber();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void Expect(string lit)
|
|
133
|
+
{
|
|
134
|
+
if (string.CompareOrdinal(_s, _i, lit, 0, lit.Length) != 0) throw new FormatException("bad literal at " + _i);
|
|
135
|
+
_i += lit.Length;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
Dictionary<string, object> ParseObject()
|
|
139
|
+
{
|
|
140
|
+
Dictionary<string, object> d = new Dictionary<string, object>();
|
|
141
|
+
_i++;
|
|
142
|
+
SkipWs();
|
|
143
|
+
if (_i < _s.Length && _s[_i] == '}') { _i++; return d; }
|
|
144
|
+
while (true)
|
|
145
|
+
{
|
|
146
|
+
SkipWs();
|
|
147
|
+
string key = ParseString();
|
|
148
|
+
SkipWs();
|
|
149
|
+
if (_s[_i] != ':') throw new FormatException("expected : at " + _i);
|
|
150
|
+
_i++;
|
|
151
|
+
object val = ParseValue();
|
|
152
|
+
d[key] = val;
|
|
153
|
+
SkipWs();
|
|
154
|
+
if (_i >= _s.Length) throw new FormatException("unterminated object");
|
|
155
|
+
char c = _s[_i];
|
|
156
|
+
if (c == ',') { _i++; continue; }
|
|
157
|
+
if (c == '}') { _i++; break; }
|
|
158
|
+
throw new FormatException("expected , or } at " + _i);
|
|
159
|
+
}
|
|
160
|
+
return d;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
List<object> ParseArray()
|
|
164
|
+
{
|
|
165
|
+
List<object> list = new List<object>();
|
|
166
|
+
_i++;
|
|
167
|
+
SkipWs();
|
|
168
|
+
if (_i < _s.Length && _s[_i] == ']') { _i++; return list; }
|
|
169
|
+
while (true)
|
|
170
|
+
{
|
|
171
|
+
list.Add(ParseValue());
|
|
172
|
+
SkipWs();
|
|
173
|
+
if (_i >= _s.Length) throw new FormatException("unterminated array");
|
|
174
|
+
char c = _s[_i];
|
|
175
|
+
if (c == ',') { _i++; continue; }
|
|
176
|
+
if (c == ']') { _i++; break; }
|
|
177
|
+
throw new FormatException("expected , or ] at " + _i);
|
|
178
|
+
}
|
|
179
|
+
return list;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
string ParseString()
|
|
183
|
+
{
|
|
184
|
+
if (_s[_i] != '"') throw new FormatException("expected string at " + _i);
|
|
185
|
+
_i++;
|
|
186
|
+
StringBuilder sb = new StringBuilder();
|
|
187
|
+
while (true)
|
|
188
|
+
{
|
|
189
|
+
if (_i >= _s.Length) throw new FormatException("unterminated string");
|
|
190
|
+
char c = _s[_i++];
|
|
191
|
+
if (c == '"') break;
|
|
192
|
+
if (c != '\\') { sb.Append(c); continue; }
|
|
193
|
+
if (_i >= _s.Length) throw new FormatException("bad escape");
|
|
194
|
+
char e = _s[_i++];
|
|
195
|
+
switch (e)
|
|
196
|
+
{
|
|
197
|
+
case '"': sb.Append('"'); break;
|
|
198
|
+
case '\\': sb.Append('\\'); break;
|
|
199
|
+
case '/': sb.Append('/'); break;
|
|
200
|
+
case 'b': sb.Append('\b'); break;
|
|
201
|
+
case 'f': sb.Append('\f'); break;
|
|
202
|
+
case 'n': sb.Append('\n'); break;
|
|
203
|
+
case 'r': sb.Append('\r'); break;
|
|
204
|
+
case 't': sb.Append('\t'); break;
|
|
205
|
+
case 'u':
|
|
206
|
+
if (_i + 4 > _s.Length) throw new FormatException("bad unicode escape");
|
|
207
|
+
sb.Append((char)int.Parse(_s.Substring(_i, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture));
|
|
208
|
+
_i += 4;
|
|
209
|
+
break;
|
|
210
|
+
default: throw new FormatException("bad escape char " + e);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return sb.ToString();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
object ParseNumber()
|
|
217
|
+
{
|
|
218
|
+
int start = _i;
|
|
219
|
+
while (_i < _s.Length)
|
|
220
|
+
{
|
|
221
|
+
char c = _s[_i];
|
|
222
|
+
if ((c >= '0' && c <= '9') || c == '-' || c == '+' || c == '.' || c == 'e' || c == 'E') _i++;
|
|
223
|
+
else break;
|
|
224
|
+
}
|
|
225
|
+
string raw = _s.Substring(start, _i - start);
|
|
226
|
+
long l;
|
|
227
|
+
if (long.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out l)) return l;
|
|
228
|
+
double d;
|
|
229
|
+
if (double.TryParse(raw, NumberStyles.Float, CultureInfo.InvariantCulture, out d)) return d;
|
|
230
|
+
throw new FormatException("bad number '" + raw + "'");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
public static Dictionary<string, object> AsObject(object v) { return v as Dictionary<string, object>; }
|
|
235
|
+
|
|
236
|
+
public static object Get(Dictionary<string, object> d, string key)
|
|
237
|
+
{
|
|
238
|
+
if (d == null) return null;
|
|
239
|
+
object v;
|
|
240
|
+
if (d.TryGetValue(key, out v)) return v;
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public static string GetString(Dictionary<string, object> d, string key)
|
|
245
|
+
{
|
|
246
|
+
object v = Get(d, key);
|
|
247
|
+
if (v == null) return null;
|
|
248
|
+
return Convert.ToString(v, CultureInfo.InvariantCulture);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public static long GetLong(Dictionary<string, object> d, string key, long fallback)
|
|
252
|
+
{
|
|
253
|
+
object v = Get(d, key);
|
|
254
|
+
if (v == null) return fallback;
|
|
255
|
+
try { return Convert.ToInt64(v, CultureInfo.InvariantCulture); } catch { return fallback; }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public static double GetDouble(Dictionary<string, object> d, string key, double fallback)
|
|
259
|
+
{
|
|
260
|
+
object v = Get(d, key);
|
|
261
|
+
if (v == null) return fallback;
|
|
262
|
+
try { return Convert.ToDouble(v, CultureInfo.InvariantCulture); } catch { return fallback; }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
public static bool GetBool(Dictionary<string, object> d, string key, bool fallback)
|
|
266
|
+
{
|
|
267
|
+
object v = Get(d, key);
|
|
268
|
+
if (v == null) return fallback;
|
|
269
|
+
if (v is bool) return (bool)v;
|
|
270
|
+
string s = v as string;
|
|
271
|
+
if (s != null) return string.Equals(s, "true", StringComparison.OrdinalIgnoreCase);
|
|
272
|
+
return fallback;
|
|
273
|
+
}
|
|
274
|
+
}
|