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)
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. */
22 /* Return the length (number of units) of the first character in S, putting
23 its 'ucs4_t' representation in *PUC. */
25 u16_mbtouc_aux (unsigned int *puc
, const unsigned short *s
, size_t n
)
27 unsigned short c
= *s
;
33 if (s
[1] >= 0xdc00 && s
[1] < 0xe000)
35 *puc
= 0x10000 + ((c
- 0xd800) << 10) + (s
[1] - 0xdc00);
38 /* invalid multibyte character */
42 /* incomplete multibyte character */
47 /* invalid multibyte character */
52 u16_mbtouc (unsigned int *puc
, const unsigned short *s
, size_t n
)
54 unsigned short c
= *s
;
56 if (c
< 0xd800 || c
>= 0xe000)
62 return u16_mbtouc_aux (puc
, s
, n
);