+2022-06-03 Paul Eggert <eggert@cs.ucla.edu>
+
+ filevercmp: don’t treat entire filename as suffix
+ Problem reported by Artém S. Tashkinóv in:
+ https://lists.gnu.org/r/bug-gnulib/2022-06/msg00012.html
+ * lib/filevercmp.c (file_prefixlen): When stripping
+ (\.[A-Za-z~][A-Za-z0-9~]*)*$ suffixes, do not strip
+ the entire file name.
+ * tests/test-filevercmp.c (examples): Adjust to match new behavior.
+
2022-06-03 Bruno Haible <bruno@clisp.org>
setlocale: Update after Turkey changed its name.
/* Return the length of a prefix of S that corresponds to the suffix
defined by this extended regular expression in the C locale:
(\.[A-Za-z~][A-Za-z0-9~]*)*$
+ Use the longest suffix matching this regular expression,
+ except do not use all of S as a suffix if S is nonempty.
If *LEN is -1, S is a string; set *LEN to S's length.
Otherwise, *LEN should be nonnegative, S is a char array,
and *LEN does not change. */
file_prefixlen (char const *s, ptrdiff_t *len)
{
size_t n = *len; /* SIZE_MAX if N == -1. */
+ idx_t prefixlen = 0;
- for (idx_t i = 0; ; i++)
+ for (idx_t i = 0; ; )
{
- idx_t prefixlen = i;
- while (i + 1 < n && s[i] == '.' && (c_isalpha (s[i + 1])
- || s[i + 1] == '~'))
- for (i += 2; i < n && (c_isalnum (s[i]) || s[i] == '~'); i++)
- continue;
-
if (*len < 0 ? !s[i] : i == n)
{
*len = i;
return prefixlen;
}
+
+ i++;
+ prefixlen = i;
+ while (i + 1 < n && s[i] == '.' && (c_isalpha (s[i + 1])
+ || s[i + 1] == '~'))
+ for (i += 2; i < n && (c_isalnum (s[i]) || s[i] == '~'); i++)
+ continue;
}
}
without them, using version sort without special priority;
if they do not compare equal, this comparison result is used and
the suffixes are effectively ignored. Otherwise, the entire
- strings are compared using version sort.
+ strings are compared using version sort. When removing a suffix
+ from a nonempty string, remove the maximal-length suffix such that
+ the remaining string is nonempty.
This function is intended to be a replacement for strverscmp. */
int filevercmp (char const *a, char const *b) _GL_ATTRIBUTE_PURE;
"",
".",
"..",
+ ".0",
+ ".9",
".A",
".Z",
".a~",
".zz~",
".zz",
".zz.~1~",
- ".0",
- ".9",
".zz.0",
".\1",
".\1.txt",