Skip to content

Commit cfa0ad7

Browse files
committed
migrate scripts to use common string functions
1 parent 9a2a261 commit cfa0ad7

8 files changed

+18
-34
lines changed

assign-attributes.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ local function generate_medians_table(race)
117117
assert(creature ~= nil)
118118
for _, raw in ipairs(creature.raws) do
119119
if string.match(raw.value, "PHYS_ATT_RANGE") then
120-
local token_parts = utils.split_string(raw.value, ":")
120+
local token_parts = raw.value:split(":")
121121
-- part 1 *2* 3 4 5 *6* 7 8 9
122122
-- [PHYS_ATT_RANGE:STRENGTH:450:950:1150:1250:1350:1550:2250]
123123
medians.PHYSICAL[token_parts[2]] = tonumber(token_parts[6])
124124
elseif string.match(raw.value, "MENT_ATT_RANGE") then
125-
local token_parts = utils.split_string(raw.value, ":")
125+
local token_parts = raw.value:split(":")
126126
-- part 1 *2* 3 4 5 *6* 7 8 9
127127
-- [MENT_ATT_RANGE:PATIENCE:450:950:1150:1250:1350:1550:2250]
128128
medians.MENTAL[token_parts[2]] = tonumber(token_parts[6])

assign-preferences.lua

