Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/wcwidth.c @ 16229:daac1ca4c436
inttypes: Modernize.
* lib/inttypes.in.h (strtoimax, strtoumax): Use the C++ safe idioms.
* modules/inttypes-incomplete (Depends-on): Add snippet/c++defs.
(Makefile.am): Update inttypes.h rule.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 05 Jan 2012 18:42:08 +0100 |
parents | 8250f2777afc |
children | a9e289a3a38d |
rev | line source |
---|---|
9071
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Determine the number of screen columns needed for a character. |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
2 Copyright (C) 2006-2007, 2010-2012 Free Software Foundation, Inc. |
9071
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9075
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
9071
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9075
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9075
diff
changeset
|
7 (at your option) any later version. |
9071
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9075
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
9071
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 #include <config.h> |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 /* Specification. */ |
9073
eff03f4ce262
Remove the wcwidth.h file. Move wcwidth's declaration to wchar_.h.
Bruno Haible <bruno@clisp.org>
parents:
9071
diff
changeset
|
20 #include <wchar.h> |
9071
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 /* Get iswprint. */ |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <wctype.h> |
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 |
9075
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
25 #include "localcharset.h" |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
26 #include "streq.h" |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
27 #include "uniwidth.h" |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
28 |
13135
3500e68d2a04
wcwidth: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
29 int |
3500e68d2a04
wcwidth: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
30 wcwidth (wchar_t wc) |
9075
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
31 #undef wcwidth |
9071
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 { |
9075
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
33 /* In UTF-8 locales, use a Unicode aware width function. */ |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
34 const char *encoding = locale_charset (); |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
35 if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0)) |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
36 { |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
37 /* We assume that in a UTF-8 locale, a wide character is the same as a |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
38 Unicode character. */ |
9075
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
39 return uc_width (wc, encoding); |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
40 } |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
41 else |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
42 { |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
43 /* Otherwise, fall back to the system's wcwidth function. */ |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
44 #if HAVE_WCWIDTH |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
45 return wcwidth (wc); |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
46 #else |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
47 return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
48 #endif |
4d262fc1845c
Work around MacOS X wcwidth(0x0301) bug.
Bruno Haible <bruno@clisp.org>
parents:
9073
diff
changeset
|
49 } |
9071
ee2dc6c88b11
Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 } |