1 /* Iterate over previous character in UTF-8 string.
2 Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2002.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published
7 by 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start)
28 /* Keep in sync with unistr.h and utf8-ucs4.c. */
38 #if CONFIG_UNICODE_SAFETY
39 if ((c_1 ^ 0x80) < 0x40)
45 if (c_2 >= 0xc2 && c_2 < 0xe0)
47 *puc = ((unsigned int) (c_2 & 0x1f) << 6)
48 | (unsigned int) (c_1 ^ 0x80);
51 #if CONFIG_UNICODE_SAFETY
52 if ((c_2 ^ 0x80) < 0x40)
58 if (c_3 >= 0xe0 && c_3 < 0xf0
59 #if CONFIG_UNICODE_SAFETY
60 && (c_3 >= 0xe1 || c_2 >= 0xa0)
61 && (c_3 != 0xed || c_2 < 0xa0)
65 *puc = ((unsigned int) (c_3 & 0x0f) << 12)
66 | ((unsigned int) (c_2 ^ 0x80) << 6)
67 | (unsigned int) (c_1 ^ 0x80);
70 #if CONFIG_UNICODE_SAFETY
71 if ((c_3 ^ 0x80) < 0x40)
77 if (c_4 >= 0xf0 && c_4 < 0xf8
78 #if CONFIG_UNICODE_SAFETY
79 && (c_4 >= 0xf1 || c_3 >= 0x90)
80 && (c_4 < 0xf4 || (c_4 == 0xf4 && c_3 < 0x90))
84 *puc = ((unsigned int) (c_4 & 0x07) << 18)
85 | ((unsigned int) (c_3 ^ 0x80) << 12)
86 | ((unsigned int) (c_2 ^ 0x80) << 6)
87 | (unsigned int) (c_1 ^ 0x80);