annotate lib/unistr/u16-prev.c @ 17431:744044c581c4

getcwd-lgpl: port to Tru64 * lib/getcwd-lgpl.c: Include <stdlib.h>, for malloc etc. Problem reported by Steven M. Schweda in <http://lists.gnu.org/archive/html/bug-gzip/2013-06/msg00010.html>.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 11 Jun 2013 19:52:46 -0700
parents e542fd46ad6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Iterate over previous character in UTF-16 string.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2002, 2006-2007, 2009-2013 Free Software Foundation, Inc.
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2002.
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9307
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8507
diff changeset
5 This program is free software: you can redistribute it and/or modify it
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8507
diff changeset
6 under the terms of the GNU Lesser General Public License as published
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8507
diff changeset
7 by the Free Software Foundation; either version 3 of the License, or
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8507
diff changeset
8 (at your option) any later version.
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9307
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8507
diff changeset
13 Lesser General Public License for more details.
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
9307
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8507
diff changeset
15 You should have received a copy of the GNU Lesser General Public License
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8507
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "unistr.h"
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 const uint16_t *
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start)
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 {
8507
2d9de99c11d9 Drop the include files utf8-ucs4.h, utf8-ucs4-unsafe.h, utf16-ucs4.h,
Bruno Haible <bruno@clisp.org>
parents: 7824
diff changeset
26 /* Keep in sync with unistr.h and utf16-ucs4.c. */
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 if (s != start)
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 {
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 uint16_t c_1 = s[-1];
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 if (c_1 < 0xd800 || c_1 >= 0xe000)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
32 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
33 *puc = c_1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
34 return s - 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
35 }
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #if CONFIG_UNICODE_SAFETY
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 if (c_1 >= 0xdc00)
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
39 if (s - 1 != start)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
40 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
41 uint16_t c_2 = s[-2];
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #if CONFIG_UNICODE_SAFETY
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
44 if (c_2 >= 0xd800 && c_2 < 0xdc00)
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
46 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
47 *puc = 0x10000 + ((c_2 - 0xd800) << 10) + (c_1 - 0xdc00);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
48 return s - 2;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
49 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9307
diff changeset
50 }
7824
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 }
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 return NULL;
af4391ae3012 New modules 'unistr/u8-prev', 'unistr/u16-prev', 'unistr/u32-prev'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 }