]> git.cworth.org Git - tar/blob - gnu/wcwidth.c
Imported Upstream version 1.24
[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, 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 int
32 wcwidth (wchar_t wc)
33 #undef wcwidth
34 {
35   /* In UTF-8 locales, use a Unicode aware width function.  */
36   const char *encoding = locale_charset ();
37   if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0))
38     {
39       /* We assume that in a UTF-8 locale, a wide character is the same as a
40          Unicode character.  */
41       return uc_width (wc, encoding);
42     }
43   else
44     {
45       /* Otherwise, fall back to the system's wcwidth function.  */
46 #if HAVE_WCWIDTH
47       return wcwidth (wc);
48 #else
49       return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
50 #endif
51     }
52 }