]> git.cworth.org Git - tar/blob - gnu/wcwidth.c
a10274436ac6a03dfdd0fcf6fd70c1af15139981
[tar] / gnu / wcwidth.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Determine the number of screen columns needed for a character.
4    Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #include <config.h>
20
21 /* Specification.  */
22 #include <wchar.h>
23
24 /* Get iswprint.  */
25 #include <wctype.h>
26
27 #include "localcharset.h"
28 #include "streq.h"
29 #include "uniwidth.h"
30
31 #undef wcwidth
32
33 int
34 rpl_wcwidth (wchar_t wc)
35 {
36   /* In UTF-8 locales, use a Unicode aware width function.  */
37   const char *encoding = locale_charset ();
38   if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0))
39     {
40       /* We assume that in a UTF-8 locale, a wide character is the same as a
41          Unicode character.  */
42       return uc_width (wc, encoding);
43     }
44   else
45     {
46       /* Otherwise, fall back to the system's wcwidth function.  */
47 #if HAVE_WCWIDTH
48       return wcwidth (wc);
49 #else
50       return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
51 #endif
52     }
53 }