aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--lib/LSL.lua99
1 files changed, 95 insertions, 4 deletions
diff --git a/lib/LSL.lua b/lib/LSL.lua
index 09f6ba8..d61457b 100644
--- a/lib/LSL.lua
+++ b/lib/LSL.lua
@@ -700,8 +700,101 @@ function --[[list]] LSL.llListSort(--[[list]] l,--[[integer]] stride,--[[integer
700 return result 700 return result
701end 701end
702 702
703--function --[[list]] LSL.llParseString2List(--[[string]] In, --[[list]] l, --[[list]] l1) return {} end; 703function --[[list]] LSL.llParseStringKeepNulls(--[[string]] In, --[[list]] l, --[[list]] l1)
704--function --[[list]] LSL.llParseStringKeepNulls(--[[string]] In, --[[list]] l, --[[list]] l1) return {} end; 704 local result = {}
705 local temp = {}
706 local len = #l
707 local slen = string.len(In)
708 local b = 1
709 local c = 1
710 local lastE = 0
711
712print("LSL.llParseStringKeepNulls(" .. In .. ") " .. #In)
713for i, v in ipairs(l) do
714 print(" [" .. v .. "]")
715end
716print(",")
717for i, v in ipairs(l1) do
718 print(" {" .. v .. "}")
719end
720
721 -- Start scanning at the beginning of the string.
722 repeat
723 local f = {slen, -slen, 0}
724 local t = l
725
726 -- Search for the first of all the matches.
727 for j = 1, len + #l1 do
728 local k = j
729
730 if j > len then t = l1; k = j - len end
731 local s, e = string.find(In, t[j], b, true)
732 if s then
733 if s < f[1] then
734 f = {s, e, j}
735 lastE = e
736 end
737 end
738 end
739
740 -- We found at least one of them, save it.
741 if f[2] > 0 then
742 temp[c] = {b, f[1] - 1}
743 -- Split at and keep spacers.
744 if f[3] > len then
745 c = c + 1
746 temp[c] = {f[1], f[2]}
747 end
748 c = c + 1
749 b = f[2]
750 end
751
752 -- Continue on from the next character, possibly after the match.
753 b = b + 1
754 until b >= slen
755
756 -- Save any left over, including the entire string if no matches found.
757 if lastE < slen then
758 temp[c] = {lastE + 1, slen}
759 end
760
761 -- Sort the findings.
762 table.sort(temp, function(a, b) return a[1] < b[1] end)
763
764 -- Construct the result.
765 for i, v in ipairs(temp) do
766 result[i] = string.sub(In, v[1], v[2])
767 end
768
769print("RESULT = ")
770for i, v in ipairs(result) do
771 print(" {" .. v .. "}")
772end
773
774 return result
775end
776
777function --[[list]] LSL.llParseString2List(--[[string]] In, --[[list]] l, --[[list]] l1)
778 local temp = LSL.llParseStringKeepNulls(--[[string]] In, --[[list]] l, --[[list]] l1)
779 local result = {}
780 local c = 1
781
782 -- Strip out the NULLS.
783 for i, v in ipairs(temp) do
784 if "" ~= v then
785 result[c] = v
786 c = c + 1
787 end
788 end
789
790print("RESULT SANS NULLS = ")
791for i, v in ipairs(result) do
792 print(" {" .. v .. "}")
793end
794
795 return result
796end
797
705 798
706 799
707-- LSL script functions 800-- LSL script functions
@@ -722,8 +815,6 @@ function --[[string]] LSL.llGetSubString(--[[string]] text, --[[integer]] start,
722end 815end
723 816
724function --[[integer]] LSL.llSubStringIndex(--[[string]] text, --[[string]] sub) 817function --[[integer]] LSL.llSubStringIndex(--[[string]] text, --[[string]] sub)
725 if nil == text then return -1 end
726 if nil == sub then return -1 end
727 local start, End = string.find(text, sub, 1, true) 818 local start, End = string.find(text, sub, 1, true)
728 819
729 if nil == start then return -1 else return start - 1 end 820 if nil == start then return -1 else return start - 1 end