X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fwcwidth.c;h=44503b04bba11a3848acac8429b1863e2731333e;hb=6417476607d4f04b1a7abf97fbfbb6bd2709e724;hp=6317083435d0bb5cd2638c196d3625134f737feb;hpb=2b3817550022a9a5c9cd89f4e5a3a77381ac328c;p=gnulib.git diff --git a/lib/wcwidth.c b/lib/wcwidth.c index 631708343..44503b04b 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-2012 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,19 +12,39 @@ 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 /* Specification. */ -#include "wcwidth.h" +#include /* 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_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. */ + 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 + } }