diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-07-03 16:06:17 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-07-03 16:06:17 -0700 |
commit | ccb998581d8ba1e2f8f9c56768d57e32c51777c5 (patch) | |
tree | f29a4d79f4dfa91880ca415c85229ea80e83d89b /stream.c | |
parent | fc4d580aaa4bbd5908507596a429621e560b024b (diff) | |
download | txr-ccb998581d8ba1e2f8f9c56768d57e32c51777c5.tar.gz txr-ccb998581d8ba1e2f8f9c56768d57e32c51777c5.tar.bz2 txr-ccb998581d8ba1e2f8f9c56768d57e32c51777c5.zip |
suffix functions: ignore trailing slashes.
Another requirements tweak to short-suffix and long-suffix:
ignore one or more trailing slashes, instead of just one.
This harmonizes with base-name, which does same, that
requirement being copies from the POSIX basename utility.
* stream.c (short_suffix, long_suffix): If sl points to a
trailing slash which is the start of a suffix that consists of
nothing but trailing slashes, then we pretend it isn't there.
* tests/018/path.tl: Adjusted two existing test cases, and
added more.
* txr.1: Documented.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -5042,8 +5042,9 @@ val short_suffix(val name, val alt_in) const wchar_t *str = c_str(name, self); const wchar_t *dot = wcsrchr(str, '.'); const wchar_t *sl = if3(dot, wcspbrk(dot + 1, psc), 0); + int sl_trail = if3(sl, sl[wcsspn(sl, psc)] == 0, 0); - if (!dot || (sl && sl[1]) || dot == str || wcschr(psc, dot[-1])) { + if (!dot || (sl && sl[1] && !sl_trail) || dot == str || wcschr(psc, dot[-1])) { return default_null_arg(alt_in); } else { wchar_t *suff = chk_strdup(dot); @@ -5063,7 +5064,7 @@ val long_suffix(val name, val alt_in) { const wchar_t *sl; - while (dot && (sl = wcspbrk(dot, psc)) && sl[1]) + while (dot && (sl = wcspbrk(dot, psc)) && sl[1] && sl[wcsspn(sl, psc)] != 0) dot = wcschr(sl + 1, '.'); if (dot && (dot == str || wcschr(psc, dot[-1]))) @@ -5074,7 +5075,7 @@ val long_suffix(val name, val alt_in) } else { wchar_t *suff = chk_strdup(dot); if (sl) - suff[sl - dot] = 0; + suff[sl - dot] = 0; return string_own(suff); } } |