diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index 82a4da7..ca3989a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |||
@@ -68,14 +68,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
68 | protected List<TakeValueCallbackClass> m_TakeStore; | 68 | protected List<TakeValueCallbackClass> m_TakeStore; |
69 | protected List<TakeValueCallbackClass> m_ReadStore; | 69 | protected List<TakeValueCallbackClass> m_ReadStore; |
70 | 70 | ||
71 | // add separators for quoted paths | 71 | // add separators for quoted paths and array references |
72 | protected static Regex m_ParsePassOne = new Regex("{[^}]+}"); | 72 | protected static Regex m_ParsePassOne = new Regex("({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])"); |
73 | |||
74 | // add separators for array references | ||
75 | protected static Regex m_ParsePassTwo = new Regex("(\\[[0-9]+\\]|\\[\\+\\])"); | ||
76 | 73 | ||
77 | // add quotes to bare identifiers which are limited to alphabetic characters | 74 | // add quotes to bare identifiers which are limited to alphabetic characters |
78 | protected static Regex m_ParsePassThree = new Regex("\\.([a-zA-Z]+)"); | 75 | protected static Regex m_ParsePassThree = new Regex("(?<!{[^}]*)\\.([a-zA-Z]+)(?=\\.)"); |
79 | 76 | ||
80 | // remove extra separator characters | 77 | // remove extra separator characters |
81 | protected static Regex m_ParsePassFour = new Regex("\\.+"); | 78 | protected static Regex m_ParsePassFour = new Regex("\\.+"); |
@@ -84,7 +81,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
84 | protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$"); | 81 | protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$"); |
85 | 82 | ||
86 | // expression used to match path components | 83 | // expression used to match path components |
87 | protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); | 84 | protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])"); |
88 | 85 | ||
89 | // extract the internals of an array reference | 86 | // extract the internals of an array reference |
90 | protected static Regex m_SimpleArrayPattern = new Regex("\\[([0-9]+)\\]"); | 87 | protected static Regex m_SimpleArrayPattern = new Regex("\\[([0-9]+)\\]"); |
@@ -131,15 +128,46 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
131 | m_TakeStore = new List<TakeValueCallbackClass>(); | 128 | m_TakeStore = new List<TakeValueCallbackClass>(); |
132 | m_ReadStore = new List<TakeValueCallbackClass>(); | 129 | m_ReadStore = new List<TakeValueCallbackClass>(); |
133 | } | 130 | } |
134 | 131 | ||
135 | public JsonStore(string value) : this() | 132 | public JsonStore(string value) : this() |
136 | { | 133 | { |
134 | // This is going to throw an exception if the value is not | ||
135 | // a valid JSON chunk. Calling routines should catch the | ||
136 | // exception and handle it appropriately | ||
137 | if (String.IsNullOrEmpty(value)) | 137 | if (String.IsNullOrEmpty(value)) |
138 | ValueStore = new OSDMap(); | 138 | ValueStore = new OSDMap(); |
139 | else | 139 | else |
140 | ValueStore = OSDParser.DeserializeJson(value); | 140 | ValueStore = OSDParser.DeserializeJson(value); |
141 | } | 141 | } |
142 | |||
143 | // ----------------------------------------------------------------- | ||
144 | /// <summary> | ||
145 | /// | ||
146 | /// </summary> | ||
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); | ||
142 | 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 | |||
143 | // ----------------------------------------------------------------- | 171 | // ----------------------------------------------------------------- |
144 | /// <summary> | 172 | /// <summary> |
145 | /// | 173 | /// |
@@ -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; |
@@ -462,11 +511,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
462 | // add front and rear separators | 511 | // add front and rear separators |
463 | expr = "." + expr + "."; | 512 | expr = "." + expr + "."; |
464 | 513 | ||
465 | // add separators for quoted exprs | 514 | // add separators for quoted exprs and array references |
466 | expr = m_ParsePassOne.Replace(expr,".$0.",-1,0); | 515 | expr = m_ParsePassOne.Replace(expr,".$1.",-1,0); |
467 | |||
468 | // add separators for array references | ||
469 | expr = m_ParsePassTwo.Replace(expr,".$0.",-1,0); | ||
470 | 516 | ||
471 | // add quotes to bare identifier | 517 | // add quotes to bare identifier |
472 | expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0); | 518 | expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0); |
@@ -574,14 +620,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
574 | // The path pointed to an intermediate hash structure | 620 | // The path pointed to an intermediate hash structure |
575 | if (result.Type == OSDType.Map) | 621 | if (result.Type == OSDType.Map) |
576 | { | 622 | { |
577 | value = OSDParser.SerializeJsonString(result as OSDMap); | 623 | value = OSDParser.SerializeJsonString(result as OSDMap,true); |
578 | return true; | 624 | return true; |
579 | } | 625 | } |
580 | 626 | ||
581 | // The path pointed to an intermediate hash structure | 627 | // The path pointed to an intermediate hash structure |
582 | if (result.Type == OSDType.Array) | 628 | if (result.Type == OSDType.Array) |
583 | { | 629 | { |
584 | value = OSDParser.SerializeJsonString(result as OSDArray); | 630 | value = OSDParser.SerializeJsonString(result as OSDArray,true); |
585 | return true; | 631 | return true; |
586 | } | 632 | } |
587 | 633 | ||