aboutsummaryrefslogtreecommitdiffstats
path: root/strrncaseeqlen.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-18 09:58:23 +0200
committerMattias Andrée <maandree@kth.se>2024-08-18 09:58:23 +0200
commita69f0f613687edf6c1f1ee83b462f77e8ea3c9a9 (patch)
treed976683461a0f427d2f1ef79a8732a048dd0c67b /strrncaseeqlen.c
parentMerge tag '1.3' into since (diff)
parentUpdate VERSION_MINOR (diff)
downloadlibsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.gz
libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.bz2
libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.xz
Merge tag '1.4' into since
Version 1.4
Diffstat (limited to '')
-rw-r--r--strrncaseeqlen.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/strrncaseeqlen.c b/strrncaseeqlen.c
new file mode 100644
index 0000000..d904577
--- /dev/null
+++ b/strrncaseeqlen.c
@@ -0,0 +1,44 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifndef TEST
+
+
+extern inline size_t libsimple_strrncaseeqlen(const char *, const char *, size_t);
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ size_t i, j, n;
+
+ for (n = 0; n < 10; n++) {
+ char a[] = "abcdefgh", b[] = "ABCDEFGH";
+ size_t I, J;
+ assert(libsimple_strrncaseeqlen("", "", n) == 0);
+ assert(libsimple_strrncaseeqlen("x", "", n) == 0);
+ assert(libsimple_strrncaseeqlen("x", "y", n) == 0);
+ assert(libsimple_strrncaseeqlen("", "y", n) == 0);
+ for (i = 0; i <= 8; i++) {
+ for (j = 0; j <= 8; j++) {
+ I = 8 - i;
+ J = 8 - j;
+ assert(libsimple_strrncaseeqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J))));
+ assert(libsimple_strrncaseeqlen(&b[i], &a[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J))));
+ a[i] = b[j] = '\0';
+ assert(libsimple_strrncaseeqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0));
+ assert(libsimple_strrncaseeqlen(b, a, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0));
+ a[i] = "abcdefgh"[i];
+ b[j] = "ABCDEFGH"[j];
+ }
+ }
+ assert(libsimple_strrncaseeqlen("abc", "abc", n) == MIN(3, n));
+ assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n));
+ }
+
+ return 0;
+}
+
+#endif