1 /* Conversion UCS-4 to UTF-16.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 Written by Bruno Haible <haible@clisp.cons.org>, 2002.
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 UTF-16 representation of uc,
23 after storing it at S. Return -1 upon failure, -2 if the number of
24 available units, N, is too small. */
26 u16_uctomb_aux (unsigned short *s
, unsigned int uc
, int n
)
34 s
[0] = 0xd800 + ((uc
- 0x10000) >> 10);
35 s
[1] = 0xdc00 + ((uc
- 0x10000) & 0x3ff);
46 u16_uctomb (unsigned short *s
, unsigned int uc
, int n
)
48 if (uc
< 0x10000 && n
> 0)
54 return u16_uctomb_aux (s
, uc
, n
);