summaryrefslogtreecommitdiff
path: root/tex/context/base/l-file.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/l-file.lua')
-rw-r--r--tex/context/base/l-file.lua61
1 files changed, 38 insertions, 23 deletions
diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua
index d47b13c30..03323d29e 100644
--- a/tex/context/base/l-file.lua
+++ b/tex/context/base/l-file.lua
@@ -105,20 +105,6 @@ function file.replacesuffix(filename, suffix)
return (gsub(filename,"%.[%a%d]+$","")) .. "." .. suffix
end
---~ function file.join(...)
---~ local pth = concat({...},"/")
---~ pth = gsub(pth,"\\","/")
---~ local a, b = match(pth,"^(.*://)(.*)$")
---~ if a and b then
---~ return a .. gsub(b,"//+","/")
---~ end
---~ a, b = match(pth,"^(//)(.*)$")
---~ if a and b then
---~ return a .. gsub(b,"//+","/")
---~ end
---~ return (gsub(pth,"//+","/"))
---~ end
-
local trick_1 = char(1)
local trick_2 = "^" .. trick_1 .. "/+"
@@ -145,15 +131,44 @@ function file.join(...) -- rather dirty
return (gsub(pth,"//+","/"))
end
---~ print(file.join("//","/y"))
---~ print(file.join("/","/y"))
---~ print(file.join("","/y"))
---~ print(file.join("/x/","/y"))
---~ print(file.join("x/","/y"))
---~ print(file.join("http://","/y"))
---~ print(file.join("http://a","/y"))
---~ print(file.join("http:///a","/y"))
---~ print(file.join("//nas-1","/y"))
+-- local slash = P("/")
+-- local colon = P(":")
+
+-- local replacer = lpeg.replacer(S("\\/")^1,"/")
+-- local stripper = Cs(P(slash)^0/"" * replacer)
+-- local isnetwork = slash * slash * (1-slash) + (1-slash-colon)^1 * colon
+-- local isroot = slash^1 * -1
+-- local hasroot = slash^1
+
+-- function file.newjoin(...) -- rather dirty
+-- local lst = { ... }
+-- local one = lst[1]
+-- if lpegmatch(isnetwork,one) then
+-- local two = lpegmatch(replacer,concat(lst,"/",2))
+-- return one .. two
+-- elseif lpegmatch(isroot,one) then
+-- local two = lpegmatch(replacer,concat(lst,"/",2))
+-- if lpegmatch(hasroot,two) then
+-- return two
+-- else
+-- return "/" .. two
+-- end
+-- elseif one == "" then
+-- return lpegmatch(stripper,concat(lst,"/",2))
+-- else
+-- return lpegmatch(replacer,concat(lst,"/"))
+-- end
+-- end
+
+-- print(file.join("//","/y"))
+-- print(file.join("/","/y"))
+-- print(file.join("","/y"))
+-- print(file.join("/x/","/y"))
+-- print(file.join("x/","/y"))
+-- print(file.join("http://","/y"))
+-- print(file.join("http://a","/y"))
+-- print(file.join("http:///a","/y"))
+-- print(file.join("//nas-1","/y"))
-- We should be able to use:
--