summaryrefslogtreecommitdiff
path: root/tex/context/base/l-file.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2008-05-21 15:21:00 +0200
committerHans Hagen <pragma@wxs.nl>2008-05-21 15:21:00 +0200
commit1d63a6eae86a6b78d4563ed60521449e4bf89f3c (patch)
tree5a0db36538992d01458e22ff765bf8258bd16161 /tex/context/base/l-file.lua
parentd7e26feb7432f7bd29dd065fa578dc8395fb408f (diff)
downloadcontext-1d63a6eae86a6b78d4563ed60521449e4bf89f3c.tar.gz
stable 2008.05.21 15:21
Diffstat (limited to 'tex/context/base/l-file.lua')
-rw-r--r--tex/context/base/l-file.lua22
1 files changed, 15 insertions, 7 deletions
diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua
index 91998532b..f49add545 100644
--- a/tex/context/base/l-file.lua
+++ b/tex/context/base/l-file.lua
@@ -134,14 +134,22 @@ end
--~ print("../test/" .. " == " .. file.collapse_path("../test/"))
--~ print("a/a" .. " == " .. file.collapse_path("a/b/c/../../a"))
+--~ function file.collapse_path(str)
+--~ local ok, n = false, 0
+--~ while not ok do
+--~ ok = true
+--~ str, n = str:gsub("[^%./]+/%.%./", function(s)
+--~ ok = false
+--~ return ""
+--~ end)
+--~ end
+--~ return (str:gsub("/%./","/"))
+--~ end
+
function file.collapse_path(str)
- local ok, n = false, 0
- while not ok do
- ok = true
- str, n = str:gsub("[^%./]+/%.%./", function(s)
- ok = false
- return ""
- end)
+ local n = 1
+ while n > 0 do
+ str, n = str:gsub("([^/%.]+/%.%./)","")
end
return (str:gsub("/%./","/"))
end