On Mon, Apr 04, 2011 at 06:44:10PM +0000, Miod Vallat wrote:
> > > Would it be better maybe to do the check in the Width() macro itself?
> > 
> > Yes indeed. New diff below.
> 
> > -#define Width(c)   wcwidth(c)
> > +#define Width(c)   (wcwidth(c) == -1 ? 0 : wcwidth(c))
> 
> But this calls wcwidth() to be invoked twice, which is ugly. As a
> minimum, make this an inline function.

Oops, already committed. What about this as a follow-up?

Index: chartype.c
===================================================================
RCS file: /cvs/src/lib/libedit/chartype.c,v
retrieving revision 1.2
diff -u -p -r1.2 chartype.c
--- chartype.c  4 Apr 2011 18:48:17 -0000       1.2
+++ chartype.c  4 Apr 2011 19:01:49 -0000
@@ -358,3 +358,14 @@ ct_chr_class(Char c)
        else
                return CHTYPE_NONPRINT;
 }
+
+inline int
+Width(Int c)
+{
+#ifdef WIDECHAR
+       int w = wcwidth(c);
+       return (w == -1 ? 0 : w);
+#else
+       return 1;
+#endif
+}
Index: chartype.h
===================================================================
RCS file: /cvs/src/lib/libedit/chartype.h,v
retrieving revision 1.2
diff -u -p -r1.2 chartype.h
--- chartype.h  4 Apr 2011 18:48:17 -0000       1.2
+++ chartype.h  4 Apr 2011 19:01:25 -0000
@@ -106,8 +106,6 @@
 
 #define Strtol(p,e,b)   wcstol(p,e,b)
 
-#define Width(c)       (wcwidth(c) == -1 ? 0 : wcwidth(c))
-
 #else /* NARROW */
 
 #define ct_mbtowc            error
@@ -156,10 +154,9 @@
 
 #define Strtol(p,e,b)   strtol(p,e,b)
 
-#define Width(c)       1
-
 #endif
 
+int Width(Int c);
 
 #ifdef WIDECHAR
 /*

Reply via email to