From 0a596481a0cb1defd0e6094c242a0362ff9950e6 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Tue, 17 Dec 2013 13:41:58 -0500 Subject: [PATCH] Add path.normalize() --- src/base/path.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/base/path.lua b/src/base/path.lua index 66b8cc32..f98151ae 100644 --- a/src/base/path.lua +++ b/src/base/path.lua @@ -185,6 +185,29 @@ end +-- +-- Remove any extraneous weirdness from a path, such as double slashes or +-- leading single dots. +-- +-- @param p +-- The path to normalize. +-- @return +-- A path known weirdnesses removed. +-- + + function path.normalize(p) + -- trim off any leading "./" sequences + while p:startswith("./") do + p = p:sub(3) + end + + -- remove any "//" sequences from path concatenation + p = p:gsub("//", "/") + + return p + end + + -- -- Takes a path which is relative to one location and makes it relative -- to another location instead.