Skip to content

Commit cb4c9d3

Browse files
committed
Revert back to the old separator and improve db reading
A smarter reading function lets us support '|' in filenames whilst still using it as the database separator.
1 parent 924f61a commit cb4c9d3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

z.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Z_MATCHMODE = 0
128128
Z_MATCHNAME = false
129129
Z_SKIPPWD = false
130130
Z_HYPHEN = "auto"
131-
Z_DATA_SEPARATOR = "\0"
131+
Z_DATA_SEPARATOR = "|"
132132

133133
os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
134134

@@ -1062,6 +1062,26 @@ function path_case_insensitive()
10621062
end
10631063

10641064

1065+
-----------------------------------------------------------------------
1066+
-- Read a line of the database and return a list of the 3 fields in it
1067+
-----------------------------------------------------------------------
1068+
function read_data_line(line)
1069+
local part = string.split(line, Z_DATA_SEPARATOR)
1070+
if #part <= 3 then
1071+
return part
1072+
end
1073+
-- If the part is made of more than 3 elements, it's probably because the
1074+
-- path element contains '|' that have been split. Thus, we want to
1075+
-- reconstruct it and keep the 2 last elements of part intact as the end
1076+
-- of the returned part.
1077+
local path = part[1]
1078+
for i=2,#part-2 do
1079+
path = path .. Z_DATA_SEPARATOR .. part[i]
1080+
end
1081+
return {path, part[#part-1], part[#part]}
1082+
end
1083+
1084+
10651085
-----------------------------------------------------------------------
10661086
-- load and split data
10671087
-----------------------------------------------------------------------
@@ -1074,7 +1094,7 @@ function data_load(filename)
10741094
return {}
10751095
end
10761096
for line in fp:lines() do
1077-
local part = string.split(line, Z_DATA_SEPARATOR)
1097+
local part = read_data_line(line)
10781098
local item = {}
10791099
if part and part[1] and part[2] and part[3] then
10801100
local key = insensitive and part[1]:lower() or part[1]

0 commit comments

Comments
 (0)