Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local strlib = {}
- strlib.findpattern = function( haystack, seed, start )
- return string.sub(haystack, string.find(haystack, seed, start))
- end
- strlib.explode = function(haystack, seed)
- if seed == '' then return haystack end
- local pos, arr = 0, {}
- for st, sp in function() return string.find(haystack,seed,pos,true) end do
- arr[#arr+1] = string.sub(haystack,pos,st-1)
- pos = sp+1
- end
- arr[#arr+1] = string.sub(haystack,pos)
- return arr
- end
- local hex = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"}
- local hex2dec = {}
- for k, v in pairs(hex) do
- hex2dec[v] = k-1
- end
- strlib.urlencode = function(str)
- local out = ""
- local c = 1
- while c <= #str do
- local chr = string.sub(str,c,c)
- local val = string.byte(chr)
- if(val>=48 and val<=57) or
- (val>=65 and val<=90) or
- (val>=97 and val<=122) then
- out = out..chr
- else
- out = out.."%"..hex[1+math.floor(val/16)]
- ..hex[1+(val%16)]
- end
- c = c+1
- end
- return out
- end
- strlib.urldecode = function(str)
- local out = ""
- local c = 0
- while c <= #str do
- local chr = string.sub(str,c,c)
- if chr ~= "%" then
- out = out .. chr
- else
- if #str < c+2 then return out end
- local code1 = string.sub(str,c+1,c+1)
- local code2 = string.sub(str,c+2,c+2)
- out = out..string.char(hex2dec[code1]*16+hex2dec[code2])
- c = c+2
- end
- c=c+1
- end
- return out
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement