summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-26 08:30:42 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-26 08:30:42 -0700
commit84fb60917ce14c80d1382545276acd436954290e (patch)
tree22fe873c5fce107ee65bb83e1b08526689ba01a3
parent1002db49685b0fdf87e7ad8532840bf93d3bc2f9 (diff)
downloadtxr-84fb60917ce14c80d1382545276acd436954290e.tar.gz
txr-84fb60917ce14c80d1382545276acd436954290e.tar.bz2
txr-84fb60917ce14c80d1382545276acd436954290e.zip
suffix functions: leading dot is not delimiter
* stream.c (short_suffix, long_suffix): Do not treat the starting dot of the last componet as a suffix delimiter. * tests/018/path.tl: Test cases edited to reflect requirements change; new tests added. * txr.1: Updated.
-rw-r--r--stream.c7
-rw-r--r--tests/018/path.tl36
-rw-r--r--txr.113
3 files changed, 37 insertions, 19 deletions
diff --git a/stream.c b/stream.c
index 1c965c8c..ecd30ba6 100644
--- a/stream.c
+++ b/stream.c
@@ -5040,7 +5040,7 @@ val short_suffix(val name, val alt_in)
const wchar_t *dot = wcsrchr(str, '.');
const wchar_t *sl = if3(dot, wcspbrk(dot + 1, psc), 0);
- if (!dot || (sl && sl[1])) {
+ if (!dot || (sl && sl[1]) || dot == str || wcschr(psc, dot[-1])) {
return default_null_arg(alt_in);
} else {
wchar_t *suff = chk_strdup(dot + 1);
@@ -5063,7 +5063,10 @@ val long_suffix(val name, val alt_in)
while (dot && (sl = wcspbrk(dot, psc)) && sl[1])
dot = wcschr(sl + 1, '.');
- if (!dot || (sl && sl[1])) {
+ if (dot && (dot == str || wcschr(psc, dot[-1])))
+ dot = wcschr(dot + 1, '.');
+
+ if (!dot || dot == str) {
return default_null_arg(alt_in);
} else {
wchar_t *suff = chk_strdup(dot + 1);
diff --git a/tests/018/path.tl b/tests/018/path.tl
index 3dcb5eb3..a00b9465 100644
--- a/tests/018/path.tl
+++ b/tests/018/path.tl
@@ -7,14 +7,15 @@
(short-suffix "" 0) 0
(short-suffix "a") nil
(short-suffix "a" 0) 0
- (short-suffix ".") ""
+ (short-suffix ".") nil
(short-suffix "a.") ""
(short-suffix "a.b.") ""
- (short-suffix ".c") "c"
+ (short-suffix ".c") nil
(short-suffix "a.c") "c"
(short-suffix "a.b.c") "c"
(short-suffix "foo.txt.gz") "gz"
- (short-suffix ".gz") "gz")
+ (short-suffix "txt.gz") "gz"
+ (short-suffix ".gz") nil)
(mtest
(long-suffix 42) :error
@@ -23,24 +24,29 @@
(long-suffix "" 0) 0
(long-suffix "a") nil
(long-suffix "a" 0) 0
- (long-suffix ".") ""
+ (long-suffix ".") nil
(long-suffix "a.") ""
(long-suffix "a.b.") "b."
- (long-suffix ".c") "c"
+ (long-suffix ".c") nil
(long-suffix "a.c") "c"
(long-suffix "a.b.c") "b.c"
(long-suffix "foo.txt.gz") "txt.gz"
- (long-suffix ".gz") "gz"
- (long-suffix ".txt.gz") "txt.gz")
+ (long-suffix ".gz") nil
+ (long-suffix ".txt.gz") "gz"
+ (long-suffix "/.txt.gz") "gz"
+ (long-suffix "a/.txt.gz") "gz")
(mtest
(short-suffix "/") nil
(short-suffix "a/") nil
- (short-suffix ".a/") "a"
+ (short-suffix "/.") nil
+ (short-suffix "a/.") nil
+ (short-suffix ".a/") nil
(short-suffix ".a/b") nil
+ (short-suffix ".a/c.b") "b"
(short-suffix ".a/b/") nil
- (short-suffix ".a/b/.b") "b"
- (short-suffix ".a/b/.b/") "b"
+ (short-suffix ".a/b/.b") nil
+ (short-suffix ".a/b/.b/") nil
(short-suffix ".a/b/c.b") "b"
(short-suffix ".a/b/c.b/") "b"
(short-suffix ".a/b/c.b//") nil)
@@ -48,13 +54,17 @@
(mtest
(long-suffix "/") nil
(long-suffix "a/") nil
- (long-suffix ".a/") "a"
+ (long-suffix "/.") nil
+ (long-suffix "a/.") nil
+ (long-suffix ".a/") nil
(long-suffix ".a/b") nil
(long-suffix ".a/b/") nil
- (long-suffix ".a/b/.b") "b"
- (long-suffix ".a/b/.b/") "b"
+ (long-suffix ".a/b/.b") nil
+ (long-suffix ".a/b/.b/") nil
(long-suffix ".a/b/c.b") "b"
(long-suffix ".a/b/c.b/") "b"
(long-suffix "a.b/c.d.e") "d.e"
(long-suffix "a.b/c.d.e/") "d.e"
+ (long-suffix "a.b/c.d.e/f") nil
+ (long-suffix "a.b/c.d.e/f.g.h") "g.h"
(long-suffix "a.b/c.d.e//") nil)
diff --git a/txr.1 b/txr.1
index 97def4e5..ba96ae34 100644
--- a/txr.1
+++ b/txr.1
@@ -57196,7 +57196,8 @@ What it means for
to have a suffix delimiter is that the
.code .
character occurs somewhere in the last component of
-.metn path .
+.metn path ,
+other than as the character of that component.
What constitutes the last component is specified
in more detail below.
@@ -57236,8 +57237,10 @@ extracted from this last component.
.verb
(short-suffix "") -> nil
- (short-suffix ".") -> ""
+ (short-suffix ".") -> nil
(short-suffix "abc") -> nil
+ (short-suffix ".abc") -> nil
+ (short-suffix "/.abc") -> nil
(short-suffix "abc" "") -> ""
(short-suffix "abc.") -> ""
(short-suffix "abc.tar") -> "tar"
@@ -57247,10 +57250,12 @@ extracted from this last component.
(short-suffix "x.y.z/abc.tar.gz//") -> nil
(long-suffix "") -> nil
- (long-suffix ".") -> ""
+ (long-suffix ".") -> nil
(long-suffix "abc") -> nil
+ (long-suffix ".abc") -> nil
+ (long-suffix "/.abc") -> nil
(long-suffix "abc.") -> ""
- (long-suffix "abc.tar") -> "txt"
+ (long-suffix "abc.tar") -> "tar"
(long-suffix "abc.tar.gz") -> "tar.gz"
(long-suffix "abc.tar.gz/") -> "tar.gz"
(long-suffix "x.y.z/abc.tar.gz/") -> "tar.gz"