Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / lib / utf16-ucs4.h
blob48caab4b80587ebfb28048d352705945477233b8
1 /* Conversion UTF-16 to UCS-4.
2 Copyright (C) 2001-2002 Free Software Foundation, Inc.
3 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include <stddef.h>
22 /* Return the length (number of units) of the first character in S, putting
23 its 'ucs4_t' representation in *PUC. */
24 static int
25 u16_mbtouc_aux (unsigned int *puc, const unsigned short *s, size_t n)
27 unsigned short c = *s;
29 if (c < 0xdc00)
31 if (n >= 2)
33 if (s[1] >= 0xdc00 && s[1] < 0xe000)
35 *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00);
36 return 2;
38 /* invalid multibyte character */
40 else
42 /* incomplete multibyte character */
43 *puc = 0xfffd;
44 return n;
47 /* invalid multibyte character */
48 *puc = 0xfffd;
49 return 1;
51 static inline int
52 u16_mbtouc (unsigned int *puc, const unsigned short *s, size_t n)
54 unsigned short c = *s;
56 if (c < 0xd800 || c >= 0xe000)
58 *puc = c;
59 return 1;
61 else
62 return u16_mbtouc_aux (puc, s, n);