-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdpt.extensions.lua
More file actions
35 lines (29 loc) · 943 Bytes
/
dpt.extensions.lua
File metadata and controls
35 lines (29 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local master = diffusion or {}
if master.extensions ~= nil then
return master.extensions
end
local RD, FD = master.utilities.RD, master.utilities.FD
-- Mark up non-printing delimiters
function string:escapeDiff()
local result = self:gsub( string.char(RD), "<RD>" )
return (result:gsub( string.char(FD), "<FD>" ))
end
function string:toRecordString()
return string.format( "[%s]", self:gsub( string.char(FD), ", " ) )
end
function string:startsWith( prefix )
local prefixLength = string.len( prefix )
local actualPrefix = string.sub( self, 1, prefixLength )
return actualPrefix == prefix
end
-- Split a string into fields by the given delimited
function string:split(sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
-- Package footer
master.extensions = {}
diffusion = master
return master.extensions