模块:Quote
来自星露谷物语扩展百科
更多操作
local p = {}
-- 检查文本中是否有且仅有一个中文冒号":",且冒号前面没有出现过中文逗号和中文句号
function p.split(frame)
local text = frame.args[1] or ""
-- 计算中文冒号的数量
local colonCount = 0
for _ in string.gmatch(text, ":") do
colonCount = colonCount + 1
end
-- 如果不是只有一个冒号,返回空
if colonCount ~= 1 then
return ""
end
-- 找到冒号的位置
local colonPos = string.find(text, ":")
-- 检查冒号前面是否有中文逗号或中文句号
local beforeColon = string.sub(text, 1, colonPos - 1)
if string.find(beforeColon, "[,。]") then
return ""
end
-- 分割文本
local afterColon = string.sub(text, colonPos + 1)
-- 返回结果
if frame.args.part == "before" then
return beforeColon
elseif frame.args.part == "after" then
return afterColon
else
-- 默认返回两部分,用 frame.args.separator 分隔(默认为制表符)
local separator = frame.args.separator or "\t"
return beforeColon .. separator .. afterColon
end
end
return p