New module 'uniconv/u32-strconv-from-locale'.
[gnulib.git] / lib / mbswidth.c
index 754d6df..0bc1a68 100644 (file)
@@ -1,5 +1,5 @@
 /* Determine the number of screen columns needed for a string.
-   Copyright (C) 2000-2006 Free Software Foundation, Inc.
+   Copyright (C) 2000-2007 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -17,9 +17,7 @@
 
 /* Written by Bruno Haible <haible@clisp.cons.org>.  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
 
 /* Specification.  */
 #include "mbswidth.h"
 /* Get isprint().  */
 #include <ctype.h>
 
-/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth().  */
+/* Get mbstate_t, mbrtowc(), mbsinit().  */
+#include <wchar.h>
+
+/* Get wcwidth().  */
 #include "wcwidth.h"
 
 /* Get iswcntrl().  */
-#if !defined iswcntrl && !HAVE_ISWCNTRL
-# define iswcntrl(wc) 0
-#endif
+#include <wctype.h>
 
 #ifndef mbsinit
 # if !HAVE_MBSINIT
 # endif
 #endif
 
-/* Get ISPRINT.  */
-#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
-# define IN_CTYPE_DOMAIN(c) 1
-#else
-# define IN_CTYPE_DOMAIN(c) isascii(c)
-#endif
-/* Undefine to protect against the definition in wctype.h of Solaris 2.6.   */
-#undef ISPRINT
-#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
-#undef ISCNTRL
-#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
-
 /* Returns the number of columns needed to represent the multibyte
    character string pointed to by STRING.  If a non-printable character
    occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned.
@@ -181,10 +168,10 @@ mbsnwidth (const char *string, size_t nbytes, int flags)
     {
       unsigned char c = (unsigned char) *p++;
 
-      if (ISPRINT (c))
+      if (isprint (c))
        width++;
       else if (!(flags & MBSW_REJECT_UNPRINTABLE))
-       width += (ISCNTRL (c) ? 0 : 1);
+       width += (iscntrl (c) ? 0 : 1);
       else
        return -1;
     }