aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
diff options
context:
space:
mode:
authorMic Bowman2013-01-31 14:53:16 -0800
committerMic Bowman2013-01-31 14:53:16 -0800
commit1e0420431f754ff71a97d01fae5617c1ea26cae0 (patch)
tree4d69a960e7701aa7af097b50b9259fbcc6d28021 /OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-1e0420431f754ff71a97d01fae5617c1ea26cae0.zip
opensim-SC_OLD-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.gz
opensim-SC_OLD-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.bz2
opensim-SC_OLD-1e0420431f754ff71a97d01fae5617c1ea26cae0.tar.xz
Move the JsonStore regular expressions to static variables to avoid
recompiling on every operation. Added JsonList2Path script function to simplify array iteration.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs73
1 files changed, 49 insertions, 24 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index 34894ba..0b7b31b 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -68,12 +68,46 @@ 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
72 protected static Regex m_ParsePassOne = new Regex("{[^}]+}");
73
74 // add separators for array references
75 protected static Regex m_ParsePassTwo = new Regex("(\\[[0-9]+\\]|\\[\\+\\])");
76
77 // add quotes to bare identifiers which are limited to alphabetic characters
78 protected static Regex m_ParsePassThree = new Regex("\\.([a-zA-Z]+)");
79
80 // remove extra separator characters
81 protected static Regex m_ParsePassFour = new Regex("\\.+");
82
83 // expression used to validate the full path, this is canonical representation
84 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$");
85
86 // expression used to match path components
87 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)");
88
89 // extract the internals of an array reference
90 protected static Regex m_SimpleArrayPattern = new Regex("\\[([0-9]+)\\]");
91 protected static Regex m_ArrayPattern = new Regex("\\[([0-9]+|\\+)\\]");
92
93 // extract the internals of a has reference
94 protected static Regex m_HashPattern = new Regex("{([^}]+)}");
71 95
72 // ----------------------------------------------------------------- 96 // -----------------------------------------------------------------
73 /// <summary> 97 /// <summary>
74 /// 98 ///
75 /// </summary> 99 /// </summary>
76 // ----------------------------------------------------------------- 100 // -----------------------------------------------------------------
101 public static string CanonicalPathExpression(string path)
102 {
103 return PathExpressionToKey(ParsePathExpression(path));
104 }
105
106 // -----------------------------------------------------------------
107 /// <summary>
108 ///
109 /// </summary>
110 // -----------------------------------------------------------------
77 public JsonStore() : this("") {} 111 public JsonStore() : this("") {}
78 112
79 public JsonStore(string value) 113 public JsonStore(string value)
@@ -224,9 +258,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
224 if (result == null) 258 if (result == null)
225 return false; 259 return false;
226 260
227 Regex aPattern = new Regex("\\[([0-9]+|\\+)\\]"); 261 // Check for and extract array references
228 MatchCollection amatches = aPattern.Matches(pkey,0); 262 MatchCollection amatches = m_ArrayPattern.Matches(pkey,0);
229
230 if (amatches.Count > 0) 263 if (amatches.Count > 0)
231 { 264 {
232 if (result.Type != OSDType.Array) 265 if (result.Type != OSDType.Array)
@@ -263,9 +296,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
263 return false; 296 return false;
264 } 297 }
265 298
266 Regex hPattern = new Regex("{([^}]+)}"); 299 // Check for and extract hash references
267 MatchCollection hmatches = hPattern.Matches(pkey,0); 300 MatchCollection hmatches = m_HashPattern.Matches(pkey,0);
268
269 if (hmatches.Count > 0) 301 if (hmatches.Count > 0)
270 { 302 {
271 Match match = hmatches[0]; 303 Match match = hmatches[0];
@@ -340,26 +372,21 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
340 path = "." + path + "."; 372 path = "." + path + ".";
341 373
342 // add separators for quoted paths 374 // add separators for quoted paths
343 Regex pass1 = new Regex("{[^}]+}"); 375 path = m_ParsePassOne.Replace(path,".$0.",-1,0);
344 path = pass1.Replace(path,".$0.",-1,0);
345 376
346 // add separators for array references 377 // add separators for array references
347 Regex pass2 = new Regex("(\\[[0-9]+\\]|\\[\\+\\])"); 378 path = m_ParsePassTwo.Replace(path,".$0.",-1,0);
348 path = pass2.Replace(path,".$0.",-1,0);
349 379
350 // add quotes to bare identifier 380 // add quotes to bare identifier
351 Regex pass3 = new Regex("\\.([a-zA-Z]+)"); 381 path = m_ParsePassThree.Replace(path,".{$1}",-1,0);
352 path = pass3.Replace(path,".{$1}",-1,0);
353 382
354 // remove extra separators 383 // remove extra separators
355 Regex pass4 = new Regex("\\.+"); 384 path = m_ParsePassFour.Replace(path,".",-1,0);
356 path = pass4.Replace(path,".",-1,0);
357 385
358 Regex validate = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$"); 386 // validate the results (catches extra quote characters for example)
359 if (validate.IsMatch(path)) 387 if (m_ValidatePath.IsMatch(path))
360 { 388 {
361 Regex parser = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); 389 MatchCollection matches = m_PathComponent.Matches(path,0);
362 MatchCollection matches = parser.Matches(path,0);
363 foreach (Match match in matches) 390 foreach (Match match in matches)
364 m_path.Push(match.Groups[1].Value); 391 m_path.Push(match.Groups[1].Value);
365 } 392 }
@@ -385,9 +412,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
385 return null; 412 return null;
386 413
387 // ---------- Check for an array index ---------- 414 // ---------- Check for an array index ----------
388 Regex aPattern = new Regex("\\[([0-9]+)\\]"); 415 MatchCollection amatches = m_SimpleArrayPattern.Matches(pkey,0);
389 MatchCollection amatches = aPattern.Matches(pkey,0); 416
390
391 if (amatches.Count > 0) 417 if (amatches.Count > 0)
392 { 418 {
393 if (rmap.Type != OSDType.Array) 419 if (rmap.Type != OSDType.Array)
@@ -410,9 +436,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
410 } 436 }
411 437
412 // ---------- Check for a hash index ---------- 438 // ---------- Check for a hash index ----------
413 Regex hPattern = new Regex("{([^}]+)}"); 439 MatchCollection hmatches = m_HashPattern.Matches(pkey,0);
414 MatchCollection hmatches = hPattern.Matches(pkey,0); 440
415
416 if (hmatches.Count > 0) 441 if (hmatches.Count > 0)
417 { 442 {
418 if (rmap.Type != OSDType.Map) 443 if (rmap.Type != OSDType.Map)