置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Str test

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
  1. local module = {}
  2. function module.main(frame)
  3. local args = frame.args
  4. local str = args[1]
  5. local ptn = mw.text.decode(mw.text.unstripNoWiki(args[2]))
  6. if mw.ustring.find(str, ptn) == nil
  7. then return ''
  8. else return 1 end
  9. end
  10. function module.MultiMatch(frame)
  11. local parent = frame:getParent()
  12. if parent and parent:getTitle() == "Template:Str substr" then
  13. frame = parent
  14. end
  15. local args = frame.args
  16. local str = args[1]
  17. local result = ""
  18. local i = 2
  19. while(frame.args[i])do
  20. local ptn = mw.text.decode(mw.text.unstripNoWiki(args[i]))
  21. local found = mw.ustring.match(str, ptn)
  22. result = result .. (found and "1" or "0")
  23. i = i+1
  24. end
  25. return result
  26. end
  27. function module.Switch(frame)
  28. local parent = frame:getParent()
  29. if parent and parent:getTitle() == "Template:Str switch" then
  30. frame = parent
  31. end
  32. local str = frame.args[1]
  33. for key, value in pairs(frame.args) do
  34. if type(key) == "string" and key ~= "#default" then
  35. local ptn = mw.text.decode(mw.text.trim(mw.text.unstripNoWiki(value)))
  36. if ptn ~= "" and mw.ustring.match(str, ptn) then
  37. return key
  38. end
  39. end
  40. end
  41. return frame.args["#default"] or ""
  42. end
  43. return module