bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: prohibit_strcmp


From: Bruno Haible
Subject: Re: prohibit_strcmp
Date: Fri, 24 Feb 2012 12:35:12 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

Jim Meyering wrote:
> > Akim suggests to rename STREQ in lib/streq.h; what name would you suggest?
> 
> STREQ_ retains the name and look while adding only one to the length.
> STREQ_opt is more descriptive, but longer

I generally prefer the more descriptive names. So, committed as follows:


2012-02-24  Bruno Haible  <address@hidden>

        streq: Rename macro.
        * lib/streq.h (STREQ_OPT): Renamed from STREQ.
        * NEWS: Mention the change.
        * lib/mbrtowc.c (mbrtowc): Update.
        * lib/uniwidth/cjk.h (is_cjk_encoding): Update.
        * lib/wcwidth.c (wcwidth): Update.
        Suggested by Akim Demaille and Jim Meyering.

--- NEWS.orig   Fri Feb 24 12:30:04 2012
+++ NEWS        Fri Feb 24 12:28:54 2012
@@ -21,6 +21,9 @@
 
 Date        Modules         Changes
 
+2012-02-24  streq           This module no longer provides the STREQ macro.
+                            Use STREQ_OPT instead.
+
 2012-01-10  ignore-value    This module no longer provides the ignore_ptr
                             function.  It was deprecated a year ago, but 
existed
                             so briefly before then that it never came into use.
--- lib/mbrtowc.c.orig  Fri Feb 24 12:30:04 2012
+++ lib/mbrtowc.c       Fri Feb 24 12:26:06 2012
@@ -128,7 +128,7 @@
       {
         const char *encoding = locale_charset ();
 
-        if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
+        if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
           {
             /* Cf. unistr/u8-mblen.c.  */
             unsigned char c = (unsigned char) p[0];
@@ -185,7 +185,8 @@
         /* As a reference for this code, you can use the GNU libiconv
            implementation.  Look for uses of the RET_TOOFEW macro.  */
 
-        if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
+        if (STREQ_OPT (encoding,
+                       "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
           {
             if (m == 1)
               {
@@ -208,9 +209,12 @@
               }
             goto invalid;
           }
-        if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
-            || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 
0)
-            || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
+        if (STREQ_OPT (encoding,
+                       "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+            || STREQ_OPT (encoding,
+                          "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
+            || STREQ_OPT (encoding,
+                          "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
           {
             if (m == 1)
               {
@@ -221,7 +225,8 @@
               }
             goto invalid;
           }
-        if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
+        if (STREQ_OPT (encoding,
+                       "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
           {
             if (m == 1)
               {
@@ -239,7 +244,8 @@
               }
             goto invalid;
           }
-        if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 
0))
+        if (STREQ_OPT (encoding,
+                       "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
           {
             if (m == 1)
               {
@@ -272,7 +278,7 @@
               }
             goto invalid;
           }
-        if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
+        if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
           {
             if (m == 1)
               {
--- lib/streq.h.orig    Fri Feb 24 12:30:04 2012
+++ lib/streq.h Fri Feb 24 12:27:47 2012
@@ -21,8 +21,8 @@
 
 #include <string.h>
 
-/* STREQ allows to optimize string comparison with a small literal string.
-     STREQ (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+/* STREQ_OPT allows to optimize string comparison with a small literal string.
+     STREQ_OPT (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
    is semantically equivalent to
      strcmp (s, "EUC-KR") == 0
    just faster.  */
@@ -163,12 +163,12 @@
     return 0;
 }
 
-#define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
   streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
 
 #else
 
-#define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
   (strcmp (s1, s2) == 0)
 
 #endif
--- lib/uniwidth/cjk.h.orig     Fri Feb 24 12:30:04 2012
+++ lib/uniwidth/cjk.h  Fri Feb 24 12:24:07 2012
@@ -22,16 +22,16 @@
 {
   if (0
       /* Legacy Japanese encodings */
-      || STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)
+      || STREQ_OPT (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)
       /* Legacy Chinese encodings */
-      || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
-      || STREQ (encoding, "GBK", 'G', 'B', 'K', 0, 0, 0, 0, 0, 0)
-      || STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)
-      || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)
+      || STREQ_OPT (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
+      || STREQ_OPT (encoding, "GBK", 'G', 'B', 'K', 0, 0, 0, 0, 0, 0)
+      || STREQ_OPT (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)
+      || STREQ_OPT (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)
       /* Legacy Korean encodings */
-      || STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
-      || STREQ (encoding, "CP949", 'C', 'P', '9', '4', '9', 0, 0, 0, 0)
-      || STREQ (encoding, "JOHAB", 'J', 'O', 'H', 'A', 'B', 0, 0, 0, 0))
+      || STREQ_OPT (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+      || STREQ_OPT (encoding, "CP949", 'C', 'P', '9', '4', '9', 0, 0, 0, 0)
+      || STREQ_OPT (encoding, "JOHAB", 'J', 'O', 'H', 'A', 'B', 0, 0, 0, 0))
     return 1;
   return 0;
 }
--- lib/wcwidth.c.orig  Fri Feb 24 12:30:04 2012
+++ lib/wcwidth.c       Fri Feb 24 12:26:17 2012
@@ -32,7 +32,7 @@
 {
   /* In UTF-8 locales, use a Unicode aware width function.  */
   const char *encoding = locale_charset ();
-  if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0))
+  if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0))
     {
       /* We assume that in a UTF-8 locale, a wide character is the same as a
          Unicode character.  */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]