Improve path handling (stripping pairs of dots)

This commit is contained in:
Norman Feske 2012-05-18 17:14:38 +02:00
parent e436d60ce7
commit 6f12659369

View File

@ -90,6 +90,17 @@ namespace Noux {
} }
} }
static void strip_superfluous_slashes(char *path)
{
for (; *path; path++) {
if (path[0] != '/') continue;
/* strip superfluous slashes, e.g., "//path/" -> "/path" */
while (path[1] == '/')
remove_char(path);
}
}
/** /**
* Find double-dot path element * Find double-dot path element
* *
@ -126,6 +137,10 @@ namespace Noux {
while (cut_start > 0 && path[cut_start - 1] != '/') while (cut_start > 0 && path[cut_start - 1] != '/')
cut_start--; cut_start--;
/* skip slash in front of the pair of dots */
if (cut_start > 0)
cut_start--;
strip(path + cut_start, cut_end - cut_start); strip(path + cut_start, cut_end - cut_start);
} }
} }
@ -167,6 +182,7 @@ namespace Noux {
{ {
strip_superfluous_dotslashes(_path); strip_superfluous_dotslashes(_path);
strip_double_dot_dirs(_path); strip_double_dot_dirs(_path);
strip_superfluous_slashes(_path);
remove_trailing('.', _path); remove_trailing('.', _path);
} }