This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
handy.h: add strEQs() and strNEs() for comparing to constant strings
authorYves Orton <demerphq@gmail.com>
Wed, 19 Oct 2016 08:30:44 +0000 (10:30 +0200)
committerYves Orton <demerphq@gmail.com>
Wed, 19 Oct 2016 11:27:59 +0000 (13:27 +0200)
They use strncmp() and derive the length using STR_WITH_LEN style
tricks in the wrapper call.

handy.h

diff --git a/handy.h b/handy.h
index 11009d3..8111309 100644 (file)
--- a/handy.h
+++ b/handy.h
@@ -481,15 +481,20 @@ Returns zero if non-equal, or non-zero if equal.
 =cut
 */
 
+
 #define strNE(s1,s2) (strcmp(s1,s2))
 #define strEQ(s1,s2) (!strcmp(s1,s2))
 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
+
 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
 
+#define strNEs(s1,s2) (strncmp(s1,"" s2 "", sizeof(s2)-1))
+#define strEQs(s1,s2) (!strncmp(s1,"" s2 "", sizeof(s2)-1))
+
 #ifdef HAS_MEMCMP
 #  define memNE(s1,s2,l) (memcmp(s1,s2,l))
 #  define memEQ(s1,s2,l) (!memcmp(s1,s2,l))