aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--libsimple/mem.h41
-rw-r--r--man/libsimple_memrcasechr.381
-rw-r--r--man/libsimple_memrchr.31
-rw-r--r--man/libsimple_rawmemcasechr.381
-rw-r--r--man/libsimple_rawmemchr.31
l---------man/memcasechr.3libsimple1
l---------man/memcasecmp.3libsimple1
l---------man/memcaseends.3libsimple1
l---------man/memcaseeq.3libsimple1
l---------man/memcasemem.3libsimple1
l---------man/memcasestarts.3libsimple1
l---------man/memrcasechr.3libsimple1
l---------man/memrcasemem.3libsimple1
l---------man/rawmemcasechr.3libsimple1
l---------man/rawmemrcasechr.3libsimple1
-rw-r--r--memrcasechr.c35
-rw-r--r--memrchr.c12
-rw-r--r--rawmemcasechr.c33
-rw-r--r--rawmemchr.c10
20 files changed, 300 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 78b071a..a3a7b31 100644
--- a/Makefile
+++ b/Makefile
@@ -66,6 +66,7 @@ OBJ =\
memeqlen.o\
memmem.o\
mempsetelem.o\
+ memrcasechr.o\
memrcaseeqlen.o\
memrchr.o\
memrelem.o\
@@ -75,6 +76,7 @@ OBJ =\
minimise_number_string.o\
multimespec.o\
multimeval.o\
+ rawmemcasechr.o\
rawmemchr.o\
rawmemrchr.o\
rawmemrchr.o\
diff --git a/libsimple/mem.h b/libsimple/mem.h
index 3092ddc..9f2f9a3 100644
--- a/libsimple/mem.h
+++ b/libsimple/mem.h
@@ -2,8 +2,6 @@
/* TODO memcasechr */
-/* TODO rawmemcasechr */
-/* TODO memrcasechr */
/* TODO rawmemrcasechr */
/* TODO memcasemem */
/* TODO memrcasemem */
@@ -35,6 +33,27 @@ void *libsimple_rawmemchr(const void *, int);
/**
+ * Finds the first occurence of a byte value in an array of bytes,
+ * the comparison is case-insensitive
+ *
+ * This function is optimised for instances where it is already
+ * known that there is at least one occurence; if is no occurence
+ * of the specified byte value in the specified byte array, this
+ * behaviour is undefined
+ *
+ * @param s The array of bytes to search
+ * @param c The byte value to search for
+ * @return `s` with a miminal offset such that `tolower(*r) == tolower(c)`,
+ * where `r` is the returned pointer
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__)))
+void *libsimple_rawmemcasechr(const void *, int);
+#ifndef rawmemcasechr
+# define rawmemcasechr libsimple_rawmemcasechr
+#endif
+
+
+/**
* Finds the last occurence of a byte value in an array of bytes,
* the comparison is case-sensitive
*
@@ -54,6 +73,24 @@ void *libsimple_memrchr(const void *, int, size_t);
/**
* Finds the last occurence of a byte value in an array of bytes,
+ * the comparison is case-insensitive
+ *
+ * @param s The array of bytes to search
+ * @param c The byte value to search for
+ * @param n The number of bytes in the byte array
+ * @return `s` with a maximal offset such that `*r == c`,
+ * where `r` is the returned pointer `NULL` if no
+ * such offset exists within [s, &s[n])
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__)))
+void *libsimple_memrcasechr(const void *, int, size_t);
+#ifndef memrcasechr
+# define memrcasechr libsimple_memrcasechr
+#endif
+
+
+/**
+ * Finds the last occurence of a byte value in an array of bytes,
* the comparison is case-sensitive
*
* This function is optimised for instances where it is already
diff --git a/man/libsimple_memrcasechr.3 b/man/libsimple_memrcasechr.3
new file mode 100644
index 0000000..be5b748
--- /dev/null
+++ b/man/libsimple_memrcasechr.3
@@ -0,0 +1,81 @@
+.TH LIBSIMPLE_MEMRCASECHR 3 2018-10-20 libsimple
+.SH NAME
+libsimple_memrcasechr \- find byte in memory
+.SH SYNOPSIS
+.nf
+#include <libsimple.h>
+
+void *libsimple_memrcasechr(const void *\fIs\fP, int \fIc\fP, size_t \fIn\fP);
+
+#ifndef memrcasechr
+# define memrcasechr libsimple_memrcasechr
+#endif
+.fi
+.PP
+Link with
+.IR \-lsimple .
+.SH DESCRIPTION
+The
+.BR libsimple_memrcasechr ()
+function scans the memory segment
+.IR s ,
+with the size
+.IR n ,
+for the last occurence of the byte
+.I c
+(it is converted to a
+.BR char ).
+.PP
+The comparison is case-insensitive.
+.SH RETURN VALUE
+The
+.BR libsimple_memrcasechr ()
+function returns the pointer
+.I s
+with a maximal offset such that
+.IR tolower(*r)==tolower(c) ,
+where
+.I r
+is the returned pointer.
+If no such offset exists,
+.B NULL
+is returned.
+.SH ERRORS
+The
+.BR libsimple_memrcasechr ()
+function cannot fail.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR libsimple_memrcasechr ()
+T} Thread safety MT-Safe
+T{
+.BR libsimple_memrcasechr ()
+T} Async-signal safety AS-Safe
+T{
+.BR libsimple_memrcasechr ()
+T} Async-cancel safety AC-Safe
+.TE
+.SH EXAMPLES
+None.
+.SH APPLICATION USAGE
+None.
+.SH RATIONALE
+None.
+.SH FUTURE DIRECTIONS
+None.
+.SH NOTES
+None.
+.SH BUGS
+None.
+.SH SEE ALSO
+.BR libsimple_memrchr (3),
+.BR libsimple_rawmemrcasechr (3),
+.BR libsimple_memrcasemem (3),
+.BR libsimple_memcasechr (3)
diff --git a/man/libsimple_memrchr.3 b/man/libsimple_memrchr.3
index 8fd74f7..958fbc9 100644
--- a/man/libsimple_memrchr.3
+++ b/man/libsimple_memrchr.3
@@ -75,6 +75,7 @@ None.
.SH BUGS
None.
.SH SEE ALSO
+.BR libsimple_memrcasechr (3),
.BR libsimple_rawmemrchr (3),
.BR libsimple_memrmem (3),
.BR memchr (3)
diff --git a/man/libsimple_rawmemcasechr.3 b/man/libsimple_rawmemcasechr.3
new file mode 100644
index 0000000..3759cd0
--- /dev/null
+++ b/man/libsimple_rawmemcasechr.3
@@ -0,0 +1,81 @@
+.TH LIBSIMPLE_RAWMEMCASECHR 3 2018-10-20 libsimple
+.SH NAME
+libsimple_rawmemcasechr \- find byte in memory
+.SH SYNOPSIS
+.nf
+#include <libsimple.h>
+
+void *libsimple_rawmemcasechr(const void *\fIs\fP, int \fIc\fP);
+
+#ifndef rawmemcasechr
+# define rawmemcasechr libsimple_rawmemcasechr
+#endif
+.fi
+.PP
+Link with
+.IR \-lsimple .
+.SH DESCRIPTION
+The
+.BR libsimple_rawmemcasechr ()
+function scans the memory segment
+.I s
+for the first occurence of the byte
+.I c
+(it is converted to a
+.BR char ).
+.PP
+The
+.BR libsimple_rawmemcasechr ()
+function assumes there is at least one
+occurence, its behaviour is undefined
+if this is not the case.
+.PP
+The comparison is case-insensitive.
+.SH RETURN VALUE
+The
+.BR libsimple_rawmemcasechr ()
+function returns the pointer
+.I s
+with a minimal offset such that
+.IR tolower(*r)==tolower(c) ,
+where
+.I r
+is the returned pointer.
+.SH ERRORS
+The
+.BR libsimple_rawmemcasechr ()
+function cannot fail.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR libsimple_rawmemcasechr ()
+T} Thread safety MT-Safe
+T{
+.BR libsimple_rawmemcasechr ()
+T} Async-signal safety AS-Safe
+T{
+.BR libsimple_rawmemcasechr ()
+T} Async-cancel safety AC-Safe
+.TE
+.SH EXAMPLES
+None.
+.SH APPLICATION USAGE
+None.
+.SH RATIONALE
+None.
+.SH FUTURE DIRECTIONS
+None.
+.SH NOTES
+None.
+.SH BUGS
+None.
+.SH SEE ALSO
+.BR libsimple_rawmemchr (3),
+.BR libsimple_rawmemrcasechr (3),
+.BR libsimple_memcasechr (3)
diff --git a/man/libsimple_rawmemchr.3 b/man/libsimple_rawmemchr.3
index 4126fbb..0425d9a 100644
--- a/man/libsimple_rawmemchr.3
+++ b/man/libsimple_rawmemchr.3
@@ -76,5 +76,6 @@ None.
.SH BUGS
None.
.SH SEE ALSO
+.BR libsimple_rawmemcasechr (3),
.BR libsimple_rawmemrchr (3),
.BR memchr (3)
diff --git a/man/memcasechr.3libsimple b/man/memcasechr.3libsimple
new file mode 120000
index 0000000..e7d10b2
--- /dev/null
+++ b/man/memcasechr.3libsimple
@@ -0,0 +1 @@
+libsimple_memcasechr.3 \ No newline at end of file
diff --git a/man/memcasecmp.3libsimple b/man/memcasecmp.3libsimple
new file mode 120000
index 0000000..275bff4
--- /dev/null
+++ b/man/memcasecmp.3libsimple
@@ -0,0 +1 @@
+libsimple_memcasecmp.3 \ No newline at end of file
diff --git a/man/memcaseends.3libsimple b/man/memcaseends.3libsimple
new file mode 120000
index 0000000..4068e05
--- /dev/null
+++ b/man/memcaseends.3libsimple
@@ -0,0 +1 @@
+libsimple_memcaseends.3 \ No newline at end of file
diff --git a/man/memcaseeq.3libsimple b/man/memcaseeq.3libsimple
new file mode 120000
index 0000000..0ec4ac0
--- /dev/null
+++ b/man/memcaseeq.3libsimple
@@ -0,0 +1 @@
+libsimple_memcaseeq.3 \ No newline at end of file
diff --git a/man/memcasemem.3libsimple b/man/memcasemem.3libsimple
new file mode 120000
index 0000000..a9c885d
--- /dev/null
+++ b/man/memcasemem.3libsimple
@@ -0,0 +1 @@
+libsimple_memcasemem.3 \ No newline at end of file
diff --git a/man/memcasestarts.3libsimple b/man/memcasestarts.3libsimple
new file mode 120000
index 0000000..c450aff
--- /dev/null
+++ b/man/memcasestarts.3libsimple
@@ -0,0 +1 @@
+libsimple_memcasestarts.3 \ No newline at end of file
diff --git a/man/memrcasechr.3libsimple b/man/memrcasechr.3libsimple
new file mode 120000
index 0000000..4337383
--- /dev/null
+++ b/man/memrcasechr.3libsimple
@@ -0,0 +1 @@
+libsimple_memrcasechr.3 \ No newline at end of file
diff --git a/man/memrcasemem.3libsimple b/man/memrcasemem.3libsimple
new file mode 120000
index 0000000..6b52d2c
--- /dev/null
+++ b/man/memrcasemem.3libsimple
@@ -0,0 +1 @@
+libsimple_memrcasemem.3 \ No newline at end of file
diff --git a/man/rawmemcasechr.3libsimple b/man/rawmemcasechr.3libsimple
new file mode 120000
index 0000000..2379e2a
--- /dev/null
+++ b/man/rawmemcasechr.3libsimple
@@ -0,0 +1 @@
+libsimple_rawmemcasechr.3 \ No newline at end of file
diff --git a/man/rawmemrcasechr.3libsimple b/man/rawmemrcasechr.3libsimple
new file mode 120000
index 0000000..8fd4d5c
--- /dev/null
+++ b/man/rawmemrcasechr.3libsimple
@@ -0,0 +1 @@
+libsimple_rawmemrcasechr.3 \ No newline at end of file
diff --git a/memrcasechr.c b/memrcasechr.c
new file mode 100644
index 0000000..e4fe52a
--- /dev/null
+++ b/memrcasechr.c
@@ -0,0 +1,35 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+void *
+libsimple_memrcasechr(const void *s_, int c, size_t n_)
+{
+ char *s = *(char **)(void *)&s_;
+ ssize_t n = n_;
+ c = tolower(c);
+ while (n-- && tolower(s[n]) != c);
+ return n < 0 ? NULL : &s[n];
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ assert(!strcmpnul(libsimple_memrcasechr("abcABCabcABC", 'a', sizeof("abcABCabcABC") - 1), "ABC"));
+ assert(!strcmpnul(libsimple_memrcasechr("abcABCabcABC", 'c', sizeof("abcABCabcABC") - 1), "C"));
+ assert(!strcmpnul(libsimple_memrcasechr("abcABCabcABC", 'A', sizeof("abcABCabcABC") - 1), "ABC"));
+ assert(!strcmpnul(libsimple_memrcasechr("abcABCabcABC", 'C', sizeof("abcABCabcABC") - 1), "C"));
+ assert(!strcmpnul(libsimple_memrcasechr("ABCabcABCabc", 'a', sizeof("ABCabcABCabc") - 1), "abc"));
+ assert(!strcmpnul(libsimple_memrcasechr("ABCabcABCabc", 'c', sizeof("ABCabcABCabc") - 1), "c"));
+ assert(!strcmpnul(libsimple_memrcasechr("ABCabcABCabc", 'A', sizeof("ABCabcABCabc") - 1), "abc"));
+ assert(!strcmpnul(libsimple_memrcasechr("ABCabcABCabc", 'C', sizeof("ABCabcABCabc") - 1), "c"));
+ assert(!libsimple_memrcasechr("abcABCabcABC", 'x', sizeof("abcABCabcABC") - 1));
+ return 0;
+}
+
+#endif
diff --git a/memrchr.c b/memrchr.c
index 30c818e..36385ec 100644
--- a/memrchr.c
+++ b/memrchr.c
@@ -19,9 +19,15 @@ libsimple_memrchr(const void *s_, int c_, size_t n_)
int
main(void)
{
- assert(!strcmpnul(libsimple_memrchr("1234512345", '3', sizeof("1234512345") - 1), "345"));
- assert(!strcmpnul(libsimple_memrchr("1234512345", '5', sizeof("1234512345") - 1), "5"));
- assert(!libsimple_memrchr("1234512345", 'x', sizeof("1234512345") - 1));
+ assert(!strcmpnul(libsimple_memrchr("abcABCabcABC", 'a', sizeof("abcABCabcABC") - 1), "abcABC"));
+ assert(!strcmpnul(libsimple_memrchr("abcABCabcABC", 'c', sizeof("abcABCabcABC") - 1), "cABC"));
+ assert(!strcmpnul(libsimple_memrchr("abcABCabcABC", 'A', sizeof("abcABCabcABC") - 1), "ABC"));
+ assert(!strcmpnul(libsimple_memrchr("abcABCabcABC", 'C', sizeof("abcABCabcABC") - 1), "C"));
+ assert(!strcmpnul(libsimple_memrchr("ABCabcABCabc", 'a', sizeof("ABCabcABCabc") - 1), "abc"));
+ assert(!strcmpnul(libsimple_memrchr("ABCabcABCabc", 'c', sizeof("ABCabcABCabc") - 1), "c"));
+ assert(!strcmpnul(libsimple_memrchr("ABCabcABCabc", 'A', sizeof("ABCabcABCabc") - 1), "ABCabc"));
+ assert(!strcmpnul(libsimple_memrchr("ABCabcABCabc", 'C', sizeof("ABCabcABCabc") - 1), "Cabc"));
+ assert(!libsimple_memrchr("abcABCabcABC", 'x', sizeof("abcABCabcABC") - 1));
return 0;
}
diff --git a/rawmemcasechr.c b/rawmemcasechr.c
new file mode 100644
index 0000000..3d3a101
--- /dev/null
+++ b/rawmemcasechr.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+void *
+libsimple_rawmemcasechr(const void *s_, int c)
+{
+ char *s = *(char **)(void *)&s_;
+ c = tolower(c);
+ for (; tolower(*s) != c; s++);
+ return s;
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ assert(!strcmpnul(libsimple_rawmemcasechr("abcABCabcABC", 'a'), "abcABCabcABC"));
+ assert(!strcmpnul(libsimple_rawmemcasechr("abcABCabcABC", 'c'), "cABCabcABC"));
+ assert(!strcmpnul(libsimple_rawmemcasechr("abcABCabcABC", 'A'), "abcABCabcABC"));
+ assert(!strcmpnul(libsimple_rawmemcasechr("abcABCabcABC", 'C'), "cABCabcABC"));
+ assert(!strcmpnul(libsimple_rawmemcasechr("ABCabcABCabc", 'a'), "ABCabcABCabc"));
+ assert(!strcmpnul(libsimple_rawmemcasechr("ABCabcABCabc", 'c'), "CabcABCabc"));
+ assert(!strcmpnul(libsimple_rawmemcasechr("ABCabcABCabc", 'A'), "ABCabcABCabc"));
+ assert(!strcmpnul(libsimple_rawmemcasechr("ABCabcABCabc", 'C'), "CabcABCabc"));
+ return 0;
+}
+
+#endif
diff --git a/rawmemchr.c b/rawmemchr.c
index e7803e2..2ed1709 100644
--- a/rawmemchr.c
+++ b/rawmemchr.c
@@ -18,8 +18,14 @@ libsimple_rawmemchr(const void *s_, int c_)
int
main(void)
{
- assert(!strcmpnul(libsimple_rawmemchr("1234512345", '3'), "34512345"));
- assert(!strcmpnul(libsimple_rawmemchr("1234512345", '1'), "1234512345"));
+ assert(!strcmpnul(libsimple_rawmemchr("abcABCabcABC", 'a'), "abcABCabcABC"));
+ assert(!strcmpnul(libsimple_rawmemchr("abcABCabcABC", 'c'), "cABCabcABC"));
+ assert(!strcmpnul(libsimple_rawmemchr("abcABCabcABC", 'A'), "ABCabcABC"));
+ assert(!strcmpnul(libsimple_rawmemchr("abcABCabcABC", 'C'), "CabcABC"));
+ assert(!strcmpnul(libsimple_rawmemchr("ABCabcABCabc", 'a'), "abcABCabc"));
+ assert(!strcmpnul(libsimple_rawmemchr("ABCabcABCabc", 'c'), "cABCabc"));
+ assert(!strcmpnul(libsimple_rawmemchr("ABCabcABCabc", 'A'), "ABCabcABCabc"));
+ assert(!strcmpnul(libsimple_rawmemchr("ABCabcABCabc", 'C'), "CabcABCabc"));
return 0;
}