annotate lib/wcwidth.c @ 9071:ee2dc6c88b11

Provide wcwidth replacement in separate file wcwidth.c.
author Bruno Haible <bruno@clisp.org>
date Sat, 07 Jul 2007 19:27:06 +0000
parents
children eff03f4ce262
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2006, 2007 Free Software Foundation, Inc.
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
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
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
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
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "wcwidth.h"
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Get iswprint. */
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <wctype.h>
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 int
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 rpl_wcwidth (wchar_t wc)
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 {
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
ee2dc6c88b11 Provide wcwidth replacement in separate file wcwidth.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 }