diff options
Diffstat (limited to 'lib/unigbrk/u8-grapheme-prev.c')
-rw-r--r-- | lib/unigbrk/u8-grapheme-prev.c | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/lib/unigbrk/u8-grapheme-prev.c b/lib/unigbrk/u8-grapheme-prev.c index 8a63f55f..a2d872f0 100644 --- a/lib/unigbrk/u8-grapheme-prev.c +++ b/lib/unigbrk/u8-grapheme-prev.c @@ -1,6 +1,5 @@ /* Previous grapheme cluster function. - Copyright (C) 2010-2024 Free Software Foundation, Inc. - Written by Ben Pfaff <blp@cs.stanford.edu>, 2010. + Copyright (C) 2010-2025 Free Software Foundation, Inc. This file is free software. It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+". @@ -23,40 +22,20 @@ License and of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/* Written by Bruno Haible <bruno@clisp.org>, 2025. */ + +/* Don't use the const-improved function macros in this compilation unit. */ +#define _LIBUNISTRING_NO_CONST_GENERICS + #include <config.h> /* Specification. */ #include "unigbrk.h" +#include "unictype.h" #include "unistr.h" -const uint8_t * -u8_grapheme_prev (const uint8_t *s, const uint8_t *start) -{ - ucs4_t next; - - if (s == start) - return NULL; - - s = u8_prev (&next, s, start); - while (s != start) - { - const uint8_t *prev_s; - ucs4_t prev; - - prev_s = u8_prev (&prev, s, start); - if (prev_s == NULL) - { - /* Ill-formed UTF-8 encoding. */ - return start; - } - - if (uc_is_grapheme_break (prev, next)) - break; - - s = prev_s; - next = prev; - } - - return s; -} +#define FUNC u8_grapheme_prev +#define UNIT uint8_t +#define U_PREV u8_prev +#include "u-grapheme-prev.h" |