+7-7
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ local preference_functions = {
256256
-- ---------------- LIKECREATURE ---------------- --
257257
LIKECREATURE = function(token)
258258
local creature_id
259-
local parts = utils.split_string(token, ":")
259+
local parts = token:split(":")
260260
if #parts == 1 then
261261
creature_id = parts[1]
262262
else
@@ -368,7 +368,7 @@ local preference_functions = {
368368
-- ---------------- HATECREATURE ---------------- --
369369
HATECREATURE = function(token)
370370
local creature_id
371-
local parts = utils.split_string(token, ":")
371+
local parts = token:split(":")
372372
if #parts == 1 then
373373
creature_id = parts[1]
374374
else
@@ -402,7 +402,7 @@ local preference_functions = {
402402
LIKEITEM = function(token)
403403
local item_type
404404
local item_subtype = -1
405-
local parts = utils.split_string(token, ":")
405+
local parts = token:split(":")
406406
if #parts == 1 then
407407
item_type = df.item_type[parts[1]]
408408
else
@@ -444,7 +444,7 @@ local preference_functions = {
444444
-- ---------------- LIKEPLANT ---------------- --
445445
LIKEPLANT = function(token)
446446
local plant_id
447-
local parts = utils.split_string(token, ":")
447+
local parts = token:split(":")
448448
if #parts == 1 then
449449
plant_id = parts[1]
450450
else
@@ -477,7 +477,7 @@ local preference_functions = {
477477
-- ---------------- LIKETREE ---------------- --
478478
LIKETREE = function(token)
479479
local plant_id
480-
local parts = utils.split_string(token, ":")
480+
local parts = token:split(":")
481481
if #parts == 1 then
482482
plant_id = parts[1]
483483
else
@@ -510,7 +510,7 @@ local preference_functions = {
510510
-- ---------------- LIKECOLOR ---------------- --
511511
LIKECOLOR = function(token)
512512
local color_name
513-
local parts = utils.split_string(token, ":")
513+
local parts = token:split(":")
514514
if #parts == 1 then
515515
color_name = parts[1]
516516
else
@@ -544,7 +544,7 @@ local preference_functions = {
544544
-- ---------------- LIKESHAPE ---------------- --
545545
LIKESHAPE = function(token)
546546
local shape_name
547-
local parts = utils.split_string(token, ":")
547+
local parts = token:split(":")
548548
if #parts == 1 then
549549
shape_name = parts[1]
550550
else

gui/gm-editor.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function GmEditorUi:find_id(force_dialog)
250250
return a.weight > b.weight
251251
end)
252252
local message = {{pen=COLOR_LIGHTRED, text="Note: "}}
253-
for _, line in ipairs(utils.split_string(raw_message, '\n')) do
253+
for _, line in ipairs(raw_message:split('\n')) do
254254
table.insert(message, line)
255255
table.insert(message, NEWLINE)
256256
end

gui/mod-manager.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function manager:formDescription()
247247
if self.selected.description then
248248
return self.selected.description
249249
--[[
250-
local str=require('utils').split_string(self.selected.description,"\n")
250+
local str=self.selected.description:split("\n")
251251
for _,s in ipairs(str) do
252252
table.insert(ret,{text=s})
253253
table.insert(ret,NEWLINE)

gui/prerelease-warning.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ yourself, please report this to your pack's maintainer.]]
8787

8888
path = dfhack.getHackPath():lower()
8989
if #pack_message > 0 and (path:find('lnp') or path:find('starter') or path:find('newb') or path:find('lazy') or path:find('pack')) then
90-
for _, v in pairs(utils.split_string(pack_message, '\n')) do
90+
for _, v in pairs(pack_message:split('\n')) do
9191
table.insert(message, NEWLINE)
9292
table.insert(message, {text=v, pen=COLOR_LIGHTMAGENTA})
9393
end
9494
end
9595

96-
for _, v in pairs(utils.split_string([[
96+
for _, v in pairs(([[
9797
9898
REMINDER: Please report any issues you encounter while
9999
using this DFHack build on GitHub (github.com/dfhack/dfhack/issues)
100-
or the Bay12 forums (dfhack.org/bay12).]], '\n')) do
100+
or the Bay12 forums (dfhack.org/bay12).]]):split('\n')) do
101101
table.insert(message, NEWLINE)
102102
table.insert(message, {text=v, pen=COLOR_LIGHTCYAN})
103103
end
@@ -107,7 +107,7 @@ nightly_message = [[
107107
You appear to be using a nightly build of DFHack. If you
108108
experience problems, check dfhack.org/builds for updates.]]
109109
if dfhack.getDFHackBuildID() ~= '' then
110-
for _, v in pairs(utils.split_string(nightly_message, '\n')) do
110+
for _, v in pairs(nightly_message:split('\n')) do
111111
table.insert(message, NEWLINE)
112112
table.insert(message, {text=v, pen=COLOR_LIGHTGREEN})
113113
end

gui/settings-manager.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function dup_table(tbl)
3232
end
3333

3434
function set_variable(name, value)
35-
local parts = name:split('.')
35+
local parts = name:split('.', true)
3636
local last_field = table.remove(parts, #parts)
3737
parent = _G
3838
for _, field in pairs(parts) do

gui/unit-info-viewer.lua

+1-17
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,6 @@ function isBlank(x)
189189
return not not x:find("^%s*$")
190190
end
191191

192-
--http://lua-users.org/wiki/StringRecipes (removed indents since I am not using them)
193-
function wrap(str, limit)--, indent, indent1)
194-
--indent = indent or ""
195-
--indent1 = indent1 or indent
196-
local limit = limit or 72
197-
local here = 1 ---#indent1
198-
return str:gsub("(%s+)()(%S+)()", --indent1..str:gsub(
199-
function(sp, st, word, fi)
200-
if fi-here > limit then
201-
here = st -- - #indent
202-
return "\n"..word --..indent..word
203-
end
204-
end)
205-
end
206-
207-
208192
--------------------------------------------------
209193
---------------------- Time ----------------------
210194
--------------------------------------------------
@@ -604,7 +588,7 @@ function UnitInfoViewer:onGetSelectedUnit()
604588
return self.ident.unit
605589
end
606590
function UnitInfoViewer:insert_chunk(str,pen)
607-
local lines = utils.split_string( wrap(str,self.frame_width) , NEWLINE )
591+
local lines = str:wrap(self.frame_width):split(NEWLINE)
608592
for i = 1,#lines do
609593
table.insert(self.text,{text=lines[i],pen=pen})
610594
table.insert(self.text,NEWLINE)

install-info.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ log_version('Is map loaded', 'isMapLoaded')
4747
function log_command(cmd)
4848
log('\nOutput of "' .. cmd .. '":')
4949
local output = select(1, dfhack.run_command_silent(cmd))
50-
for _, line in pairs(utils.split_string(output, '\n')) do
50+
for _, line in pairs(output:split('\n')) do
5151
log(' ' .. line)
5252
end
5353
end

0 commit comments

Comments
 (0)