From 2cb3b86a8260a01d87bd88f4c20de1c107616d8a Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 14 May 2014 20:27:49 +1000 Subject: REal llStrimTrim(), and sanity check inputs to llSubStringIndex(). --- lib/LSL.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/LSL.lua') diff --git a/lib/LSL.lua b/lib/LSL.lua index 571ecf1..09f6ba8 100644 --- a/lib/LSL.lua +++ b/lib/LSL.lua @@ -722,11 +722,24 @@ function --[[string]] LSL.llGetSubString(--[[string]] text, --[[integer]] start, end function --[[integer]] LSL.llSubStringIndex(--[[string]] text, --[[string]] sub) + if nil == text then return -1 end + if nil == sub then return -1 end local start, End = string.find(text, sub, 1, true) if nil == start then return -1 else return start - 1 end end +function LSL.llStringTrim(--[[string]] text, --[[integer]] Type) + -- Trims spaces (ASCII 32), tabs (ASCII 9) '\t', and new lines (ASCII 10) '\n' + -- Lua doesn't document what it considers to be "space characters" + if (Type == LSL.STRING_TRIM_HEAD) or (Type == LSL.STRING_TRIM) then + text = string.gsub(text, '^%s*(.*)', '%1') + end + if (Type == LSL.STRING_TRIM_TAIL) or (Type == LSL.STRING_TRIM) then + text = string.gsub(text, '(.-)%s*$', '%1') + end + return text +end -- Crements stuff. -- cgit v1.1