aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs47
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs8
2 files changed, 34 insertions, 21 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 91cef5e..d107d90 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -1353,16 +1353,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1353 1353
1354 public static explicit operator LSLInteger(LSLString s) 1354 public static explicit operator LSLInteger(LSLString s)
1355 { 1355 {
1356 Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*"); 1356 return new LSLInteger(s.m_string);
1357 Match m = r.Match(s);
1358 string v = m.Groups[0].Value;
1359
1360 if (v == String.Empty)
1361 v = "0";
1362
1363 if (v.Contains("x") || v.Contains("X"))
1364 return new LSLInteger(int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber));
1365 return new LSLInteger(int.Parse(v, System.Globalization.NumberStyles.Integer));
1366 } 1357 }
1367 1358
1368 public static explicit operator LSLString(double d) 1359 public static explicit operator LSLString(double d)
@@ -1445,7 +1436,30 @@ namespace OpenSim.Region.ScriptEngine.Shared
1445 1436
1446 public LSLInteger(string s) 1437 public LSLInteger(string s)
1447 { 1438 {
1448 value = (int)double.Parse(s); 1439 Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*");
1440 Match m = r.Match(s);
1441 string v = m.Groups[0].Value;
1442
1443 if (v == String.Empty)
1444 {
1445 value = 0;
1446 }
1447 else
1448 {
1449 try
1450 {
1451 if (v.Contains("x") || v.Contains("X"))
1452 value = int.Parse(v.Substring(2),
1453 System.Globalization.NumberStyles.HexNumber);
1454 else
1455 value = int.Parse(v,
1456 System.Globalization.NumberStyles.Integer);
1457 }
1458 catch (OverflowException oe)
1459 {
1460 value = -1;
1461 }
1462 }
1449 } 1463 }
1450 1464
1451 #endregion 1465 #endregion
@@ -1486,16 +1500,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1486 1500
1487 static public explicit operator LSLInteger(string s) 1501 static public explicit operator LSLInteger(string s)
1488 { 1502 {
1489 Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*"); 1503 return new LSLInteger(s);
1490 Match m = r.Match(s);
1491 string v = m.Groups[0].Value;
1492
1493 if (v == String.Empty)
1494 v = "0";
1495
1496 if (v.Contains("x") || v.Contains("X"))
1497 return new LSLInteger(int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber));
1498 return new LSLInteger(int.Parse(v, System.Globalization.NumberStyles.Integer));
1499 } 1504 }
1500 1505
1501 static public implicit operator LSLInteger(uint u) 1506 static public implicit operator LSLInteger(uint u)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
index f826c00..957a3b6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
@@ -62,6 +62,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
62 m_stringIntSet.Add("123.9", 123); 62 m_stringIntSet.Add("123.9", 123);
63 m_stringIntSet.Add("999999999", 999999999); 63 m_stringIntSet.Add("999999999", 999999999);
64 m_stringIntSet.Add("-99999999", -99999999); 64 m_stringIntSet.Add("-99999999", -99999999);
65 m_stringIntSet.Add("", 0);
66 m_stringIntSet.Add("aa", 0);
67 m_stringIntSet.Add("42", 42);
68 m_stringIntSet.Add("42 is the answer", 42);
69 m_stringIntSet.Add(" 42", 42);
70 m_stringIntSet.Add("42,123,456", 42);
71 m_stringIntSet.Add("0xff", 255);
72 m_stringIntSet.Add("12345678900000", -1);
65 } 73 }
66 74
67 /// <summary> 75 /// <summary>