diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs | 397 |
1 files changed, 245 insertions, 152 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs index 802eac2..fbdf1bf 100644 --- a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs +++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstAbstract.cs | |||
@@ -63,7 +63,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
63 | 63 | ||
64 | private static readonly XMR_Array[] noArrays = new XMR_Array[0]; | 64 | private static readonly XMR_Array[] noArrays = new XMR_Array[0]; |
65 | private static readonly char[] noChars = new char[0]; | 65 | private static readonly char[] noChars = new char[0]; |
66 | private static readonly double[] noFloats = new double[0]; | 66 | private static readonly double[] noFloats = new double[0]; |
67 | private static readonly int[] noIntegers = new int[0]; | 67 | private static readonly int[] noIntegers = new int[0]; |
68 | private static readonly LSL_List[] noLists = new LSL_List[0]; | 68 | private static readonly LSL_List[] noLists = new LSL_List[0]; |
69 | private static readonly object[] noObjects = new object[0]; | 69 | private static readonly object[] noObjects = new object[0]; |
@@ -97,7 +97,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
97 | 97 | ||
98 | iarArrays = (ars.iasArrays > 0) ? new XMR_Array [ars.iasArrays] : noArrays; | 98 | iarArrays = (ars.iasArrays > 0) ? new XMR_Array [ars.iasArrays] : noArrays; |
99 | iarChars = (ars.iasChars > 0) ? new char [ars.iasChars] : noChars; | 99 | iarChars = (ars.iasChars > 0) ? new char [ars.iasChars] : noChars; |
100 | iarFloats = (ars.iasFloats > 0) ? new double [ars.iasFloats] : noFloats; | 100 | iarFloats = (ars.iasFloats > 0) ? new double [ars.iasFloats] : noFloats; |
101 | iarIntegers = (ars.iasIntegers > 0) ? new int [ars.iasIntegers] : noIntegers; | 101 | iarIntegers = (ars.iasIntegers > 0) ? new int [ars.iasIntegers] : noIntegers; |
102 | iarLists = (ars.iasLists > 0) ? new LSL_List [ars.iasLists] : noLists; | 102 | iarLists = (ars.iasLists > 0) ? new LSL_List [ars.iasLists] : noLists; |
103 | iarObjects = (ars.iasObjects > 0) ? new object [ars.iasObjects] : noObjects; | 103 | iarObjects = (ars.iasObjects > 0) ? new object [ars.iasObjects] : noObjects; |
@@ -170,7 +170,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
170 | 170 | ||
171 | iarArrays = (XMR_Array[]) recver (); | 171 | iarArrays = (XMR_Array[]) recver (); |
172 | char[] chrs = (char[]) recver (); | 172 | char[] chrs = (char[]) recver (); |
173 | double[] flts = (double[]) recver (); | 173 | double[] flts = (double[]) recver (); |
174 | int[] ints = (int[]) recver (); | 174 | int[] ints = (int[]) recver (); |
175 | LSL_List[] liss = (LSL_List[]) recver (); | 175 | LSL_List[] liss = (LSL_List[]) recver (); |
176 | object[] objs = (object[]) recver (); | 176 | object[] objs = (object[]) recver (); |
@@ -191,15 +191,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
191 | newheapuse += dels.Length * HeapTrackerObject.HT_DELE; | 191 | newheapuse += dels.Length * HeapTrackerObject.HT_DELE; |
192 | 192 | ||
193 | // lists, objects, strings are the sum of the size of each element | 193 | // lists, objects, strings are the sum of the size of each element |
194 | foreach (LSL_List lis in liss) { | 194 | foreach (LSL_List lis in liss) |
195 | newheapuse += HeapTrackerList.Size (lis); | 195 | newheapuse += HeapTrackerList.Size (lis); |
196 | } | 196 | |
197 | foreach (object obj in objs) { | 197 | foreach (object obj in objs) |
198 | newheapuse += HeapTrackerObject.Size (obj); | 198 | newheapuse += HeapTrackerObject.Size (obj); |
199 | } | 199 | |
200 | foreach (string str in strs) { | 200 | foreach (string str in strs) |
201 | newheapuse += HeapTrackerString.Size (str); | 201 | newheapuse += HeapTrackerString.Size (str); |
202 | } | ||
203 | 202 | ||
204 | // others (XMR_Array, XMRSDTypeClObj) keep track of their own heap usage | 203 | // others (XMR_Array, XMRSDTypeClObj) keep track of their own heap usage |
205 | 204 | ||
@@ -222,46 +221,55 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
222 | int newheapuse = heapUse; | 221 | int newheapuse = heapUse; |
223 | 222 | ||
224 | iarArrays = null; | 223 | iarArrays = null; |
225 | if (iarChars != null) { | 224 | if (iarChars != null) |
225 | { | ||
226 | newheapuse -= iarChars.Length * HeapTrackerObject.HT_CHAR; | 226 | newheapuse -= iarChars.Length * HeapTrackerObject.HT_CHAR; |
227 | iarChars = null; | 227 | iarChars = null; |
228 | } | 228 | } |
229 | if (iarFloats != null) { | 229 | if (iarFloats != null) |
230 | { | ||
230 | newheapuse -= iarFloats.Length * HeapTrackerObject.HT_SFLT; | 231 | newheapuse -= iarFloats.Length * HeapTrackerObject.HT_SFLT; |
231 | iarFloats = null; | 232 | iarFloats = null; |
232 | } | 233 | } |
233 | if (iarIntegers != null) { | 234 | if (iarIntegers != null) |
235 | { | ||
234 | newheapuse -= iarIntegers.Length * HeapTrackerObject.HT_INT; | 236 | newheapuse -= iarIntegers.Length * HeapTrackerObject.HT_INT; |
235 | iarIntegers = null; | 237 | iarIntegers = null; |
236 | } | 238 | } |
237 | if (iarLists != null) { | 239 | if (iarLists != null) |
238 | foreach (LSL_List lis in iarLists) { | 240 | { |
241 | foreach (LSL_List lis in iarLists) | ||
239 | newheapuse -= HeapTrackerList.Size (lis); | 242 | newheapuse -= HeapTrackerList.Size (lis); |
240 | } | 243 | |
241 | iarLists = null; | 244 | iarLists = null; |
242 | } | 245 | } |
243 | if (iarObjects != null) { | 246 | if (iarObjects != null) |
244 | foreach (object obj in iarObjects) { | 247 | { |
248 | foreach (object obj in iarObjects) | ||
245 | newheapuse -= HeapTrackerObject.Size (obj); | 249 | newheapuse -= HeapTrackerObject.Size (obj); |
246 | } | 250 | |
247 | iarObjects = null; | 251 | iarObjects = null; |
248 | } | 252 | } |
249 | if (iarRotations != null) { | 253 | if (iarRotations != null) |
254 | { | ||
250 | newheapuse -= iarRotations.Length * HeapTrackerObject.HT_ROT; | 255 | newheapuse -= iarRotations.Length * HeapTrackerObject.HT_ROT; |
251 | iarRotations = null; | 256 | iarRotations = null; |
252 | } | 257 | } |
253 | if (iarStrings != null) { | 258 | if (iarStrings != null) |
254 | foreach (string str in iarStrings) { | 259 | { |
260 | foreach (string str in iarStrings) | ||
255 | newheapuse -= HeapTrackerString.Size (str); | 261 | newheapuse -= HeapTrackerString.Size (str); |
256 | } | 262 | |
257 | iarStrings = null; | 263 | iarStrings = null; |
258 | } | 264 | } |
259 | if (iarVectors != null) { | 265 | if (iarVectors != null) |
266 | { | ||
260 | newheapuse -= iarVectors.Length * HeapTrackerObject.HT_VEC; | 267 | newheapuse -= iarVectors.Length * HeapTrackerObject.HT_VEC; |
261 | iarVectors = null; | 268 | iarVectors = null; |
262 | } | 269 | } |
263 | iarSDTClObjs = null; | 270 | iarSDTClObjs = null; |
264 | if (iarSDTIntfObjs != null) { | 271 | if (iarSDTIntfObjs != null) |
272 | { | ||
265 | newheapuse -= iarSDTIntfObjs.Length * HeapTrackerObject.HT_DELE; | 273 | newheapuse -= iarSDTIntfObjs.Length * HeapTrackerObject.HT_DELE; |
266 | iarSDTIntfObjs = null; | 274 | iarSDTIntfObjs = null; |
267 | } | 275 | } |
@@ -270,7 +278,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
270 | } | 278 | } |
271 | } | 279 | } |
272 | 280 | ||
273 | public class XMRInstArSizes { | 281 | public class XMRInstArSizes |
282 | { | ||
274 | public int iasArrays; | 283 | public int iasArrays; |
275 | public int iasChars; | 284 | public int iasChars; |
276 | public int iasFloats; | 285 | public int iasFloats; |
@@ -327,7 +336,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
327 | } | 336 | } |
328 | } | 337 | } |
329 | 338 | ||
330 | public class XMRStackFrame { | 339 | public class XMRStackFrame |
340 | { | ||
331 | public XMRStackFrame nextSF; | 341 | public XMRStackFrame nextSF; |
332 | public string funcName; | 342 | public string funcName; |
333 | public int callNo; | 343 | public int callNo; |
@@ -478,8 +488,10 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
478 | callMode = (stackFrames == null) ? XMRInstAbstract.CallMode_NORMAL : | 488 | callMode = (stackFrames == null) ? XMRInstAbstract.CallMode_NORMAL : |
479 | XMRInstAbstract.CallMode_RESTORE; | 489 | XMRInstAbstract.CallMode_RESTORE; |
480 | 490 | ||
481 | while (true) { | 491 | while (true) |
482 | if (this.newStateCode < 0) { | 492 | { |
493 | if (this.newStateCode < 0) | ||
494 | { | ||
483 | 495 | ||
484 | /* | 496 | /* |
485 | * Process event given by 'stateCode' and 'eventCode'. | 497 | * Process event given by 'stateCode' and 'eventCode'. |
@@ -487,10 +499,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
487 | */ | 499 | */ |
488 | int newState = this.stateCode; | 500 | int newState = this.stateCode; |
489 | seh = this.m_ObjCode.scriptEventHandlerTable[newState,(int)this.eventCode]; | 501 | seh = this.m_ObjCode.scriptEventHandlerTable[newState,(int)this.eventCode]; |
490 | if (seh != null) { | 502 | if (seh != null) |
491 | try { | 503 | { |
504 | try | ||
505 | { | ||
492 | seh (this); | 506 | seh (this); |
493 | } catch (ScriptChangeStateException scse) { | 507 | } |
508 | catch (ScriptChangeStateException scse) | ||
509 | { | ||
494 | newState = scse.newState; | 510 | newState = scse.newState; |
495 | } | 511 | } |
496 | } | 512 | } |
@@ -503,7 +519,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
503 | * It does not execute the state_exit() or state_entry() handlers. | 519 | * It does not execute the state_exit() or state_entry() handlers. |
504 | * See http://wiki.secondlife.com/wiki/State | 520 | * See http://wiki.secondlife.com/wiki/State |
505 | */ | 521 | */ |
506 | if (newState == this.stateCode) break; | 522 | if (newState == this.stateCode) |
523 | break; | ||
507 | 524 | ||
508 | /* | 525 | /* |
509 | * Save new state in a more permanent location in case we | 526 | * Save new state in a more permanent location in case we |
@@ -517,10 +534,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
517 | */ | 534 | */ |
518 | this.eventCode = ScriptEventCode.state_exit; | 535 | this.eventCode = ScriptEventCode.state_exit; |
519 | seh = this.m_ObjCode.scriptEventHandlerTable[this.stateCode,(int)ScriptEventCode.state_exit]; | 536 | seh = this.m_ObjCode.scriptEventHandlerTable[this.stateCode,(int)ScriptEventCode.state_exit]; |
520 | if (seh != null) { | 537 | if (seh != null) |
521 | try { | 538 | { |
539 | try | ||
540 | { | ||
522 | seh (this); | 541 | seh (this); |
523 | } catch (ScriptChangeStateException scse) { | 542 | } |
543 | catch (ScriptChangeStateException scse) | ||
544 | { | ||
524 | this.newStateCode = scse.newState; | 545 | this.newStateCode = scse.newState; |
525 | } | 546 | } |
526 | } | 547 | } |
@@ -563,7 +584,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
563 | */ | 584 | */ |
564 | public void CheckRunStack () | 585 | public void CheckRunStack () |
565 | { | 586 | { |
566 | if (xmrStackLeft () < stackLimit) { | 587 | if (xmrStackLeft () < stackLimit) |
588 | { | ||
567 | throw new OutOfStackException (); | 589 | throw new OutOfStackException (); |
568 | } | 590 | } |
569 | CheckRunQuick (); | 591 | CheckRunQuick (); |
@@ -574,9 +596,9 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
574 | */ | 596 | */ |
575 | public void CheckRunQuick () | 597 | public void CheckRunQuick () |
576 | { | 598 | { |
577 | if (suspendOnCheckRunHold || suspendOnCheckRunTemp) { | 599 | // if (suspendOnCheckRunHold || suspendOnCheckRunTemp) { |
578 | CheckRunWork (); | 600 | CheckRunWork (); |
579 | } | 601 | // } |
580 | } | 602 | } |
581 | 603 | ||
582 | /** | 604 | /** |
@@ -608,7 +630,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
608 | public object[] RestoreStackFrame (string funcName, out int callNo) | 630 | public object[] RestoreStackFrame (string funcName, out int callNo) |
609 | { | 631 | { |
610 | XMRStackFrame sf = stackFrames; | 632 | XMRStackFrame sf = stackFrames; |
611 | if (sf.funcName != funcName) { | 633 | if (sf.funcName != funcName) |
634 | { | ||
612 | throw new Exception ("frame mismatch " + sf.funcName + " vs " + funcName); | 635 | throw new Exception ("frame mismatch " + sf.funcName + " vs " + funcName); |
613 | } | 636 | } |
614 | callNo = sf.callNo; | 637 | callNo = sf.callNo; |
@@ -625,7 +648,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
625 | object[] oldarray = oldlist.Data; | 648 | object[] oldarray = oldlist.Data; |
626 | int len = oldarray.Length; | 649 | int len = oldarray.Length; |
627 | object[] newarray = new object[len]; | 650 | object[] newarray = new object[len]; |
628 | for (int i = 0; i < len; i ++) { | 651 | for (int i = 0; i < len; i ++) |
652 | { | ||
629 | object obj = oldarray[i]; | 653 | object obj = oldarray[i]; |
630 | if (obj is LSL_Integer) obj = (int)(LSL_Integer)obj; | 654 | if (obj is LSL_Integer) obj = (int)(LSL_Integer)obj; |
631 | newarray[i] = obj; | 655 | newarray[i] = obj; |
@@ -643,18 +667,25 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
643 | int len = oldarray.Length; | 667 | int len = oldarray.Length; |
644 | object[] newarray = new object[len]; | 668 | object[] newarray = new object[len]; |
645 | int verbatim = 0; | 669 | int verbatim = 0; |
646 | for (int i = 0; i < len; i ++) { | 670 | for (int i = 0; i < len; i ++) |
671 | { | ||
647 | object obj = oldarray[i]; | 672 | object obj = oldarray[i]; |
648 | if (-- verbatim < 0) { | 673 | if (-- verbatim < 0) |
649 | if (obj is LSL_Integer) obj = (int)(LSL_Integer)obj; | 674 | { |
650 | if (obj is int) { | 675 | if (obj is LSL_Integer) |
651 | switch ((int)obj) { | 676 | obj = (int)(LSL_Integer)obj; |
652 | case ScriptBaseClass.PARCEL_MEDIA_COMMAND_AUTO_ALIGN: { | 677 | if (obj is int) |
678 | { | ||
679 | switch ((int)obj) | ||
680 | { | ||
681 | case ScriptBaseClass.PARCEL_MEDIA_COMMAND_AUTO_ALIGN: | ||
682 | { | ||
653 | // leave next integer as LSL_Integer | 683 | // leave next integer as LSL_Integer |
654 | verbatim = 1; | 684 | verbatim = 1; |
655 | break; | 685 | break; |
656 | } | 686 | } |
657 | case ScriptBaseClass.PARCEL_MEDIA_COMMAND_SIZE: { | 687 | case ScriptBaseClass.PARCEL_MEDIA_COMMAND_SIZE: |
688 | { | ||
658 | // leave next two integers as LSL_Integer | 689 | // leave next two integers as LSL_Integer |
659 | verbatim = 2; | 690 | verbatim = 2; |
660 | break; | 691 | break; |
@@ -715,7 +746,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
715 | * class that is implementing the interface. This should let the next | 746 | * class that is implementing the interface. This should let the next |
716 | * step get the script-defined type name of the object. | 747 | * step get the script-defined type name of the object. |
717 | */ | 748 | */ |
718 | if (o is Delegate[]) { | 749 | if (o is Delegate[]) |
750 | { | ||
719 | o = ((Delegate[])o)[0].Target; | 751 | o = ((Delegate[])o)[0].Target; |
720 | } | 752 | } |
721 | 753 | ||
@@ -723,7 +755,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
723 | * If script-defined class instance, get the script-defined | 755 | * If script-defined class instance, get the script-defined |
724 | * type name. | 756 | * type name. |
725 | */ | 757 | */ |
726 | if (o is XMRSDTypeClObj) { | 758 | if (o is XMRSDTypeClObj) |
759 | { | ||
727 | return ((XMRSDTypeClObj)o).sdtcClass.longName.val; | 760 | return ((XMRSDTypeClObj)o).sdtcClass.longName.val; |
728 | } | 761 | } |
729 | 762 | ||
@@ -731,7 +764,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
731 | * If it's a delegate, maybe we can look up its script-defined type name. | 764 | * If it's a delegate, maybe we can look up its script-defined type name. |
732 | */ | 765 | */ |
733 | Type ot = o.GetType (); | 766 | Type ot = o.GetType (); |
734 | if (o is Delegate) { | 767 | if (o is Delegate) |
768 | { | ||
735 | String os; | 769 | String os; |
736 | if (m_ObjCode.sdDelTypes.TryGetValue (ot, out os)) return os; | 770 | if (m_ObjCode.sdDelTypes.TryGetValue (ot, out os)) return os; |
737 | } | 771 | } |
@@ -754,7 +788,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
754 | object[] data = ev.Data; | 788 | object[] data = ev.Data; |
755 | int evc = (int)(ev.GetLSLIntegerItem (0).value & 0xFFFFFFFF); | 789 | int evc = (int)(ev.GetLSLIntegerItem (0).value & 0xFFFFFFFF); |
756 | ScriptEventHandler seh = m_ObjCode.scriptEventHandlerTable[stateCode,evc]; | 790 | ScriptEventHandler seh = m_ObjCode.scriptEventHandlerTable[stateCode,evc]; |
757 | if (seh != null) { | 791 | if (seh != null) |
792 | { | ||
758 | int nargs = data.Length - 1; | 793 | int nargs = data.Length - 1; |
759 | object[] args = new object[nargs]; | 794 | object[] args = new object[nargs]; |
760 | Array.Copy (data, 1, args, 0, nargs); | 795 | Array.Copy (data, 1, args, 0, nargs); |
@@ -777,23 +812,30 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
777 | */ | 812 | */ |
778 | public string xmrSubstring (string s, int offset) | 813 | public string xmrSubstring (string s, int offset) |
779 | { | 814 | { |
780 | if (offset >= s.Length) return ""; | 815 | if (offset >= s.Length) |
816 | return ""; | ||
781 | return s.Substring (offset); | 817 | return s.Substring (offset); |
782 | } | 818 | } |
783 | // C# style | 819 | // C# style |
784 | public string xmrSubstring (string s, int offset, int length) | 820 | public string xmrSubstring (string s, int offset, int length) |
785 | { | 821 | { |
786 | if (length <= 0) return ""; | 822 | if (length <= 0) |
787 | if (offset >= s.Length) return ""; | 823 | return ""; |
788 | if (length > s.Length - offset) length = s.Length - offset; | 824 | if (offset >= s.Length) |
825 | return ""; | ||
826 | if (length > s.Length - offset) | ||
827 | length = s.Length - offset; | ||
789 | return s.Substring (offset, length); | 828 | return s.Substring (offset, length); |
790 | } | 829 | } |
791 | // java style | 830 | // java style |
792 | public string xmrJSubstring (string s, int beg, int end) | 831 | public string xmrJSubstring (string s, int beg, int end) |
793 | { | 832 | { |
794 | if (end <= beg) return ""; | 833 | if (end <= beg) |
795 | if (beg >= s.Length) return ""; | 834 | return ""; |
796 | if (end > s.Length) end = s.Length; | 835 | if (beg >= s.Length) |
836 | return ""; | ||
837 | if (end > s.Length) | ||
838 | end = s.Length; | ||
797 | return s.Substring (beg, end - beg); | 839 | return s.Substring (beg, end - beg); |
798 | } | 840 | } |
799 | 841 | ||
@@ -839,22 +881,22 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
839 | public int xmrString2Integer (string s) | 881 | public int xmrString2Integer (string s) |
840 | { | 882 | { |
841 | s = s.Trim (); | 883 | s = s.Trim (); |
842 | if (s.StartsWith ("0x") || s.StartsWith ("0X")) { | 884 | if (s.StartsWith ("0x") || s.StartsWith ("0X")) |
843 | return int.Parse (s.Substring (2), NumberStyles.HexNumber); | 885 | return int.Parse (s.Substring (2), NumberStyles.HexNumber); |
844 | } | 886 | |
845 | return int.Parse (s, CultureInfo.InvariantCulture); | 887 | return int.Parse (s, CultureInfo.InvariantCulture); |
846 | } | 888 | } |
847 | public LSL_Rotation xmrString2Rotation (string s) | 889 | public LSL_Rotation xmrString2Rotation (string s) |
848 | { | 890 | { |
849 | s = s.Trim (); | 891 | s = s.Trim (); |
850 | if (!s.StartsWith ("<") || !s.EndsWith (">")) { | 892 | if (!s.StartsWith ("<") || !s.EndsWith (">")) |
851 | throw new FormatException ("doesn't begin with < and end with >"); | 893 | throw new FormatException ("doesn't begin with < and end with >"); |
852 | } | 894 | |
853 | s = s.Substring (1, s.Length - 2); | 895 | s = s.Substring (1, s.Length - 2); |
854 | string[] splitup = s.Split (justacomma, 5); | 896 | string[] splitup = s.Split (justacomma, 5); |
855 | if (splitup.Length != 4) { | 897 | if (splitup.Length != 4) |
856 | throw new FormatException ("doesn't have exactly 3 commas"); | 898 | throw new FormatException ("doesn't have exactly 3 commas"); |
857 | } | 899 | |
858 | double x = double.Parse (splitup[0], CultureInfo.InvariantCulture); | 900 | double x = double.Parse (splitup[0], CultureInfo.InvariantCulture); |
859 | double y = double.Parse (splitup[1], CultureInfo.InvariantCulture); | 901 | double y = double.Parse (splitup[1], CultureInfo.InvariantCulture); |
860 | double z = double.Parse (splitup[2], CultureInfo.InvariantCulture); | 902 | double z = double.Parse (splitup[2], CultureInfo.InvariantCulture); |
@@ -864,14 +906,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
864 | public LSL_Vector xmrString2Vector (string s) | 906 | public LSL_Vector xmrString2Vector (string s) |
865 | { | 907 | { |
866 | s = s.Trim (); | 908 | s = s.Trim (); |
867 | if (!s.StartsWith ("<") || !s.EndsWith (">")) { | 909 | if (!s.StartsWith ("<") || !s.EndsWith (">")) |
868 | throw new FormatException ("doesn't begin with < and end with >"); | 910 | throw new FormatException ("doesn't begin with < and end with >"); |
869 | } | 911 | |
870 | s = s.Substring (1, s.Length - 2); | 912 | s = s.Substring (1, s.Length - 2); |
871 | string[] splitup = s.Split (justacomma, 4); | 913 | string[] splitup = s.Split (justacomma, 4); |
872 | if (splitup.Length != 3) { | 914 | if (splitup.Length != 3) |
873 | throw new FormatException ("doesn't have exactly 2 commas"); | 915 | throw new FormatException ("doesn't have exactly 2 commas"); |
874 | } | 916 | |
875 | double x = double.Parse (splitup[0], CultureInfo.InvariantCulture); | 917 | double x = double.Parse (splitup[0], CultureInfo.InvariantCulture); |
876 | double y = double.Parse (splitup[1], CultureInfo.InvariantCulture); | 918 | double y = double.Parse (splitup[1], CultureInfo.InvariantCulture); |
877 | double z = double.Parse (splitup[2], CultureInfo.InvariantCulture); | 919 | double z = double.Parse (splitup[2], CultureInfo.InvariantCulture); |
@@ -933,14 +975,14 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
933 | /* | 975 | /* |
934 | * If it is a script-defined interface object, convert to the original XMRSDTypeClObj. | 976 | * If it is a script-defined interface object, convert to the original XMRSDTypeClObj. |
935 | */ | 977 | */ |
936 | if (thrown is Delegate[]) { | 978 | if (thrown is Delegate[]) |
937 | thrown = ((Delegate[])thrown)[0].Target; | 979 | thrown = ((Delegate[])thrown)[0].Target; |
938 | } | ||
939 | 980 | ||
940 | /* | 981 | /* |
941 | * If it is a script-defined delegate object, make sure it is an instance of the expected type. | 982 | * If it is a script-defined delegate object, make sure it is an instance of the expected type. |
942 | */ | 983 | */ |
943 | if (thrown is Delegate) { | 984 | if (thrown is Delegate) |
985 | { | ||
944 | Type ot = thrown.GetType (); | 986 | Type ot = thrown.GetType (); |
945 | Type tt = sdType.GetSysType (); | 987 | Type tt = sdType.GetSysType (); |
946 | return (ot == tt) ? thrown : null; | 988 | return (ot == tt) ? thrown : null; |
@@ -949,15 +991,18 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
949 | /* | 991 | /* |
950 | * If it is a script-defined class object, make sure it is an instance of the expected class. | 992 | * If it is a script-defined class object, make sure it is an instance of the expected class. |
951 | */ | 993 | */ |
952 | if (thrown is XMRSDTypeClObj) { | 994 | if (thrown is XMRSDTypeClObj) |
995 | { | ||
953 | 996 | ||
954 | /* | 997 | /* |
955 | * Step from the object's actual class rootward. | 998 | * Step from the object's actual class rootward. |
956 | * If we find the requested class along the way, the cast is valid. | 999 | * If we find the requested class along the way, the cast is valid. |
957 | * If we run off the end of the root, the cast is not valid. | 1000 | * If we run off the end of the root, the cast is not valid. |
958 | */ | 1001 | */ |
959 | for (TokenDeclSDTypeClass ac = ((XMRSDTypeClObj)thrown).sdtcClass; ac != null; ac = ac.extends) { | 1002 | for (TokenDeclSDTypeClass ac = ((XMRSDTypeClObj)thrown).sdtcClass; ac != null; ac = ac.extends) |
960 | if (ac == sdType) return thrown; | 1003 | { |
1004 | if (ac == sdType) | ||
1005 | return thrown; | ||
961 | } | 1006 | } |
962 | } | 1007 | } |
963 | 1008 | ||
@@ -1015,10 +1060,11 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1015 | */ | 1060 | */ |
1016 | int i = srctypename.IndexOf ('['); | 1061 | int i = srctypename.IndexOf ('['); |
1017 | int j = dsttypename.IndexOf ('['); | 1062 | int j = dsttypename.IndexOf ('['); |
1018 | if ((i < 0) || (j < 0)) throw new InvalidCastException ("non-array passed: " + srctypename + " and/or " + dsttypename); | 1063 | if ((i < 0) || (j < 0)) |
1019 | if ((i != j) || !srctypename.StartsWith (dsttypename.Substring (0, j))) { | 1064 | throw new InvalidCastException ("non-array passed: " + srctypename + " and/or " + dsttypename); |
1065 | if ((i != j) || !srctypename.StartsWith (dsttypename.Substring (0, j))) | ||
1020 | throw new ArrayTypeMismatchException (srctypename + " vs " + dsttypename); | 1066 | throw new ArrayTypeMismatchException (srctypename + " vs " + dsttypename); |
1021 | } | 1067 | |
1022 | 1068 | ||
1023 | /* | 1069 | /* |
1024 | * The number of brackets must match exactly. | 1070 | * The number of brackets must match exactly. |
@@ -1030,11 +1076,15 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1030 | int dstlen = dsttypename.Length; | 1076 | int dstlen = dsttypename.Length; |
1031 | int srcjags = 0; | 1077 | int srcjags = 0; |
1032 | int dstjags = 0; | 1078 | int dstjags = 0; |
1033 | while (++ i < srclen) if (srctypename[i] == ']') srcjags ++; | 1079 | while (++ i < srclen) |
1034 | while (++ j < dstlen) if (dsttypename[j] == ']') dstjags ++; | 1080 | if (srctypename[i] == ']') |
1035 | if (dstjags != srcjags) { | 1081 | srcjags ++; |
1082 | while (++ j < dstlen) | ||
1083 | if (dsttypename[j] == ']') | ||
1084 | dstjags ++; | ||
1085 | if (dstjags != srcjags) | ||
1036 | throw new ArrayTypeMismatchException (srctypename + " vs " + dsttypename); | 1086 | throw new ArrayTypeMismatchException (srctypename + " vs " + dsttypename); |
1037 | } | 1087 | |
1038 | 1088 | ||
1039 | /* | 1089 | /* |
1040 | * Perform the copy. | 1090 | * Perform the copy. |
@@ -1059,9 +1109,9 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1059 | */ | 1109 | */ |
1060 | XMRSDTypeClObj array = (XMRSDTypeClObj)srcar; | 1110 | XMRSDTypeClObj array = (XMRSDTypeClObj)srcar; |
1061 | TokenDeclSDTypeClass sdtClass = array.sdtcClass; | 1111 | TokenDeclSDTypeClass sdtClass = array.sdtcClass; |
1062 | if (sdtClass.arrayOfRank == 0) { | 1112 | if (sdtClass.arrayOfRank == 0) |
1063 | throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); | 1113 | throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); |
1064 | } | 1114 | |
1065 | 1115 | ||
1066 | /* | 1116 | /* |
1067 | * Validate objects they want to put in the list. | 1117 | * Validate objects they want to put in the list. |
@@ -1069,26 +1119,33 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1069 | */ | 1119 | */ |
1070 | Array srcarray = (Array)array.instVars.iarObjects[0]; | 1120 | Array srcarray = (Array)array.instVars.iarObjects[0]; |
1071 | object[] output = new object[count]; | 1121 | object[] output = new object[count]; |
1072 | for (int i = 0; i < count; i ++) { | 1122 | for (int i = 0; i < count; i ++) |
1123 | { | ||
1073 | object src = srcarray.GetValue (i + start); | 1124 | object src = srcarray.GetValue (i + start); |
1074 | if (src == null) throw new NullReferenceException ("null element " + i); | 1125 | if (src == null) |
1075 | if (src is double) { | 1126 | throw new NullReferenceException ("null element " + i); |
1127 | if (src is double) | ||
1128 | { | ||
1076 | output[i] = new LSL_Float ((double)src); | 1129 | output[i] = new LSL_Float ((double)src); |
1077 | continue; | 1130 | continue; |
1078 | } | 1131 | } |
1079 | if (src is int) { | 1132 | if (src is int) |
1133 | { | ||
1080 | output[i] = new LSL_Integer ((int)src); | 1134 | output[i] = new LSL_Integer ((int)src); |
1081 | continue; | 1135 | continue; |
1082 | } | 1136 | } |
1083 | if (src is LSL_Rotation) { | 1137 | if (src is LSL_Rotation) |
1138 | { | ||
1084 | output[i] = src; | 1139 | output[i] = src; |
1085 | continue; | 1140 | continue; |
1086 | } | 1141 | } |
1087 | if (src is LSL_Vector) { | 1142 | if (src is LSL_Vector) |
1143 | { | ||
1088 | output[i] = src; | 1144 | output[i] = src; |
1089 | continue; | 1145 | continue; |
1090 | } | 1146 | } |
1091 | if (src is string) { | 1147 | if (src is string) |
1148 | { | ||
1092 | output[i] = new LSL_String ((string)src); | 1149 | output[i] = new LSL_String ((string)src); |
1093 | continue; | 1150 | continue; |
1094 | } | 1151 | } |
@@ -1117,9 +1174,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1117 | */ | 1174 | */ |
1118 | XMRSDTypeClObj dstarray = (XMRSDTypeClObj)dstobj; | 1175 | XMRSDTypeClObj dstarray = (XMRSDTypeClObj)dstobj; |
1119 | TokenDeclSDTypeClass sdtClass = dstarray.sdtcClass; | 1176 | TokenDeclSDTypeClass sdtClass = dstarray.sdtcClass; |
1120 | if (sdtClass.arrayOfType == null) { | 1177 | if (sdtClass.arrayOfType == null) |
1121 | throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); | 1178 | throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); |
1122 | } | ||
1123 | 1179 | ||
1124 | /* | 1180 | /* |
1125 | * Copy from the immutable array to the mutable array. | 1181 | * Copy from the immutable array to the mutable array. |
@@ -1128,11 +1184,12 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1128 | object[] srcarr = srclist.Data; | 1184 | object[] srcarr = srclist.Data; |
1129 | Array dstarr = (Array)dstarray.instVars.iarObjects[0]; | 1185 | Array dstarr = (Array)dstarray.instVars.iarObjects[0]; |
1130 | 1186 | ||
1131 | for (int i = 0; i < count; i ++) { | 1187 | for (int i = 0; i < count; i ++) |
1188 | { | ||
1132 | object obj = srcarr[i+srcstart]; | 1189 | object obj = srcarr[i+srcstart]; |
1133 | if (obj is LSL_Float) obj = ((LSL_Float)obj).value; | 1190 | if (obj is LSL_Float) obj = ((LSL_Float)obj).value; |
1134 | if (obj is LSL_Integer) obj = ((LSL_Integer)obj).value; | 1191 | else if (obj is LSL_Integer) obj = ((LSL_Integer)obj).value; |
1135 | if (obj is LSL_String) obj = ((LSL_String)obj).m_string; | 1192 | else if (obj is LSL_String) obj = ((LSL_String)obj).m_string; |
1136 | dstarr.SetValue (obj, i + dststart); | 1193 | dstarr.SetValue (obj, i + dststart); |
1137 | } | 1194 | } |
1138 | } | 1195 | } |
@@ -1151,9 +1208,8 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1151 | */ | 1208 | */ |
1152 | XMRSDTypeClObj array = (XMRSDTypeClObj)srcar; | 1209 | XMRSDTypeClObj array = (XMRSDTypeClObj)srcar; |
1153 | TokenDeclSDTypeClass sdtClass = array.sdtcClass; | 1210 | TokenDeclSDTypeClass sdtClass = array.sdtcClass; |
1154 | if (sdtClass.arrayOfRank == 0) { | 1211 | if (sdtClass.arrayOfRank == 0) |
1155 | throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); | 1212 | throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); |
1156 | } | ||
1157 | 1213 | ||
1158 | /* | 1214 | /* |
1159 | * We get a type cast error from mono if they didn't give us a character array. | 1215 | * We get a type cast error from mono if they didn't give us a character array. |
@@ -1178,18 +1234,16 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1178 | */ | 1234 | */ |
1179 | XMRSDTypeClObj dstarray = (XMRSDTypeClObj)dstobj; | 1235 | XMRSDTypeClObj dstarray = (XMRSDTypeClObj)dstobj; |
1180 | TokenDeclSDTypeClass sdtClass = dstarray.sdtcClass; | 1236 | TokenDeclSDTypeClass sdtClass = dstarray.sdtcClass; |
1181 | if (sdtClass.arrayOfType == null) { | 1237 | if (sdtClass.arrayOfType == null) |
1182 | throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); | 1238 | throw new InvalidCastException ("only do arrays not " + sdtClass.longName.val); |
1183 | } | ||
1184 | 1239 | ||
1185 | /* | 1240 | /* |
1186 | * We get a type cast error from mono if they didn't give us a character array. | 1241 | * We get a type cast error from mono if they didn't give us a character array. |
1187 | * But if it is ok, copy from the string to the character array. | 1242 | * But if it is ok, copy from the string to the character array. |
1188 | */ | 1243 | */ |
1189 | char[] dstarr = (char[])dstarray.instVars.iarObjects[0]; | 1244 | char[] dstarr = (char[])dstarray.instVars.iarObjects[0]; |
1190 | for (int i = 0; i < count; i ++) { | 1245 | for (int i = 0; i < count; i ++) |
1191 | dstarr[i+dststart] = srcstr[i+srcstart]; | 1246 | dstarr[i+dststart] = srcstr[i+srcstart]; |
1192 | } | ||
1193 | } | 1247 | } |
1194 | 1248 | ||
1195 | /** | 1249 | /** |
@@ -1202,8 +1256,10 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1202 | { | 1256 | { |
1203 | XMR_Array dict = new XMR_Array (this); | 1257 | XMR_Array dict = new XMR_Array (this); |
1204 | int idx = ParseJSON (dict, nullList, json, 0); | 1258 | int idx = ParseJSON (dict, nullList, json, 0); |
1205 | while (idx < json.Length) { | 1259 | while (idx < json.Length) |
1206 | if (json[idx] > ' ') throw new Exception ("left-over json " + json); | 1260 | { |
1261 | if (json[idx] > ' ') | ||
1262 | throw new Exception ("left-over json " + json); | ||
1207 | idx ++; | 1263 | idx ++; |
1208 | } | 1264 | } |
1209 | return dict; | 1265 | return dict; |
@@ -1214,35 +1270,46 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1214 | char c; | 1270 | char c; |
1215 | 1271 | ||
1216 | while ((c = json[idx++]) <= ' ') { } | 1272 | while ((c = json[idx++]) <= ' ') { } |
1217 | switch (c) { | 1273 | switch (c) |
1274 | { | ||
1218 | 1275 | ||
1219 | // '{' <keystring> ':' <value> [ ',' <keystring> ':' <value> ... ] '}' | 1276 | // '{' <keystring> ':' <value> [ ',' <keystring> ':' <value> ... ] '}' |
1220 | case '{': { | 1277 | case '{': |
1221 | do { | 1278 | { |
1279 | do | ||
1280 | { | ||
1222 | string key = ParseJSONString (json, ref idx); | 1281 | string key = ParseJSONString (json, ref idx); |
1223 | while ((c = json[idx++]) <= ' ') { } | 1282 | while ((c = json[idx++]) <= ' ') { } |
1224 | if (c != ':') throw new Exception ("missing : after key"); | 1283 | if (c != ':') |
1284 | throw new Exception ("missing : after key"); | ||
1225 | idx = ParseJSON (dict, ParseJSONKeyAdd (keys, key), json, idx); | 1285 | idx = ParseJSON (dict, ParseJSONKeyAdd (keys, key), json, idx); |
1226 | while ((c = json[idx++]) <= ' ') { } | 1286 | while ((c = json[idx++]) <= ' ') { } |
1227 | } while (c == ','); | 1287 | } while (c == ','); |
1228 | if (c != '}') throw new Exception ("missing , or } after value"); | 1288 | |
1289 | if (c != '}') | ||
1290 | throw new Exception ("missing , or } after value"); | ||
1229 | break; | 1291 | break; |
1230 | } | 1292 | } |
1231 | 1293 | ||
1232 | // '[' <value> [ ',' <value> ... ] ']' | 1294 | // '[' <value> [ ',' <value> ... ] ']' |
1233 | case '[': { | 1295 | case '[': |
1296 | { | ||
1234 | int index = 0; | 1297 | int index = 0; |
1235 | do { | 1298 | do |
1299 | { | ||
1236 | object key = index ++; | 1300 | object key = index ++; |
1237 | idx = ParseJSON (dict, ParseJSONKeyAdd (keys, key), json, idx); | 1301 | idx = ParseJSON (dict, ParseJSONKeyAdd (keys, key), json, idx); |
1238 | while ((c = json[idx++]) <= ' ') { } | 1302 | while ((c = json[idx++]) <= ' ') { } |
1239 | } while (c == ','); | 1303 | } while (c == ','); |
1240 | if (c != ']') throw new Exception ("missing , or ] after value"); | 1304 | |
1305 | if (c != ']') | ||
1306 | throw new Exception ("missing , or ] after value"); | ||
1241 | break; | 1307 | break; |
1242 | } | 1308 | } |
1243 | 1309 | ||
1244 | // '"'<string>'"' | 1310 | // '"'<string>'"' |
1245 | case '"': { | 1311 | case '"': |
1312 | { | ||
1246 | -- idx; | 1313 | -- idx; |
1247 | string val = ParseJSONString (json, ref idx); | 1314 | string val = ParseJSONString (json, ref idx); |
1248 | dict.SetByKey (keys, val); | 1315 | dict.SetByKey (keys, val); |
@@ -1250,29 +1317,36 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1250 | } | 1317 | } |
1251 | 1318 | ||
1252 | // true false null | 1319 | // true false null |
1253 | case 't': { | 1320 | case 't': |
1254 | if (json.Substring (idx, 3) != "rue") throw new Exception ("bad true in json"); | 1321 | { |
1322 | if (json.Substring (idx, 3) != "rue") | ||
1323 | throw new Exception ("bad true in json"); | ||
1255 | idx += 3; | 1324 | idx += 3; |
1256 | dict.SetByKey (keys, 1); | 1325 | dict.SetByKey (keys, 1); |
1257 | break; | 1326 | break; |
1258 | } | 1327 | } |
1259 | 1328 | ||
1260 | case 'f': { | 1329 | case 'f': |
1261 | if (json.Substring (idx, 4) != "alse") throw new Exception ("bad false in json"); | 1330 | { |
1331 | if (json.Substring (idx, 4) != "alse") | ||
1332 | throw new Exception ("bad false in json"); | ||
1262 | idx += 4; | 1333 | idx += 4; |
1263 | dict.SetByKey (keys, 0); | 1334 | dict.SetByKey (keys, 0); |
1264 | break; | 1335 | break; |
1265 | } | 1336 | } |
1266 | 1337 | ||
1267 | case 'n': { | 1338 | case 'n': |
1268 | if (json.Substring (idx, 3) != "ull") throw new Exception ("bad null in json"); | 1339 | { |
1340 | if (json.Substring (idx, 3) != "ull") | ||
1341 | throw new Exception ("bad null in json"); | ||
1269 | idx += 3; | 1342 | idx += 3; |
1270 | dict.SetByKey (keys, null); | 1343 | dict.SetByKey (keys, null); |
1271 | break; | 1344 | break; |
1272 | } | 1345 | } |
1273 | 1346 | ||
1274 | // otherwise assume it's a number | 1347 | // otherwise assume it's a number |
1275 | default: { | 1348 | default: |
1349 | { | ||
1276 | -- idx; | 1350 | -- idx; |
1277 | object val = ParseJSONNumber (json, ref idx); | 1351 | object val = ParseJSONNumber (json, ref idx); |
1278 | dict.SetByKey (keys, val); | 1352 | dict.SetByKey (keys, val); |
@@ -1302,36 +1376,39 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1302 | if (c != '"') throw new Exception ("bad start of json string"); | 1376 | if (c != '"') throw new Exception ("bad start of json string"); |
1303 | 1377 | ||
1304 | StringBuilder sb = new StringBuilder (); | 1378 | StringBuilder sb = new StringBuilder (); |
1305 | while ((c = json[idx++]) != '"') { | 1379 | while ((c = json[idx++]) != '"') |
1306 | if (c == '\\') { | 1380 | { |
1381 | if (c == '\\') | ||
1382 | { | ||
1307 | c = json[idx++]; | 1383 | c = json[idx++]; |
1308 | switch (c) { | 1384 | switch (c) |
1309 | case 'b': { | 1385 | { |
1386 | case 'b': | ||
1310 | c = '\b'; | 1387 | c = '\b'; |
1311 | break; | 1388 | break; |
1312 | } | 1389 | |
1313 | case 'f': { | 1390 | case 'f': |
1314 | c = '\f'; | 1391 | c = '\f'; |
1315 | break; | 1392 | break; |
1316 | } | 1393 | |
1317 | case 'n': { | 1394 | case 'n': |
1318 | c = '\n'; | 1395 | c = '\n'; |
1319 | break; | 1396 | break; |
1320 | } | 1397 | |
1321 | case 'r': { | 1398 | case 'r': |
1322 | c = '\r'; | 1399 | c = '\r'; |
1323 | break; | 1400 | break; |
1324 | } | 1401 | |
1325 | case 't': { | 1402 | case 't': |
1326 | c = '\t'; | 1403 | c = '\t'; |
1327 | break; | 1404 | break; |
1328 | } | 1405 | |
1329 | case 'u': { | 1406 | case 'u': |
1330 | c = (char) Int32.Parse (json.Substring (idx, 4), | 1407 | c = (char) Int32.Parse (json.Substring (idx, 4), |
1331 | System.Globalization.NumberStyles.HexNumber); | 1408 | System.Globalization.NumberStyles.HexNumber); |
1332 | idx += 4; | 1409 | idx += 4; |
1333 | break; | 1410 | break; |
1334 | } | 1411 | |
1335 | default: break; | 1412 | default: break; |
1336 | } | 1413 | } |
1337 | } | 1414 | } |
@@ -1358,49 +1435,65 @@ namespace OpenSim.Region.ScriptEngine.XMREngine | |||
1358 | isneg = true; | 1435 | isneg = true; |
1359 | c = json[idx++]; | 1436 | c = json[idx++]; |
1360 | } | 1437 | } |
1361 | if ((c < '0') || (c > '9')) { | 1438 | if ((c < '0') || (c > '9')) |
1362 | throw new Exception ("bad json number"); | 1439 | throw new Exception ("bad json number"); |
1363 | } | 1440 | |
1364 | while ((c >= '0') && (c <= '9')) { | 1441 | while ((c >= '0') && (c <= '9')) |
1442 | { | ||
1365 | dval *= 10; | 1443 | dval *= 10; |
1366 | ival *= 10; | 1444 | ival *= 10; |
1367 | dval += c - '0'; | 1445 | dval += c - '0'; |
1368 | ival += c - '0'; | 1446 | ival += c - '0'; |
1369 | c = '\0'; | 1447 | c = '\0'; |
1370 | if (idx < json.Length) c = json[idx++]; | 1448 | if (idx < json.Length) |
1449 | c = json[idx++]; | ||
1371 | } | 1450 | } |
1372 | if (c == '.') { | 1451 | if (c == '.') |
1452 | { | ||
1373 | decpt = 0; | 1453 | decpt = 0; |
1374 | c = '\0'; | 1454 | c = '\0'; |
1375 | if (idx < json.Length) c = json[idx++]; | 1455 | if (idx < json.Length) |
1456 | c = json[idx++]; | ||
1376 | while ((c >= '0') && (c <= '9')) { | 1457 | while ((c >= '0') && (c <= '9')) { |
1377 | dval *= 10; | 1458 | dval *= 10; |
1378 | dval += c - '0'; | 1459 | dval += c - '0'; |
1379 | decpt ++; | 1460 | decpt ++; |
1380 | c = '\0'; | 1461 | c = '\0'; |
1381 | if (idx < json.Length) c = json[idx++]; | 1462 | if (idx < json.Length) |
1463 | c = json[idx++]; | ||
1382 | } | 1464 | } |
1383 | } | 1465 | } |
1384 | if ((c == 'e') || (c == 'E')) { | 1466 | if ((c == 'e') || (c == 'E')) |
1385 | if (decpt < 0) decpt = 0; | 1467 | { |
1468 | if (decpt < 0) | ||
1469 | decpt = 0; | ||
1386 | c = json[idx++]; | 1470 | c = json[idx++]; |
1387 | if (c == '-') expneg = true; | 1471 | if (c == '-') |
1388 | if ((c == '-') || (c == '+')) c = json[idx++]; | 1472 | expneg = true; |
1389 | while ((c >= '0') && (c <= '9')) { | 1473 | if ((c == '-') || (c == '+')) |
1474 | c = json[idx++]; | ||
1475 | while ((c >= '0') && (c <= '9')) | ||
1476 | { | ||
1390 | expon *= 10; | 1477 | expon *= 10; |
1391 | expon += c - '0'; | 1478 | expon += c - '0'; |
1392 | c = '\0'; | 1479 | c = '\0'; |
1393 | if (idx < json.Length) c = json[idx++]; | 1480 | if (idx < json.Length) |
1481 | c = json[idx++]; | ||
1394 | } | 1482 | } |
1395 | if (expneg) expon = -expon; | 1483 | if (expneg) |
1484 | expon = -expon; | ||
1396 | } | 1485 | } |
1397 | 1486 | ||
1398 | if (c != 0) -- idx; | 1487 | if (c != 0) |
1399 | if (decpt < 0) { | 1488 | --idx; |
1400 | if (isneg) ival = -ival; | 1489 | if (decpt < 0) |
1490 | { | ||
1491 | if (isneg) | ||
1492 | ival = -ival; | ||
1401 | return ival; | 1493 | return ival; |
1402 | } else { | 1494 | } else { |
1403 | if (isneg) dval = -dval; | 1495 | if (isneg) |
1496 | dval = -dval; | ||
1404 | dval *= Math.Pow (10, expon - decpt); | 1497 | dval *= Math.Pow (10, expon - decpt); |
1405 | return dval; | 1498 | return dval; |
1406 | } | 1499 | } |