ok 那先来一个 explode,功能接口与php定义完全一样
local strfind = string.find
local strsub = string.sub
local strlen = string.len
function explode(sep, str, limit)
if not sep or sep == "" then return false end
if not str then return false end
limit = limit or 0
if limit < 0 then return {} end
local r = {}
local n, init = 0, 1
while true do
local s,e = strfind(str, sep, init, true)
if not s then break end
r[#r+1] = strsub(str, init, s - 1)
init = e + 1
n = n + 1
if n == limit - 1 then break end
end
if init <= strlen(str) then
r[#r+1] = strsub(str, init)
else
r[#r+1] = ""
end
return r, n+1
end
Lance
2012/10/8 agentzh
<age...@gmail.com>
Hello!
2012/10/7 Lance <lance...@gmail.com>:
> 这里有一个之前我就注意到过,后来忘掉的 lua-resty-string,前两天就为了实现 random strong
> 费了半天力气,今天看到这里已经有了。
>
呵呵
欢迎贡献文档补丁 :)
> 另外 lua-resty-* 系列,能否有一个总的文档,甚至 openresty 发行包的总体功能说明文档,指导用户去哪里找相关的功能呢?
>
欢迎贡献 :D
> 对了,还有两个我最近一直在纠结的功能,类似 php 的 explode 和
> str_replace,基于纯字符串而不是正则表达式的字符串切分和替换,这个在实际使用中我觉得比正则的更加常用。我自己做了一些实现(前两天那些邮件大多与此有关),但总感觉性能不太满意,你看看是否可能扩展在这个包里面呢?
>
这两个可以有 :) 欢迎贡献补丁 :)