模块:Phlaman:修订间差异

来自「荏苒之境」
创建页面,内容为“local ustring = mw.ustring local phlaman = {} phlaman.split_words = function(text) local ws = {} for sign, word in ustring.gmatch(text, "([^ ]+)([ ])") do if word ~= "" then ws[#ws+1] = word..sign end end return ws end phlaman.show_resplitted = function(frame) local delimiter = frame.args[1] local text = frame.args[2] return table.concat(phlaman.split_words(text), delimiter) end return phlaman”
 
无编辑摘要
 
(未显示同一用户的4个中间版本)
第5行: 第5行:
phlaman.split_words = function(text)
phlaman.split_words = function(text)
local ws = {}
local ws = {}
for sign, word in ustring.gmatch(text, "([^ ]+)([ ])") do
for sign, word in ustring.gmatch(text, "([^ ]+)([ ]?)") do
if word ~= "" then
if sign == " " then
if word ~= "" then
ws[#ws+1] = word
end
ws[#ws+1] = " "
else
ws[#ws+1] = word..sign
ws[#ws+1] = word..sign
end
end

2025年10月31日 (五) 14:10的最新版本

此模块的文档可以在模块:Phlaman/doc创建

local ustring = mw.ustring

local phlaman = {}

phlaman.split_words = function(text)
	local ws = {}
	for sign, word in ustring.gmatch(text, "([^ ]+)([ ]?)") do
		if sign == " " then
			if word ~= "" then
				ws[#ws+1] = word
			end
			ws[#ws+1] = " "
		else
			ws[#ws+1] = word..sign
		end
	end
	return ws
end

phlaman.show_resplitted = function(frame)
	local delimiter = frame.args[1]
	local text = frame.args[2]
	return table.concat(phlaman.split_words(text), delimiter)
end

return phlaman