X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fwcwidth.c;h=66b5b15e0ba83f8203c6b4f170a37ecc96dacb29;hb=fcdbbe0069c767a03f42f7615175ac03494de93a;hp=57fb0a467bb8680964e601cc9881543f7995e501;hpb=9e8ce574adfade2243a6141a1655addb92512aeb;p=gnulib.git diff --git a/lib/wcwidth.c b/lib/wcwidth.c index 57fb0a467..66b5b15e0 100644 --- a/lib/wcwidth.c +++ b/lib/wcwidth.c @@ -1,10 +1,10 @@ /* Determine the number of screen columns needed for a character. - Copyright (C) 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2006-2007, 2010 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,8 +12,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ #include @@ -23,8 +22,29 @@ /* Get iswprint. */ #include +#include "localcharset.h" +#include "streq.h" +#include "uniwidth.h" + int -rpl_wcwidth (wchar_t wc) +wcwidth (wchar_t wc) +#undef wcwidth { - return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; + /* 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)) + { + /* We assume that in a UTF-8 locale, a wide character is the same as a + Unicode character. */ + return uc_width (wc, encoding); + } + else + { + /* Otherwise, fall back to the system's wcwidth function. */ +#if HAVE_WCWIDTH + return wcwidth (wc); +#else + return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; +#endif + } }