diff options
author | David Walter Seikel | 2014-05-15 13:14:04 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-05-15 13:14:04 +1000 |
commit | 286ea32f24be4643222db5692b4179fdacf302a5 (patch) | |
tree | a346cac3cdeb92539992b7b8a774003715a8627b /lib | |
parent | Another MLP fudge to get it to work. (diff) | |
download | SledjHamr-286ea32f24be4643222db5692b4179fdacf302a5.zip SledjHamr-286ea32f24be4643222db5692b4179fdacf302a5.tar.gz SledjHamr-286ea32f24be4643222db5692b4179fdacf302a5.tar.bz2 SledjHamr-286ea32f24be4643222db5692b4179fdacf302a5.tar.xz |
Implement llParseStringKeepNulls() and llParseString2List().
Diffstat (limited to 'lib')
-rw-r--r-- | lib/LSL.lua | 99 |
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 |
701 | end | 701 | end |
702 | 702 | ||
703 | --function --[[list]] LSL.llParseString2List(--[[string]] In, --[[list]] l, --[[list]] l1) return {} end; | 703 | function --[[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 | |||
712 | print("LSL.llParseStringKeepNulls(" .. In .. ") " .. #In) | ||
713 | for i, v in ipairs(l) do | ||
714 | print(" [" .. v .. "]") | ||
715 | end | ||
716 | print(",") | ||
717 | for i, v in ipairs(l1) do | ||
718 | print(" {" .. v .. "}") | ||
719 | end | ||
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 | |||
769 | print("RESULT = ") | ||
770 | for i, v in ipairs(result) do | ||
771 | print(" {" .. v .. "}") | ||
772 | end | ||
773 | |||
774 | return result | ||
775 | end | ||
776 | |||
777 | function --[[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 | |||
790 | print("RESULT SANS NULLS = ") | ||
791 | for i, v in ipairs(result) do | ||
792 | print(" {" .. v .. "}") | ||
793 | end | ||
794 | |||
795 | return result | ||
796 | end | ||
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, | |||
722 | end | 815 | end |
723 | 816 | ||
724 | function --[[integer]] LSL.llSubStringIndex(--[[string]] text, --[[string]] sub) | 817 | function --[[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 |