Deprecate wml_utils.trim in favour of stringx.trim and update all use cases

This commit is contained in:
Celtic Minstrel 2019-12-04 00:53:59 -05:00
parent 462538bf36
commit 4eb043bb16
3 changed files with 4 additions and 7 deletions

View file

@ -25,7 +25,7 @@ function wml_actions.sync_variable(cfg)
function() function()
local res = {} local res = {}
for name_raw in utils.split(names) do for name_raw in utils.split(names) do
local name = utils.trim(name_raw) local name = name_raw:trim()
local variable_type = string.sub(name, string.len(name)) == "]" and "indexed" or ( wml.variables[name .. ".length"] > 0 and "array" or "attribute") local variable_type = string.sub(name, string.len(name)) == "]" and "indexed" or ( wml.variables[name .. ".length"] > 0 and "array" or "attribute")
local variable_info = { name = name, type = variable_type } local variable_info = { name = name, type = variable_type }
table.insert(res, { "variable", variable_info }) table.insert(res, { "variable", variable_info })
@ -110,7 +110,7 @@ function wml_actions.clear_variable(cfg, variables)
wml.error "[clear_variable] missing required name= attribute." wml.error "[clear_variable] missing required name= attribute."
if variables == nil then variables = wml.variables end if variables == nil then variables = wml.variables end
for w in utils.split(names) do for w in utils.split(names) do
variables[utils.trim(w)] = nil variables[w:trim()] = nil
end end
end end

View file

@ -1,10 +1,7 @@
local utils = {vwriter = {}} local utils = {vwriter = {}}
function utils.trim(s) utils.trim = wesnoth.deprecate_api('wml_utils.trim', 'stringx.trim', 1, nil, stringx.trim)
-- use (f(a)) to get first argument
return (tostring(s):gsub("^%s*(.-)%s*$", "%1"))
end
function utils.split(s) function utils.split(s)
return tostring(s or ""):gmatch("[^%s,][^,]*") return tostring(s or ""):gmatch("[^%s,][^,]*")

View file

@ -14,7 +14,7 @@ function wesnoth.wml_actions.role(cfg)
if cfg.type then if cfg.type then
for value in utils.split(cfg.type) do for value in utils.split(cfg.type) do
table.insert(types, utils.trim(value)) table.insert(types, value:trim())
end end
end end