aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs33
-rw-r--r--OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs8
2 files changed, 36 insertions, 5 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index 8c24ae3..5bfe8bf 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -1269,8 +1269,7 @@ namespace OpenSim.Region.ScriptEngine.Common
1269 1269
1270 public static explicit operator LSLInteger(LSLString s) 1270 public static explicit operator LSLInteger(LSLString s)
1271 { 1271 {
1272 // double.Parse() used because s could be "123.9" for example. 1272 return new LSLInteger(s.m_string);
1273 return new LSLInteger(double.Parse(s.m_string));
1274 } 1273 }
1275 1274
1276 public static explicit operator LSLString(double d) 1275 public static explicit operator LSLString(double d)
@@ -1353,7 +1352,32 @@ namespace OpenSim.Region.ScriptEngine.Common
1353 1352
1354 public LSLInteger(string s) 1353 public LSLInteger(string s)
1355 { 1354 {
1356 value = (int)double.Parse(s); 1355 Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*");
1356 Match m = r.Match(s);
1357 string v = m.Groups[0].Value;
1358
1359 if (v == String.Empty)
1360 {
1361 value = 0;
1362 }
1363 else
1364 {
1365 try
1366 {
1367 if (v.Contains("x") || v.Contains("X"))
1368 {
1369 value = int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber);
1370 }
1371 else
1372 {
1373 value = int.Parse(v, System.Globalization.NumberStyles.Integer);
1374 }
1375 }
1376 catch (OverflowException oe)
1377 {
1378 value = -1;
1379 }
1380 }
1357 } 1381 }
1358 1382
1359 #endregion 1383 #endregion
@@ -1394,8 +1418,7 @@ namespace OpenSim.Region.ScriptEngine.Common
1394 1418
1395 static public explicit operator LSLInteger(string s) 1419 static public explicit operator LSLInteger(string s)
1396 { 1420 {
1397 // double.Parse() used because s could be "123.9" for example. 1421 return new LSLInteger(s);
1398 return new LSLInteger(double.Parse(s));
1399 } 1422 }
1400 1423
1401 static public implicit operator LSLInteger(uint u) 1424 static public implicit operator LSLInteger(uint u)
diff --git a/OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs b/OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs
index d2839db..a769608 100644
--- a/OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs
+++ b/OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs
@@ -62,6 +62,14 @@ namespace OpenSim.Region.ScriptEngine.Common.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>