diff options
author | Mic Bowman | 2013-02-13 07:14:04 -0800 |
---|---|---|
committer | Mic Bowman | 2013-02-13 07:14:04 -0800 |
commit | bcb172301dfc1d8dcdb837be89c3ce3248500cc0 (patch) | |
tree | c6e86bda51d3922395d629f8c62f5d359b8ccbe4 /OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |
parent | Make path parsing more robust in the JsonStore. (diff) | |
download | opensim-SC_OLD-bcb172301dfc1d8dcdb837be89c3ce3248500cc0.zip opensim-SC_OLD-bcb172301dfc1d8dcdb837be89c3ce3248500cc0.tar.gz opensim-SC_OLD-bcb172301dfc1d8dcdb837be89c3ce3248500cc0.tar.bz2 opensim-SC_OLD-bcb172301dfc1d8dcdb837be89c3ce3248500cc0.tar.xz |
Adds a couple requested functions to the JsonStore script
interface. JsonPathType returns the type of node pointed to by the
path and deprecates the functionality of both JsonTestPath
functions. JsonArrayLength returns the length of an array node.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index f7625fb..ca3989a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |||
@@ -145,6 +145,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
145 | /// | 145 | /// |
146 | /// </summary> | 146 | /// </summary> |
147 | // ----------------------------------------------------------------- | 147 | // ----------------------------------------------------------------- |
148 | public JsonStoreNodeType PathType(string expr) | ||
149 | { | ||
150 | Stack<string> path; | ||
151 | if (! ParsePathExpression(expr,out path)) | ||
152 | return JsonStoreNodeType.Undefined; | ||
153 | |||
154 | OSD result = ProcessPathExpression(ValueStore,path); | ||
155 | |||
156 | if (result == null) | ||
157 | return JsonStoreNodeType.Undefined; | ||
158 | |||
159 | if (result is OSDMap) | ||
160 | return JsonStoreNodeType.Object; | ||
161 | |||
162 | if (result is OSDArray) | ||
163 | return JsonStoreNodeType.Array; | ||
164 | |||
165 | if (OSDBaseType(result.Type)) | ||
166 | return JsonStoreNodeType.Value; | ||
167 | |||
168 | return JsonStoreNodeType.Undefined; | ||
169 | } | ||
170 | |||
171 | // ----------------------------------------------------------------- | ||
172 | /// <summary> | ||
173 | /// | ||
174 | /// </summary> | ||
175 | // ----------------------------------------------------------------- | ||
148 | public bool TestPath(string expr, bool useJson) | 176 | public bool TestPath(string expr, bool useJson) |
149 | { | 177 | { |
150 | Stack<string> path; | 178 | Stack<string> path; |
@@ -167,6 +195,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
167 | /// | 195 | /// |
168 | /// </summary> | 196 | /// </summary> |
169 | // ----------------------------------------------------------------- | 197 | // ----------------------------------------------------------------- |
198 | public int ArrayLength(string expr) | ||
199 | { | ||
200 | Stack<string> path; | ||
201 | if (! ParsePathExpression(expr,out path)) | ||
202 | return -1; | ||
203 | |||
204 | OSD result = ProcessPathExpression(ValueStore,path); | ||
205 | if (result != null && result.Type == OSDType.Array) | ||
206 | { | ||
207 | OSDArray arr = result as OSDArray; | ||
208 | return arr.Count; | ||
209 | } | ||
210 | |||
211 | return -1; | ||
212 | } | ||
213 | |||
214 | // ----------------------------------------------------------------- | ||
215 | /// <summary> | ||
216 | /// | ||
217 | /// </summary> | ||
218 | // ----------------------------------------------------------------- | ||
170 | public bool GetValue(string expr, out string value, bool useJson) | 219 | public bool GetValue(string expr, out string value, bool useJson) |
171 | { | 220 | { |
172 | Stack<string> path; | 221 | Stack<string> path; |