From fa83249db81da9204affd1af9f2834e541bea93d Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sat, 12 Jan 2008 22:25:10 +0000 Subject: Thank you very much, Kinoc for implementing llGetSubString and llDeleteSubString: from the c# implementations of string.SubString(start,len) and string.Remove(start,len). Especially since negative indexing and exclusion are included in the LSL versions. This patch is closer to the LSL version. Maybe an osSubString and osRemoveString would be appropriate? --- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 41 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index f5354c5..4cceb5f 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -907,15 +907,44 @@ namespace OpenSim.Region.ScriptEngine.Common } public string llGetSubString(string src, int start, int end) - { - return src.Substring(start, end); - } + { + // substring expects length + // return src.Substring(start, end); + + // if one is negative so use length of string as base + // if start > end then it is exclusive + // for length add +1 for char at location=0 + if (start < 0) { start = src.Length-start; } + if (end < 0) { end = src.Length - end; } + if (start > end) + { + return src.Substring(0, 1+end) + src.Substring(start, src.Length - start); + } + else + { + return src.Substring(start, (1+end) - start); + } + } public string llDeleteSubString(string src, int start, int end) - { - return src.Remove(start, end - start); + { + //return src.Remove(start, end - start); + // if one is negative so use length of string as base + // if start > end then it is exclusive + // for length add +1 for char at location=0 + if (start < 0) { start = src.Length - start; } + if (end < 0) { end = src.Length - end; } + if (start > end) + { + return src.Remove(0, 1 + end) + src.Remove(start, src.Length - start); + } + else + { + return src.Remove(start, (1 + end) - start); + } } - + + public string llInsertString(string dst, int position, string src) { return dst.Insert(position, src); -- cgit v1.1