diff options
author | Charles Krinke | 2008-01-12 22:25:10 +0000 |
---|---|---|
committer | Charles Krinke | 2008-01-12 22:25:10 +0000 |
commit | fa83249db81da9204affd1af9f2834e541bea93d (patch) | |
tree | 588ef5b242c139eb3112bedca6fa2ab85ff609d8 /OpenSim | |
parent | Thank you, Kinoc for adding: When accessing slower web sites or proxy services (diff) | |
download | opensim-SC-fa83249db81da9204affd1af9f2834e541bea93d.zip opensim-SC-fa83249db81da9204affd1af9f2834e541bea93d.tar.gz opensim-SC-fa83249db81da9204affd1af9f2834e541bea93d.tar.bz2 opensim-SC-fa83249db81da9204affd1af9f2834e541bea93d.tar.xz |
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?
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 41 |
1 files changed, 35 insertions, 6 deletions
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 | |||
907 | } | 907 | } |
908 | 908 | ||
909 | public string llGetSubString(string src, int start, int end) | 909 | public string llGetSubString(string src, int start, int end) |
910 | { | 910 | { |
911 | return src.Substring(start, end); | 911 | // substring expects length |
912 | } | 912 | // return src.Substring(start, end); |
913 | |||
914 | // if one is negative so use length of string as base | ||
915 | // if start > end then it is exclusive | ||
916 | // for length add +1 for char at location=0 | ||
917 | if (start < 0) { start = src.Length-start; } | ||
918 | if (end < 0) { end = src.Length - end; } | ||
919 | if (start > end) | ||
920 | { | ||
921 | return src.Substring(0, 1+end) + src.Substring(start, src.Length - start); | ||
922 | } | ||
923 | else | ||
924 | { | ||
925 | return src.Substring(start, (1+end) - start); | ||
926 | } | ||
927 | } | ||
913 | 928 | ||
914 | public string llDeleteSubString(string src, int start, int end) | 929 | public string llDeleteSubString(string src, int start, int end) |
915 | { | 930 | { |
916 | return src.Remove(start, end - start); | 931 | //return src.Remove(start, end - start); |
932 | // if one is negative so use length of string as base | ||
933 | // if start > end then it is exclusive | ||
934 | // for length add +1 for char at location=0 | ||
935 | if (start < 0) { start = src.Length - start; } | ||
936 | if (end < 0) { end = src.Length - end; } | ||
937 | if (start > end) | ||
938 | { | ||
939 | return src.Remove(0, 1 + end) + src.Remove(start, src.Length - start); | ||
940 | } | ||
941 | else | ||
942 | { | ||
943 | return src.Remove(start, (1 + end) - start); | ||
944 | } | ||
917 | } | 945 | } |
918 | 946 | ||
947 | |||
919 | public string llInsertString(string dst, int position, string src) | 948 | public string llInsertString(string dst, int position, string src) |
920 | { | 949 | { |
921 | return dst.Insert(position, src); | 950 | return dst.Insert(position, src); |