@@ -128,6 +128,7 @@ Z_MATCHMODE = 0
128128Z_MATCHNAME = false
129129Z_SKIPPWD = false
130130Z_HYPHEN = " auto"
131+ Z_DATA_SEPARATOR = " |"
131132
132133os .LOG_NAME = os.getenv (' _ZL_LOG_NAME' )
133134
@@ -1061,6 +1062,26 @@ function path_case_insensitive()
10611062end
10621063
10631064
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+
10641085---- -------------------------------------------------------------------
10651086-- load and split data
10661087---- -------------------------------------------------------------------
@@ -1073,7 +1094,7 @@ function data_load(filename)
10731094 return {}
10741095 end
10751096 for line in fp :lines () do
1076- local part = string . split (line , ' | ' )
1097+ local part = read_data_line (line )
10771098 local item = {}
10781099 if part and part [1 ] and part [2 ] and part [3 ] then
10791100 local key = insensitive and part [1 ]:lower () or part [1 ]
@@ -1135,7 +1156,7 @@ function data_save(filename, M)
11351156 end
11361157 for i = 1 , # M do
11371158 local item = M [i ]
1138- local text = item .name .. ' | ' .. item .rank .. ' | ' .. item .time
1159+ local text = item .name .. Z_DATA_SEPARATOR .. item .rank .. Z_DATA_SEPARATOR .. item .time
11391160 fp :write (text .. ' \n ' )
11401161 end
11411162 fp :close ()
0 commit comments