summaryrefslogtreecommitdiff
path: root/tex/context/base/l-file.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-12-06 16:40:13 +0200
committerMarius <mariausol@gmail.com>2012-12-06 16:40:13 +0200
commitc5eeba726820e576380fadff494ce494b625b6ae (patch)
tree300975aac0caaf2e7722bdd0edabf335d7b4d5b1 /tex/context/base/l-file.lua
parent8bf2b14b01c07e915720438abcc5b0441b3c883d (diff)
downloadcontext-c5eeba726820e576380fadff494ce494b625b6ae.tar.gz
beta 2012.12.06 15:01
Diffstat (limited to 'tex/context/base/l-file.lua')
-rw-r--r--tex/context/base/l-file.lua164
1 files changed, 84 insertions, 80 deletions
diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua
index bea4ef0aa..d47b13c30 100644
--- a/tex/context/base/l-file.lua
+++ b/tex/context/base/l-file.lua
@@ -297,15 +297,15 @@ function file.collapsepath(str,anchor)
end
end
---~ local function test(str)
---~ print(string.format("%-20s %-15s %-15s",str,file.collapsepath(str),file.collapsepath(str,true)))
---~ end
---~ test("a/b.c/d") test("b.c/d") test("b.c/..")
---~ test("/") test("c:/..") test("sys://..")
---~ test("") test("./") test(".") test("..") test("./..") test("../..")
---~ test("a") test("./a") test("/a") test("a/../..")
---~ test("a/./b/..") test("a/aa/../b/bb") test("a/.././././b/..") test("a/./././b/..")
---~ test("a/b/c/../..") test("./a/b/c/../..") test("a/b/c/../..")
+-- local function test(str)
+-- print(string.format("%-20s %-15s %-15s",str,file.collapsepath(str),file.collapsepath(str,true)))
+-- end
+-- test("a/b.c/d") test("b.c/d") test("b.c/..")
+-- test("/") test("c:/..") test("sys://..")
+-- test("") test("./") test(".") test("..") test("./..") test("../..")
+-- test("a") test("./a") test("/a") test("a/../..")
+-- test("a/./b/..") test("a/aa/../b/bb") test("a/.././././b/..") test("a/./././b/..")
+-- test("a/b/c/../..") test("./a/b/c/../..") test("a/b/c/../..")
function file.robustname(str,strict)
str = gsub(str,"[^%a%d%/%-%.\\]+","-")
@@ -316,6 +316,20 @@ function file.robustname(str,strict)
end
end
+-- local pattern_a = lpeg.replacer(1-R("az","09","AZ","--",".."))
+-- local pattern_a = Cs((R("az","09","AZ","--","..") + P(1)/"-")^1)
+-- local whatever = P("-")^0 / ""
+-- local pattern_b = Cs(whatever * (1 - whatever * -1)^1)
+
+-- function file.robustname(str,strict)
+-- str = lpegmatch(pattern_a,str) or str
+-- if strict then
+-- return lpegmatch(pattern_b,str) or str -- two step is cleaner (less backtracking)
+-- else
+-- return str
+-- end
+-- end
+
file.readdata = io.loaddata
file.savedata = io.savedata
@@ -325,92 +339,82 @@ end
-- lpeg variants, slightly faster, not always
---~ local period = P(".")
---~ local slashes = S("\\/")
---~ local noperiod = 1-period
---~ local noslashes = 1-slashes
---~ local name = noperiod^1
+-- local period = P(".")
+-- local slashes = S("\\/")
+-- local noperiod = 1-period
+-- local noslashes = 1-slashes
+-- local name = noperiod^1
---~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * C(noperiod^1) * -1
+-- local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * C(noperiod^1) * -1
---~ function file.suffixonly(name)
---~ return lpegmatch(pattern,name) or ""
---~ end
+-- function file.suffixonly(name)
+-- return lpegmatch(pattern,name) or ""
+-- end
---~ local pattern = Cs(((period * noperiod^1 * -1)/"" + 1)^1)
+-- local pattern = Cs(((period * noperiod^1 * -1)/"" + 1)^1)
---~ function file.removesuffix(name)
---~ return lpegmatch(pattern,name)
---~ end
+-- function file.removesuffix(name)
+-- return lpegmatch(pattern,name)
+-- end
---~ local pattern = (noslashes^0 * slashes)^1 * C(noslashes^1) * -1
+-- local pattern = (noslashes^0 * slashes)^1 * C(noslashes^1) * -1
---~ function file.basename(name)
---~ return lpegmatch(pattern,name) or name
---~ end
+-- function file.basename(name)
+-- return lpegmatch(pattern,name) or name
+-- end
---~ local pattern = (noslashes^0 * slashes)^1 * Cp() * noslashes^1 * -1
+-- local pattern = Cs ((1 - slashes * noslashes^1 * -1)^1)
---~ function file.dirname(name)
---~ local p = lpegmatch(pattern,name)
---~ if p then
---~ return sub(name,1,p-2)
---~ else
---~ return ""
---~ end
---~ end
+-- function file.dirname(name)
+-- return lpegmatch(pattern,name) or ""
+-- end
---~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * Cp() * noperiod^1 * -1
+-- local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * Cp() * noperiod^1 * -1
---~ function file.addsuffix(name, suffix)
---~ local p = lpegmatch(pattern,name)
---~ if p then
---~ return name
---~ else
---~ return name .. "." .. suffix
---~ end
---~ end
+-- function file.addsuffix(name, suffix)
+-- local p = lpegmatch(pattern,name)
+-- if p then
+-- return name
+-- else
+-- return name .. "." .. suffix
+-- end
+-- end
---~ local pattern = (noslashes^0 * slashes)^0 * (noperiod^1 * period)^1 * Cp() * noperiod^1 * -1
+-- local suffix = period * (1-period-slashes)^1 * -1
+-- local pattern = Cs((1-suffix)^1)
---~ function file.replacesuffix(name,suffix)
---~ local p = lpegmatch(pattern,name)
---~ if p then
---~ return sub(name,1,p-2) .. "." .. suffix
---~ else
---~ return name .. "." .. suffix
---~ end
---~ end
+-- function file.replacesuffix(name,suffix)
+-- if suffix and suffix ~= "" then
+-- return lpegmatch(pattern,name) .. "." .. suffix
+-- else
+-- return name
+-- end
+-- end
---~ local pattern = (noslashes^0 * slashes)^0 * Cp() * ((noperiod^1 * period)^1 * Cp() + P(true)) * noperiod^1 * -1
+-- local path = noslashes^0 * slashes^1
+-- local suffix = period * (1-period-slashes)^1 * -1
+-- local pattern = path^0 * Cs((1-suffix)^1) * suffix^0
---~ function file.nameonly(name)
---~ local a, b = lpegmatch(pattern,name)
---~ if b then
---~ return sub(name,a,b-2)
---~ elseif a then
---~ return sub(name,a)
---~ else
---~ return name
---~ end
---~ end
+-- function file.nameonly(name)
+-- return lpegmatch(pattern,name) or name
+-- end
---~ local test = file.suffixonly
---~ local test = file.basename
---~ local test = file.dirname
---~ local test = file.addsuffix
---~ local test = file.replacesuffix
---~ local test = file.nameonly
-
---~ print(1,test("./a/b/c/abd.def.xxx","!!!"))
---~ print(2,test("./../b/c/abd.def.xxx","!!!"))
---~ print(3,test("a/b/c/abd.def.xxx","!!!"))
---~ print(4,test("a/b/c/def.xxx","!!!"))
---~ print(5,test("a/b/c/def","!!!"))
---~ print(6,test("def","!!!"))
---~ print(7,test("def.xxx","!!!"))
-
---~ local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
+-- local test = file.suffixonly
+-- local test = file.basename
+-- local test = file.dirname
+-- local test = file.addsuffix
+-- local test = file.replacesuffix
+-- local test = file.nameonly
+
+-- print(1,test("./a/b/c/abd.def.xxx","!!!"))
+-- print(2,test("./../b/c/abd.def.xxx","!!!"))
+-- print(3,test("a/b/c/abd.def.xxx","!!!"))
+-- print(4,test("a/b/c/def.xxx","!!!"))
+-- print(5,test("a/b/c/def","!!!"))
+-- print(6,test("def","!!!"))
+-- print(7,test("def.xxx","!!!"))
+
+-- local tim = os.clock() for i=1,250000 do local ext = test("abd.def.xxx","!!!") end print(os.clock()-tim)
-- also rewrite previous