diff options
| author | Jörg Frings-Fürst <debian@jff.email> | 2026-03-08 17:28:33 +0100 |
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff.email> | 2026-03-08 17:28:33 +0100 |
| commit | 5f59a34ab747dde8ede7357f3431bf06bd6002fe (patch) | |
| tree | 056a4477fd870d454d5be5868cddab829a47f4d2 /lib/unistr | |
| parent | 27dae84ed92f1ef0300263091972338d12e78348 (diff) | |
New upstream version 1.4.2upstream/1.4.2upstream
Diffstat (limited to 'lib/unistr')
154 files changed, 554 insertions, 585 deletions
diff --git a/lib/unistr/u-cmp2.h b/lib/unistr/u-cmp2.h index 89882846..d5e80ca3 100644 --- a/lib/unistr/u-cmp2.h +++ b/lib/unistr/u-cmp2.h @@ -1,5 +1,5 @@ /* Compare pieces of UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This file is free software. diff --git a/lib/unistr/u-cpy-alloc.h b/lib/unistr/u-cpy-alloc.h index baec6d73..001ce16e 100644 --- a/lib/unistr/u-cpy-alloc.h +++ b/lib/unistr/u-cpy-alloc.h @@ -1,5 +1,5 @@ /* Copy piece of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u-cpy.h b/lib/unistr/u-cpy.h index 447c65aa..b683a4a2 100644 --- a/lib/unistr/u-cpy.h +++ b/lib/unistr/u-cpy.h @@ -1,5 +1,5 @@ /* Copy piece of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u-endswith.h b/lib/unistr/u-endswith.h index d157804a..36f0848b 100644 --- a/lib/unistr/u-endswith.h +++ b/lib/unistr/u-endswith.h @@ -1,5 +1,5 @@ /* Substring test for UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-move.h b/lib/unistr/u-move.h index cd4a88af..3f1d1b78 100644 --- a/lib/unistr/u-move.h +++ b/lib/unistr/u-move.h @@ -1,5 +1,5 @@ /* Copy piece of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-pcpy.h b/lib/unistr/u-pcpy.h index 67155703..1dd6437c 100644 --- a/lib/unistr/u-pcpy.h +++ b/lib/unistr/u-pcpy.h @@ -1,5 +1,5 @@ /* Copy piece of UTF-8/16/32 string, return pointer after last written unit. - Copyright (C) 2020-2025 Free Software Foundation, Inc. + Copyright (C) 2020-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2023. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u-set.h b/lib/unistr/u-set.h index effe8564..22777c2f 100644 --- a/lib/unistr/u-set.h +++ b/lib/unistr/u-set.h @@ -1,5 +1,5 @@ /* Fill UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-startswith.h b/lib/unistr/u-startswith.h index f398a94e..5a849142 100644 --- a/lib/unistr/u-startswith.h +++ b/lib/unistr/u-startswith.h @@ -1,5 +1,5 @@ /* Substring test for UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-stpcpy.h b/lib/unistr/u-stpcpy.h index b4bb70d9..30968f7b 100644 --- a/lib/unistr/u-stpcpy.h +++ b/lib/unistr/u-stpcpy.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-stpncpy.h b/lib/unistr/u-stpncpy.h index cd9ed379..4420b5cc 100644 --- a/lib/unistr/u-stpncpy.h +++ b/lib/unistr/u-stpncpy.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-strcat.h b/lib/unistr/u-strcat.h index 13076c70..3afb9cf2 100644 --- a/lib/unistr/u-strcat.h +++ b/lib/unistr/u-strcat.h @@ -1,5 +1,5 @@ /* Concatenate UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u-strcoll.h b/lib/unistr/u-strcoll.h index e53feb02..8279e68c 100644 --- a/lib/unistr/u-strcoll.h +++ b/lib/unistr/u-strcoll.h @@ -1,6 +1,6 @@ /* Compare UTF-8/UTF-16/UTF-32 strings using the collation rules of the current locale. - Copyright (C) 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This file is free software. diff --git a/lib/unistr/u-strcpy.h b/lib/unistr/u-strcpy.h index 80975351..fa948ad1 100644 --- a/lib/unistr/u-strcpy.h +++ b/lib/unistr/u-strcpy.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-strcspn.h b/lib/unistr/u-strcspn.h index bbc75ed9..a12c4172 100644 --- a/lib/unistr/u-strcspn.h +++ b/lib/unistr/u-strcspn.h @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-strdup.h b/lib/unistr/u-strdup.h index 99ff4cb2..9b8e7b90 100644 --- a/lib/unistr/u-strdup.h +++ b/lib/unistr/u-strdup.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u-strlen.h b/lib/unistr/u-strlen.h index d4e75f3a..af2ed80f 100644 --- a/lib/unistr/u-strlen.h +++ b/lib/unistr/u-strlen.h @@ -1,5 +1,5 @@ /* Determine length of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u-strncat.h b/lib/unistr/u-strncat.h index 3801bfba..974ddca9 100644 --- a/lib/unistr/u-strncat.h +++ b/lib/unistr/u-strncat.h @@ -1,5 +1,5 @@ /* Concatenate UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-strncpy.h b/lib/unistr/u-strncpy.h index e733b9b7..12c46c60 100644 --- a/lib/unistr/u-strncpy.h +++ b/lib/unistr/u-strncpy.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-strnlen.h b/lib/unistr/u-strnlen.h index 65e396be..3fb6e9b4 100644 --- a/lib/unistr/u-strnlen.h +++ b/lib/unistr/u-strnlen.h @@ -1,5 +1,5 @@ /* Determine bounded length of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-strpbrk.h b/lib/unistr/u-strpbrk.h index 9213c616..a7dcca82 100644 --- a/lib/unistr/u-strpbrk.h +++ b/lib/unistr/u-strpbrk.h @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-strspn.h b/lib/unistr/u-strspn.h index c3f67844..dcaac120 100644 --- a/lib/unistr/u-strspn.h +++ b/lib/unistr/u-strspn.h @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u-strtok.h b/lib/unistr/u-strtok.h index a48d3093..826d91e1 100644 --- a/lib/unistr/u-strtok.h +++ b/lib/unistr/u-strtok.h @@ -1,5 +1,5 @@ /* Tokenize UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-check.c b/lib/unistr/u16-check.c index 485bb8ea..facf858e 100644 --- a/lib/unistr/u16-check.c +++ b/lib/unistr/u16-check.c @@ -1,5 +1,5 @@ /* Check UTF-16 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-chr.c b/lib/unistr/u16-chr.c index 6c7999ad..75d75dfc 100644 --- a/lib/unistr/u16-chr.c +++ b/lib/unistr/u16-chr.c @@ -1,5 +1,5 @@ /* Search character in piece of UTF-16 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. @@ -35,8 +35,6 @@ uint16_t * u16_chr (const uint16_t *s, size_t n, ucs4_t uc) { - uint16_t c[2]; - if (uc < 0x10000) { uint16_t c0 = uc; @@ -48,21 +46,25 @@ u16_chr (const uint16_t *s, size_t n, ucs4_t uc) } } else - switch (u16_uctomb_aux (c, uc, 2)) - { - case 2: - if (n > 1) - { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; + { + uint16_t c[2]; + + switch (u16_uctomb_aux (c, uc, 2)) + { + case 2: + if (n > 1) + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; - for (n--; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1) - return (uint16_t *) s; - } - } - break; - } + for (n--; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1) + return (uint16_t *) s; + } + } + break; + } + } return NULL; } diff --git a/lib/unistr/u16-cmp.c b/lib/unistr/u16-cmp.c index cedf9d2e..8ebe5d22 100644 --- a/lib/unistr/u16-cmp.c +++ b/lib/unistr/u16-cmp.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-16 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -34,29 +34,27 @@ u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n) /* Note that the UTF-16 encoding does NOT preserve lexicographic order. Namely, if uc1 is a 16-bit character and [uc2a,uc2b] is a surrogate pair, we must enforce uc1 < [uc2a,uc2b], even if uc1 > uc2a. */ - for (; n > 0;) + for (; n > 0; n--) { uint16_t c1 = *s1++; uint16_t c2 = *s2++; - if (c1 == c2) + if (c1 != c2) { - n--; - continue; + if (c1 < 0xd800 || c1 >= 0xe000) + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } + else + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } + return (int)c1 - (int)c2; + /* > 0 if c1 > c2, < 0 if c1 < c2. */ } - if (c1 < 0xd800 || c1 >= 0xe000) - { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; - } - else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } - return (int)c1 - (int)c2; - /* > 0 if c1 > c2, < 0 if c1 < c2. */ } return 0; } diff --git a/lib/unistr/u16-cmp2.c b/lib/unistr/u16-cmp2.c index 7bf33bd5..27259e86 100644 --- a/lib/unistr/u16-cmp2.c +++ b/lib/unistr/u16-cmp2.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-16 strings. - Copyright (C) 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This file is free software. diff --git a/lib/unistr/u16-cpy-alloc.c b/lib/unistr/u16-cpy-alloc.c index b105a72e..c3cc36ec 100644 --- a/lib/unistr/u16-cpy-alloc.c +++ b/lib/unistr/u16-cpy-alloc.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-cpy.c b/lib/unistr/u16-cpy.c index 73bfc197..b8632273 100644 --- a/lib/unistr/u16-cpy.c +++ b/lib/unistr/u16-cpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-endswith.c b/lib/unistr/u16-endswith.c index 02f7955c..55f80578 100644 --- a/lib/unistr/u16-endswith.c +++ b/lib/unistr/u16-endswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-16 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-mblen.c b/lib/unistr/u16-mblen.c index d4f3e73a..0082594a 100644 --- a/lib/unistr/u16-mblen.c +++ b/lib/unistr/u16-mblen.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2025 Free Software + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u16-mbsnlen.c b/lib/unistr/u16-mbsnlen.c index 43f23c5b..211df43c 100644 --- a/lib/unistr/u16-mbsnlen.c +++ b/lib/unistr/u16-mbsnlen.c @@ -1,5 +1,5 @@ /* Count characters in UTF-16 string. - Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2007. This file is free software. @@ -31,9 +31,7 @@ size_t u16_mbsnlen (const uint16_t *s, size_t n) { - size_t characters; - - characters = 0; + size_t characters = 0; while (n > 0) { ucs4_t uc; diff --git a/lib/unistr/u16-mbtouc-aux.c b/lib/unistr/u16-mbtouc-aux.c index 1266e7da..4748141d 100644 --- a/lib/unistr/u16-mbtouc-aux.c +++ b/lib/unistr/u16-mbtouc-aux.c @@ -1,5 +1,5 @@ /* Conversion UTF-16 to UCS-4. - Copyright (C) 2001-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software. diff --git a/lib/unistr/u16-mbtouc-unsafe-aux.c b/lib/unistr/u16-mbtouc-unsafe-aux.c index b14e7296..4c2b9cf4 100644 --- a/lib/unistr/u16-mbtouc-unsafe-aux.c +++ b/lib/unistr/u16-mbtouc-unsafe-aux.c @@ -1,5 +1,5 @@ /* Conversion UTF-16 to UCS-4. - Copyright (C) 2001-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software. diff --git a/lib/unistr/u16-mbtouc-unsafe.c b/lib/unistr/u16-mbtouc-unsafe.c index 37c1a7cf..4f015ac5 100644 --- a/lib/unistr/u16-mbtouc-unsafe.c +++ b/lib/unistr/u16-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software. diff --git a/lib/unistr/u16-mbtouc.c b/lib/unistr/u16-mbtouc.c index a42437dc..37debe0b 100644 --- a/lib/unistr/u16-mbtouc.c +++ b/lib/unistr/u16-mbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software. diff --git a/lib/unistr/u16-mbtoucr.c b/lib/unistr/u16-mbtoucr.c index 0d94ec2b..6abfe551 100644 --- a/lib/unistr/u16-mbtoucr.c +++ b/lib/unistr/u16-mbtoucr.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string, returning an error code. - Copyright (C) 1999-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u16-move.c b/lib/unistr/u16-move.c index 70b64a2a..cdef80b0 100644 --- a/lib/unistr/u16-move.c +++ b/lib/unistr/u16-move.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-next.c b/lib/unistr/u16-next.c index d74ae224..e2cc035b 100644 --- a/lib/unistr/u16-next.c +++ b/lib/unistr/u16-next.c @@ -1,5 +1,5 @@ /* Iterate over next character in UTF-16 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -34,9 +34,7 @@ const uint16_t * u16_next (ucs4_t *puc, const uint16_t *s) { - int count; - - count = u16_strmbtouc (puc, s); + int count = u16_strmbtouc (puc, s); if (count > 0) return s + count; else diff --git a/lib/unistr/u16-pcpy.c b/lib/unistr/u16-pcpy.c index 042234bf..fd1f9ac4 100644 --- a/lib/unistr/u16-pcpy.c +++ b/lib/unistr/u16-pcpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-16 string, return pointer after last written unit. - Copyright (C) 2020-2025 Free Software Foundation, Inc. + Copyright (C) 2020-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2023. This file is free software. diff --git a/lib/unistr/u16-prev.c b/lib/unistr/u16-prev.c index 53823e06..b49a8e81 100644 --- a/lib/unistr/u16-prev.c +++ b/lib/unistr/u16-prev.c @@ -1,5 +1,5 @@ /* Iterate over previous character in UTF-16 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-set.c b/lib/unistr/u16-set.c index 9c830b7e..04d2ca2d 100644 --- a/lib/unistr/u16-set.c +++ b/lib/unistr/u16-set.c @@ -1,5 +1,5 @@ /* Fill UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-startswith.c b/lib/unistr/u16-startswith.c index cd873713..19769a08 100644 --- a/lib/unistr/u16-startswith.c +++ b/lib/unistr/u16-startswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-16 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-stpcpy.c b/lib/unistr/u16-stpcpy.c index 46fdfa3a..49abec53 100644 --- a/lib/unistr/u16-stpcpy.c +++ b/lib/unistr/u16-stpcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u16-stpncpy.c b/lib/unistr/u16-stpncpy.c index 04119635..6d9bfd70 100644 --- a/lib/unistr/u16-stpncpy.c +++ b/lib/unistr/u16-stpncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strcat.c b/lib/unistr/u16-strcat.c index 8ced49b5..64d525c3 100644 --- a/lib/unistr/u16-strcat.c +++ b/lib/unistr/u16-strcat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-16 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strchr.c b/lib/unistr/u16-strchr.c index 832c0e8f..4a533b0f 100644 --- a/lib/unistr/u16-strchr.c +++ b/lib/unistr/u16-strchr.c @@ -1,5 +1,5 @@ /* Search character in UTF-16 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. @@ -35,8 +35,6 @@ uint16_t * u16_strchr (const uint16_t *s, ucs4_t uc) { - uint16_t c[2]; - if (uc < 0x10000) { uint16_t c0 = uc; @@ -51,25 +49,29 @@ u16_strchr (const uint16_t *s, ucs4_t uc) return (uint16_t *) s; } else - switch (u16_uctomb_aux (c, uc, 2)) - { - case 2: - if (*s == 0) - goto notfound; + { + uint16_t c[2]; + + switch (u16_uctomb_aux (c, uc, 2)) { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; + case 2: + if (*s == 0) + goto notfound; + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; - for (;; s++) - { - if (s[1] == 0) - goto notfound; - if (*s == c0 && s[1] == c1) - break; - } - return (uint16_t *) s; + for (;; s++) + { + if (s[1] == 0) + goto notfound; + if (*s == c0 && s[1] == c1) + break; + } + return (uint16_t *) s; + } } - } + } notfound: return NULL; } diff --git a/lib/unistr/u16-strcmp.c b/lib/unistr/u16-strcmp.c index 8dd332d7..96c2c1cc 100644 --- a/lib/unistr/u16-strcmp.c +++ b/lib/unistr/u16-strcmp.c @@ -1,5 +1,5 @@ /* Compare UTF-16 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -38,21 +38,22 @@ u16_strcmp (const uint16_t *s1, const uint16_t *s2) { uint16_t c1 = *s1++; uint16_t c2 = *s2++; - if (c1 != 0 && c1 == c2) - continue; - if (c1 < 0xd800 || c1 >= 0xe000) + if (c1 == 0 || c1 != c2) { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; + if (c1 < 0xd800 || c1 >= 0xe000) + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } + else + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } + return (int)c1 - (int)c2; + /* > 0 if c1 > c2, < 0 if c1 < c2. */ } - else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } - return (int)c1 - (int)c2; - /* > 0 if c1 > c2, < 0 if c1 < c2. */ } } diff --git a/lib/unistr/u16-strcoll.c b/lib/unistr/u16-strcoll.c index 92239b4d..94a19fc1 100644 --- a/lib/unistr/u16-strcoll.c +++ b/lib/unistr/u16-strcoll.c @@ -1,5 +1,5 @@ /* Compare UTF-16 strings using the collation rules of the current locale. - Copyright (C) 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This file is free software. diff --git a/lib/unistr/u16-strcpy.c b/lib/unistr/u16-strcpy.c index 6d108246..7c1a3828 100644 --- a/lib/unistr/u16-strcpy.c +++ b/lib/unistr/u16-strcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strcspn.c b/lib/unistr/u16-strcspn.c index bfc5461b..180de924 100644 --- a/lib/unistr/u16-strcspn.c +++ b/lib/unistr/u16-strcspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strdup.c b/lib/unistr/u16-strdup.c index 68de4236..9dff85d7 100644 --- a/lib/unistr/u16-strdup.c +++ b/lib/unistr/u16-strdup.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strlen.c b/lib/unistr/u16-strlen.c index 24b77bd0..8b2b5837 100644 --- a/lib/unistr/u16-strlen.c +++ b/lib/unistr/u16-strlen.c @@ -1,5 +1,5 @@ /* Determine length of UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u16-strmblen.c b/lib/unistr/u16-strmblen.c index 51413046..3ca260c6 100644 --- a/lib/unistr/u16-strmblen.c +++ b/lib/unistr/u16-strmblen.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2025 Free Software + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u16-strmbtouc.c b/lib/unistr/u16-strmbtouc.c index d87ed759..8fb43df1 100644 --- a/lib/unistr/u16-strmbtouc.c +++ b/lib/unistr/u16-strmbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2025 Free Software + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u16-strncat.c b/lib/unistr/u16-strncat.c index dd701957..147f8fb4 100644 --- a/lib/unistr/u16-strncat.c +++ b/lib/unistr/u16-strncat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-16 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strncmp.c b/lib/unistr/u16-strncmp.c index 3bba6e22..795435a5 100644 --- a/lib/unistr/u16-strncmp.c +++ b/lib/unistr/u16-strncmp.c @@ -1,5 +1,5 @@ /* Compare UTF-16 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -34,29 +34,27 @@ u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n) /* Note that the UTF-16 encoding does NOT preserve lexicographic order. Namely, if uc1 is a 16-bit character and [uc2a,uc2b] is a surrogate pair, we must enforce uc1 < [uc2a,uc2b], even if uc1 > uc2a. */ - for (; n > 0;) + for (; n > 0; n--) { uint16_t c1 = *s1++; uint16_t c2 = *s2++; - if (c1 != 0 && c1 == c2) + if (c1 == 0 || c1 != c2) { - n--; - continue; + if (c1 < 0xd800 || c1 >= 0xe000) + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } + else + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } + return (int)c1 - (int)c2; + /* > 0 if c1 > c2, < 0 if c1 < c2, = 0 if c1 and c2 are both 0. */ } - if (c1 < 0xd800 || c1 >= 0xe000) - { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; - } - else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } - return (int)c1 - (int)c2; - /* > 0 if c1 > c2, < 0 if c1 < c2, = 0 if c1 and c2 are both 0. */ } return 0; } diff --git a/lib/unistr/u16-strncpy.c b/lib/unistr/u16-strncpy.c index d39caf5b..05d3ce05 100644 --- a/lib/unistr/u16-strncpy.c +++ b/lib/unistr/u16-strncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strnlen.c b/lib/unistr/u16-strnlen.c index a00d5d8f..a41d2968 100644 --- a/lib/unistr/u16-strnlen.c +++ b/lib/unistr/u16-strnlen.c @@ -1,5 +1,5 @@ /* Determine bounded length of UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strpbrk.c b/lib/unistr/u16-strpbrk.c index e9a65088..b846188b 100644 --- a/lib/unistr/u16-strpbrk.c +++ b/lib/unistr/u16-strpbrk.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strrchr.c b/lib/unistr/u16-strrchr.c index 6aa7c407..f00d0cd7 100644 --- a/lib/unistr/u16-strrchr.c +++ b/lib/unistr/u16-strrchr.c @@ -1,5 +1,5 @@ /* Search character in UTF-16 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. @@ -38,7 +38,6 @@ u16_strrchr (const uint16_t *s, ucs4_t uc) /* Calling u16_strlen and then searching from the other end would cause more memory accesses. Avoid that, at the cost of a few more comparisons. */ uint16_t *result = NULL; - uint16_t c[2]; if (uc < 0x10000) { @@ -53,24 +52,28 @@ u16_strrchr (const uint16_t *s, ucs4_t uc) } } else - switch (u16_uctomb_aux (c, uc, 2)) - { - case 2: - if (*s) - { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; + { + uint16_t c[2]; + + switch (u16_uctomb_aux (c, uc, 2)) + { + case 2: + if (*s) + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; - /* FIXME: Maybe walking the string via u16_mblen is a win? */ - for (;; s++) - { - if (s[1] == 0) - break; - if (*s == c0 && s[1] == c1) - result = (uint16_t *) s; - } - } - break; - } + /* FIXME: Maybe walking the string via u16_mblen is a win? */ + for (;; s++) + { + if (s[1] == 0) + break; + if (*s == c0 && s[1] == c1) + result = (uint16_t *) s; + } + } + break; + } + } return result; } diff --git a/lib/unistr/u16-strspn.c b/lib/unistr/u16-strspn.c index 3b76049c..1494b570 100644 --- a/lib/unistr/u16-strspn.c +++ b/lib/unistr/u16-strspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strstr.c b/lib/unistr/u16-strstr.c index 6e0681dc..e2c1d480 100644 --- a/lib/unistr/u16-strstr.c +++ b/lib/unistr/u16-strstr.c @@ -1,5 +1,5 @@ /* Substring test for UTF-16 strings. - Copyright (C) 1999, 2002, 2006, 2010-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2010-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-strtok.c b/lib/unistr/u16-strtok.c index 2d2b977b..7eaed457 100644 --- a/lib/unistr/u16-strtok.c +++ b/lib/unistr/u16-strtok.c @@ -1,5 +1,5 @@ /* Tokenize UTF-16 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-to-u32.c b/lib/unistr/u16-to-u32.c index 51e42262..d5229ca8 100644 --- a/lib/unistr/u16-to-u32.c +++ b/lib/unistr/u16-to-u32.c @@ -1,5 +1,5 @@ /* Convert UTF-16 string to UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify @@ -32,11 +32,10 @@ DST_UNIT * FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) { const SRC_UNIT *s_end = s + n; + /* Output string accumulator. */ DST_UNIT *result; size_t allocated; - size_t length; - if (resultbuf != NULL) { result = resultbuf; @@ -47,18 +46,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) result = NULL; allocated = 0; } - length = 0; + size_t length = 0; /* Invariants: result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ while (s < s_end) { - ucs4_t uc; - int count; - /* Fetch a Unicode character from the input string. */ - count = u16_mbtoucr (&uc, s, s_end - s); + ucs4_t uc; + int count = u16_mbtoucr (&uc, s, s_end - s); if (count < 0) { if (!(result == resultbuf || result == NULL)) @@ -71,11 +68,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Store it in the output string. */ if (length + 1 > allocated) { - DST_UNIT *memory; - allocated = (allocated > 0 ? 2 * allocated : 12); if (length + 1 > allocated) allocated = length + 1; + + DST_UNIT *memory; if (result == resultbuf || result == NULL) memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); else @@ -113,9 +110,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) else if (result != resultbuf && length < allocated) { /* Shrink the allocated memory if possible. */ - DST_UNIT *memory; - - memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); + DST_UNIT *memory = + (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) result = memory; } diff --git a/lib/unistr/u16-to-u8.c b/lib/unistr/u16-to-u8.c index d9f092c4..1af65d65 100644 --- a/lib/unistr/u16-to-u8.c +++ b/lib/unistr/u16-to-u8.c @@ -1,5 +1,5 @@ /* Convert UTF-16 string to UTF-8 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -40,11 +40,10 @@ DST_UNIT * FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) { const SRC_UNIT *s_end = s + n; + /* Output string accumulator. */ DST_UNIT *result; size_t allocated; - size_t length; - if (resultbuf != NULL) { result = resultbuf; @@ -55,18 +54,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) result = NULL; allocated = 0; } - length = 0; + size_t length = 0; /* Invariants: result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ while (s < s_end) { - ucs4_t uc; - int count; - /* Fetch a Unicode character from the input string. */ - count = u16_mbtoucr (&uc, s, s_end - s); + ucs4_t uc; + int count = u16_mbtoucr (&uc, s, s_end - s); if (count < 0) { if (!(result == resultbuf || result == NULL)) @@ -87,11 +84,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) } if (count == -2) { - DST_UNIT *memory; - allocated = (allocated > 0 ? 2 * allocated : 12); if (length + 6 > allocated) allocated = length + 6; + + DST_UNIT *memory; if (result == resultbuf || result == NULL) memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); else @@ -132,9 +129,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) else if (result != resultbuf && length < allocated) { /* Shrink the allocated memory if possible. */ - DST_UNIT *memory; - - memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); + DST_UNIT *memory = + (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) result = memory; } diff --git a/lib/unistr/u16-uctomb-aux.c b/lib/unistr/u16-uctomb-aux.c index c6c04ecf..a0e384e4 100644 --- a/lib/unistr/u16-uctomb-aux.c +++ b/lib/unistr/u16-uctomb-aux.c @@ -1,5 +1,5 @@ /* Conversion UCS-4 to UTF-16. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u16-uctomb.c b/lib/unistr/u16-uctomb.c index 4ceea331..9e649447 100644 --- a/lib/unistr/u16-uctomb.c +++ b/lib/unistr/u16-uctomb.c @@ -1,5 +1,5 @@ /* Store a character in UTF-16 string. - Copyright (C) 2002, 2005-2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-check.c b/lib/unistr/u32-check.c index e6d95e98..abcc26d1 100644 --- a/lib/unistr/u32-check.c +++ b/lib/unistr/u32-check.c @@ -1,5 +1,5 @@ /* Check UTF-32 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-chr.c b/lib/unistr/u32-chr.c index 956c33af..09be3107 100644 --- a/lib/unistr/u32-chr.c +++ b/lib/unistr/u32-chr.c @@ -1,5 +1,5 @@ /* Search character in piece of UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u32-cmp.c b/lib/unistr/u32-cmp.c index e38c7e81..dddb4bc0 100644 --- a/lib/unistr/u32-cmp.c +++ b/lib/unistr/u32-cmp.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-32 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -31,18 +31,16 @@ int u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n) { - for (; n > 0;) + for (; n > 0; n--) { uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; - if (uc1 == uc2) + if (uc1 != uc2) { - n--; - continue; + /* Note that uc1 and uc2 each have at most 31 bits. */ + return (int)uc1 - (int)uc2; + /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */ } - /* Note that uc1 and uc2 each have at most 31 bits. */ - return (int)uc1 - (int)uc2; - /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */ } return 0; } diff --git a/lib/unistr/u32-cmp2.c b/lib/unistr/u32-cmp2.c index 4a31f8cf..605d8834 100644 --- a/lib/unistr/u32-cmp2.c +++ b/lib/unistr/u32-cmp2.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-32 strings. - Copyright (C) 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This file is free software. diff --git a/lib/unistr/u32-cpy-alloc.c b/lib/unistr/u32-cpy-alloc.c index 2b48d61f..37aa8c04 100644 --- a/lib/unistr/u32-cpy-alloc.c +++ b/lib/unistr/u32-cpy-alloc.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-cpy.c b/lib/unistr/u32-cpy.c index 27275497..fa030b66 100644 --- a/lib/unistr/u32-cpy.c +++ b/lib/unistr/u32-cpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u32-endswith.c b/lib/unistr/u32-endswith.c index 6f1cd5cb..a9b8d2a4 100644 --- a/lib/unistr/u32-endswith.c +++ b/lib/unistr/u32-endswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-32 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-mblen.c b/lib/unistr/u32-mblen.c index f3b4fa14..377ad60a 100644 --- a/lib/unistr/u32-mblen.c +++ b/lib/unistr/u32-mblen.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-mbsnlen.c b/lib/unistr/u32-mbsnlen.c index e949beb0..74cc07d8 100644 --- a/lib/unistr/u32-mbsnlen.c +++ b/lib/unistr/u32-mbsnlen.c @@ -1,5 +1,5 @@ /* Count characters in UTF-32 string. - Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2007. This file is free software. diff --git a/lib/unistr/u32-mbtouc-unsafe.c b/lib/unistr/u32-mbtouc-unsafe.c index 9e8bfb64..f4150885 100644 --- a/lib/unistr/u32-mbtouc-unsafe.c +++ b/lib/unistr/u32-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u32-mbtouc.c b/lib/unistr/u32-mbtouc.c index 2352917e..ddc60783 100644 --- a/lib/unistr/u32-mbtouc.c +++ b/lib/unistr/u32-mbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-mbtoucr.c b/lib/unistr/u32-mbtoucr.c index 29a38fca..83e34732 100644 --- a/lib/unistr/u32-mbtoucr.c +++ b/lib/unistr/u32-mbtoucr.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string, returning an error code. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-move.c b/lib/unistr/u32-move.c index c07e04de..a07d7cd2 100644 --- a/lib/unistr/u32-move.c +++ b/lib/unistr/u32-move.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-next.c b/lib/unistr/u32-next.c index 9ed2ef13..1bcf86f4 100644 --- a/lib/unistr/u32-next.c +++ b/lib/unistr/u32-next.c @@ -1,5 +1,5 @@ /* Iterate over next character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -34,9 +34,7 @@ const uint32_t * u32_next (ucs4_t *puc, const uint32_t *s) { - int count; - - count = u32_strmbtouc (puc, s); + int count = u32_strmbtouc (puc, s); if (count > 0) return s + count; else diff --git a/lib/unistr/u32-pcpy.c b/lib/unistr/u32-pcpy.c index 135151c7..f05d9355 100644 --- a/lib/unistr/u32-pcpy.c +++ b/lib/unistr/u32-pcpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-32 string, return pointer after last written unit. - Copyright (C) 2020-2025 Free Software Foundation, Inc. + Copyright (C) 2020-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2023. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u32-prev.c b/lib/unistr/u32-prev.c index 626be452..d8369a70 100644 --- a/lib/unistr/u32-prev.c +++ b/lib/unistr/u32-prev.c @@ -1,5 +1,5 @@ /* Iterate over previous character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-set.c b/lib/unistr/u32-set.c index 157ad5f5..5c1a9d5c 100644 --- a/lib/unistr/u32-set.c +++ b/lib/unistr/u32-set.c @@ -1,5 +1,5 @@ /* Fill UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-startswith.c b/lib/unistr/u32-startswith.c index 3c2b759d..a96a390d 100644 --- a/lib/unistr/u32-startswith.c +++ b/lib/unistr/u32-startswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-32 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-stpcpy.c b/lib/unistr/u32-stpcpy.c index dd5b5e3a..5d4937db 100644 --- a/lib/unistr/u32-stpcpy.c +++ b/lib/unistr/u32-stpcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-stpncpy.c b/lib/unistr/u32-stpncpy.c index 3cf683a5..6c657ae1 100644 --- a/lib/unistr/u32-stpncpy.c +++ b/lib/unistr/u32-stpncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strcat.c b/lib/unistr/u32-strcat.c index cb4d3b7b..5ef4a881 100644 --- a/lib/unistr/u32-strcat.c +++ b/lib/unistr/u32-strcat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-32 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u32-strchr.c b/lib/unistr/u32-strchr.c index 8b8abfd7..7e91b09b 100644 --- a/lib/unistr/u32-strchr.c +++ b/lib/unistr/u32-strchr.c @@ -1,5 +1,5 @@ /* Search character in UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strcmp.c b/lib/unistr/u32-strcmp.c index d0ec7d3c..346d46e9 100644 --- a/lib/unistr/u32-strcmp.c +++ b/lib/unistr/u32-strcmp.c @@ -1,5 +1,5 @@ /* Compare UTF-32 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -35,10 +35,11 @@ u32_strcmp (const uint32_t *s1, const uint32_t *s2) { uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; - if (uc1 != 0 && uc1 == uc2) - continue; - /* Note that uc1 and uc2 each have at most 31 bits. */ - return (int)uc1 - (int)uc2; - /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */ + if (uc1 == 0 || uc1 != uc2) + { + /* Note that uc1 and uc2 each have at most 31 bits. */ + return (int)uc1 - (int)uc2; + /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */ + } } } diff --git a/lib/unistr/u32-strcoll.c b/lib/unistr/u32-strcoll.c index a20ba943..47d5161f 100644 --- a/lib/unistr/u32-strcoll.c +++ b/lib/unistr/u32-strcoll.c @@ -1,5 +1,5 @@ /* Compare UTF-32 strings using the collation rules of the current locale. - Copyright (C) 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This file is free software. diff --git a/lib/unistr/u32-strcpy.c b/lib/unistr/u32-strcpy.c index f64a31f2..8a3b937b 100644 --- a/lib/unistr/u32-strcpy.c +++ b/lib/unistr/u32-strcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strcspn.c b/lib/unistr/u32-strcspn.c index e03289ce..a7add17d 100644 --- a/lib/unistr/u32-strcspn.c +++ b/lib/unistr/u32-strcspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strdup.c b/lib/unistr/u32-strdup.c index 633ce0e9..4c5ca4f8 100644 --- a/lib/unistr/u32-strdup.c +++ b/lib/unistr/u32-strdup.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strlen.c b/lib/unistr/u32-strlen.c index 5aa8236e..496eb57b 100644 --- a/lib/unistr/u32-strlen.c +++ b/lib/unistr/u32-strlen.c @@ -1,5 +1,5 @@ /* Determine length of UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u32-strmblen.c b/lib/unistr/u32-strmblen.c index 351ae6c5..1e71279a 100644 --- a/lib/unistr/u32-strmblen.c +++ b/lib/unistr/u32-strmblen.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strmbtouc.c b/lib/unistr/u32-strmbtouc.c index 3bdac61f..b02362a5 100644 --- a/lib/unistr/u32-strmbtouc.c +++ b/lib/unistr/u32-strmbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strncat.c b/lib/unistr/u32-strncat.c index a753526a..c611aa0b 100644 --- a/lib/unistr/u32-strncat.c +++ b/lib/unistr/u32-strncat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-32 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strncmp.c b/lib/unistr/u32-strncmp.c index 98461ad7..b6d2c038 100644 --- a/lib/unistr/u32-strncmp.c +++ b/lib/unistr/u32-strncmp.c @@ -1,5 +1,5 @@ /* Compare UTF-32 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -31,18 +31,16 @@ int u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n) { - for (; n > 0;) + for (; n > 0; n--) { uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; - if (uc1 != 0 && uc1 == uc2) + if (uc1 == 0 || uc1 != uc2) { - n--; - continue; + /* Note that uc1 and uc2 each have at most 31 bits. */ + return (int)uc1 - (int)uc2; + /* > 0 if uc1 > uc2, < 0 if uc1 < uc2, = 0 if uc1 and uc2 are both 0. */ } - /* Note that uc1 and uc2 each have at most 31 bits. */ - return (int)uc1 - (int)uc2; - /* > 0 if uc1 > uc2, < 0 if uc1 < uc2, = 0 if uc1 and uc2 are both 0. */ } return 0; } diff --git a/lib/unistr/u32-strncpy.c b/lib/unistr/u32-strncpy.c index c3a932f1..8186c581 100644 --- a/lib/unistr/u32-strncpy.c +++ b/lib/unistr/u32-strncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strnlen.c b/lib/unistr/u32-strnlen.c index 246c2fbe..3a32c4d8 100644 --- a/lib/unistr/u32-strnlen.c +++ b/lib/unistr/u32-strnlen.c @@ -1,5 +1,5 @@ /* Determine bounded length of UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strpbrk.c b/lib/unistr/u32-strpbrk.c index f057dea0..aa46e1aa 100644 --- a/lib/unistr/u32-strpbrk.c +++ b/lib/unistr/u32-strpbrk.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strrchr.c b/lib/unistr/u32-strrchr.c index 10d5958c..fa7ee149 100644 --- a/lib/unistr/u32-strrchr.c +++ b/lib/unistr/u32-strrchr.c @@ -1,5 +1,5 @@ /* Search character in UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strspn.c b/lib/unistr/u32-strspn.c index 4c88dbfc..7bea5aff 100644 --- a/lib/unistr/u32-strspn.c +++ b/lib/unistr/u32-strspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strstr.c b/lib/unistr/u32-strstr.c index 08b97453..be981e02 100644 --- a/lib/unistr/u32-strstr.c +++ b/lib/unistr/u32-strstr.c @@ -1,5 +1,5 @@ /* Substring test for UTF-32 strings. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-strtok.c b/lib/unistr/u32-strtok.c index 2640f901..e7a23447 100644 --- a/lib/unistr/u32-strtok.c +++ b/lib/unistr/u32-strtok.c @@ -1,5 +1,5 @@ /* Tokenize UTF-32 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u32-to-u16.c b/lib/unistr/u32-to-u16.c index 94530e2b..4ea9125a 100644 --- a/lib/unistr/u32-to-u16.c +++ b/lib/unistr/u32-to-u16.c @@ -1,5 +1,5 @@ /* Convert UTF-32 string to UTF-16 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -40,11 +40,10 @@ DST_UNIT * FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) { const SRC_UNIT *s_end = s + n; + /* Output string accumulator. */ DST_UNIT *result; size_t allocated; - size_t length; - if (resultbuf != NULL) { result = resultbuf; @@ -55,23 +54,20 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) result = NULL; allocated = 0; } - length = 0; + size_t length = 0; /* Invariants: result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ while (s < s_end) { - ucs4_t uc; - int count; - /* Fetch a Unicode character from the input string. */ - uc = *s++; + ucs4_t uc = *s++; /* No need to call the safe variant u32_mbtouc, because u16_uctomb will verify uc anyway. */ /* Store it in the output string. */ - count = u16_uctomb (result + length, uc, allocated - length); + int count = u16_uctomb (result + length, uc, allocated - length); if (count == -1) { if (!(result == resultbuf || result == NULL)) @@ -81,11 +77,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) } if (count == -2) { - DST_UNIT *memory; - allocated = (allocated > 0 ? 2 * allocated : 12); if (length + 2 > allocated) allocated = length + 2; + + DST_UNIT *memory; if (result == resultbuf || result == NULL) memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); else @@ -126,9 +122,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) else if (result != resultbuf && length < allocated) { /* Shrink the allocated memory if possible. */ - DST_UNIT *memory; - - memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); + DST_UNIT *memory = + (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) result = memory; } diff --git a/lib/unistr/u32-to-u8.c b/lib/unistr/u32-to-u8.c index 0c4f0bc3..6460130b 100644 --- a/lib/unistr/u32-to-u8.c +++ b/lib/unistr/u32-to-u8.c @@ -1,5 +1,5 @@ /* Convert UTF-32 string to UTF-8 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify @@ -32,11 +32,10 @@ DST_UNIT * FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) { const SRC_UNIT *s_end = s + n; + /* Output string accumulator. */ DST_UNIT *result; size_t allocated; - size_t length; - if (resultbuf != NULL) { result = resultbuf; @@ -47,23 +46,20 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) result = NULL; allocated = 0; } - length = 0; + size_t length = 0; /* Invariants: result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ while (s < s_end) { - ucs4_t uc; - int count; - /* Fetch a Unicode character from the input string. */ - uc = *s++; + ucs4_t uc = *s++; /* No need to call the safe variant u32_mbtouc, because u8_uctomb will verify uc anyway. */ /* Store it in the output string. */ - count = u8_uctomb (result + length, uc, allocated - length); + int count = u8_uctomb (result + length, uc, allocated - length); if (count == -1) { if (!(result == resultbuf || result == NULL)) @@ -73,11 +69,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) } if (count == -2) { - DST_UNIT *memory; - allocated = (allocated > 0 ? 2 * allocated : 12); if (length + 6 > allocated) allocated = length + 6; + + DST_UNIT *memory; if (result == resultbuf || result == NULL) memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); else @@ -118,9 +114,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) else if (result != resultbuf && length < allocated) { /* Shrink the allocated memory if possible. */ - DST_UNIT *memory; - - memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); + DST_UNIT *memory = + (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) result = memory; } diff --git a/lib/unistr/u32-uctomb.c b/lib/unistr/u32-uctomb.c index f68e4c0a..a2d9fa76 100644 --- a/lib/unistr/u32-uctomb.c +++ b/lib/unistr/u32-uctomb.c @@ -1,5 +1,5 @@ /* Store a character in UTF-32 string. - Copyright (C) 2002, 2005-2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-check.c b/lib/unistr/u8-check.c index e7c56f1e..f7fcc620 100644 --- a/lib/unistr/u8-check.c +++ b/lib/unistr/u8-check.c @@ -1,5 +1,5 @@ /* Check UTF-8 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-chr.c b/lib/unistr/u8-chr.c index c34e1fe3..5f98cb7f 100644 --- a/lib/unistr/u8-chr.c +++ b/lib/unistr/u8-chr.c @@ -1,5 +1,5 @@ /* Search character in piece of UTF-8 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. @@ -46,8 +46,7 @@ u8_chr (const uint8_t *s, size_t n, ucs4_t uc) { uint8_t c[6]; - size_t uc_size; - uc_size = u8_uctomb_aux (c, uc, 6); + size_t uc_size = u8_uctomb_aux (c, uc, 6); if (n < uc_size) return NULL; diff --git a/lib/unistr/u8-cmp.c b/lib/unistr/u8-cmp.c index b3926547..d00b9201 100644 --- a/lib/unistr/u8-cmp.c +++ b/lib/unistr/u8-cmp.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-8 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-cmp2.c b/lib/unistr/u8-cmp2.c index f9bc3f90..54c9a76b 100644 --- a/lib/unistr/u8-cmp2.c +++ b/lib/unistr/u8-cmp2.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-8 strings. - Copyright (C) 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This file is free software. diff --git a/lib/unistr/u8-cpy-alloc.c b/lib/unistr/u8-cpy-alloc.c index 247b07c5..f3caf516 100644 --- a/lib/unistr/u8-cpy-alloc.c +++ b/lib/unistr/u8-cpy-alloc.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-cpy.c b/lib/unistr/u8-cpy.c index 7f19bf78..d5ea0412 100644 --- a/lib/unistr/u8-cpy.c +++ b/lib/unistr/u8-cpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-endswith.c b/lib/unistr/u8-endswith.c index 8135e88e..c684262a 100644 --- a/lib/unistr/u8-endswith.c +++ b/lib/unistr/u8-endswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-8 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-mblen.c b/lib/unistr/u8-mblen.c index e2e4ba39..2d8663dd 100644 --- a/lib/unistr/u8-mblen.c +++ b/lib/unistr/u8-mblen.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2025 Free Software + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u8-mbsnlen.c b/lib/unistr/u8-mbsnlen.c index d7043779..7cb168dd 100644 --- a/lib/unistr/u8-mbsnlen.c +++ b/lib/unistr/u8-mbsnlen.c @@ -1,5 +1,5 @@ /* Count characters in UTF-8 string. - Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2007. This file is free software. @@ -31,9 +31,7 @@ size_t u8_mbsnlen (const uint8_t *s, size_t n) { - size_t characters; - - characters = 0; + size_t characters = 0; while (n > 0) { ucs4_t uc; diff --git a/lib/unistr/u8-mbtouc-aux.c b/lib/unistr/u8-mbtouc-aux.c index 9f80d7e2..23554b73 100644 --- a/lib/unistr/u8-mbtouc-aux.c +++ b/lib/unistr/u8-mbtouc-aux.c @@ -1,5 +1,5 @@ /* Conversion UTF-8 to UCS-4. - Copyright (C) 2001-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-mbtouc-unsafe-aux.c b/lib/unistr/u8-mbtouc-unsafe-aux.c index 1683b8ad..eef38aa8 100644 --- a/lib/unistr/u8-mbtouc-unsafe-aux.c +++ b/lib/unistr/u8-mbtouc-unsafe-aux.c @@ -1,5 +1,5 @@ /* Conversion UTF-8 to UCS-4. - Copyright (C) 2001-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-mbtouc-unsafe.c b/lib/unistr/u8-mbtouc-unsafe.c index cf93e56f..718fb20d 100644 --- a/lib/unistr/u8-mbtouc-unsafe.c +++ b/lib/unistr/u8-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-mbtouc.c b/lib/unistr/u8-mbtouc.c index 6bcf085a..711e61d6 100644 --- a/lib/unistr/u8-mbtouc.c +++ b/lib/unistr/u8-mbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-mbtoucr.c b/lib/unistr/u8-mbtoucr.c index 63415ab0..fa845675 100644 --- a/lib/unistr/u8-mbtoucr.c +++ b/lib/unistr/u8-mbtoucr.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string, returning an error code. - Copyright (C) 1999-2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-move.c b/lib/unistr/u8-move.c index a31e36b1..00da3700 100644 --- a/lib/unistr/u8-move.c +++ b/lib/unistr/u8-move.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-next.c b/lib/unistr/u8-next.c index 3701701a..0d4d324a 100644 --- a/lib/unistr/u8-next.c +++ b/lib/unistr/u8-next.c @@ -1,5 +1,5 @@ /* Iterate over next character in UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -34,9 +34,7 @@ const uint8_t * u8_next (ucs4_t *puc, const uint8_t *s) { - int count; - - count = u8_strmbtouc (puc, s); + int count = u8_strmbtouc (puc, s); if (count > 0) return s + count; else diff --git a/lib/unistr/u8-pcpy.c b/lib/unistr/u8-pcpy.c index e1462691..9e7990b3 100644 --- a/lib/unistr/u8-pcpy.c +++ b/lib/unistr/u8-pcpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-8 string, return pointer after last written unit. - Copyright (C) 2020-2025 Free Software Foundation, Inc. + Copyright (C) 2020-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2023. This file is free software. diff --git a/lib/unistr/u8-prev.c b/lib/unistr/u8-prev.c index e9d0eec5..52ad4c7c 100644 --- a/lib/unistr/u8-prev.c +++ b/lib/unistr/u8-prev.c @@ -1,5 +1,5 @@ /* Iterate over previous character in UTF-8 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-set.c b/lib/unistr/u8-set.c index f9a9b9f1..0d196579 100644 --- a/lib/unistr/u8-set.c +++ b/lib/unistr/u8-set.c @@ -1,5 +1,5 @@ /* Fill UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-startswith.c b/lib/unistr/u8-startswith.c index 741480d0..391b3308 100644 --- a/lib/unistr/u8-startswith.c +++ b/lib/unistr/u8-startswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-8 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-stpcpy.c b/lib/unistr/u8-stpcpy.c index 5e2a1d1b..06fe0998 100644 --- a/lib/unistr/u8-stpcpy.c +++ b/lib/unistr/u8-stpcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-stpncpy.c b/lib/unistr/u8-stpncpy.c index a81be2a8..ba17f208 100644 --- a/lib/unistr/u8-stpncpy.c +++ b/lib/unistr/u8-stpncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strcat.c b/lib/unistr/u8-strcat.c index a9ecca97..bc6cda6f 100644 --- a/lib/unistr/u8-strcat.c +++ b/lib/unistr/u8-strcat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-8 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strchr.c b/lib/unistr/u8-strchr.c index 3ccf0516..30468be1 100644 --- a/lib/unistr/u8-strchr.c +++ b/lib/unistr/u8-strchr.c @@ -1,5 +1,5 @@ /* Search character in UTF-8 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. @@ -37,8 +37,6 @@ uint8_t * u8_strchr (const uint8_t *s, ucs4_t uc) { - uint8_t c[6]; - if (uc < 0x80) { uint8_t c0 = uc; @@ -65,187 +63,191 @@ u8_strchr (const uint8_t *s, ucs4_t uc) } } else + { /* Loops equivalent to strstr, optimized for a specific length (2, 3, 4) of the needle. We use an algorithm similar to Boyer-Moore which is documented in lib/unistr/u8-chr.c. There is additional complication because we need to check after every byte for a NUL byte, but the idea is the same. */ - switch (u8_uctomb_aux (c, uc, 6)) - { - case 2: - if (*s == 0 || s[1] == 0) - break; - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - /* Search for { c0, c1 }. */ - uint8_t s1 = s[1]; - - for (;;) - { - /* Here s[0] != 0, s[1] != 0. - Test whether s[0..1] == { c0, c1 }. */ - if (s1 == c1) - { - if (*s == c0) - return (uint8_t *) s; - else - /* Skip the search at s + 1, because s[1] = c1 < c0. */ - goto case2_skip2; - } - else - { - if (s1 == c0) - goto case2_skip1; - else - /* Skip the search at s + 1, because s[1] != c0. */ - goto case2_skip2; - } - case2_skip2: - s++; - s1 = s[1]; - if (s[1] == 0) - break; - case2_skip1: - s++; - s1 = s[1]; - if (s[1] == 0) - break; - } - } - break; + uint8_t c[6]; - case 3: - if (*s == 0 || s[1] == 0 || s[2] == 0) - break; + switch (u8_uctomb_aux (c, uc, 6)) { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - /* Search for { c0, c1, c2 }. */ - uint8_t s2 = s[2]; + case 2: + if (*s == 0 || s[1] == 0) + break; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + /* Search for { c0, c1 }. */ + uint8_t s1 = s[1]; + + for (;;) + { + /* Here s[0] != 0, s[1] != 0. + Test whether s[0..1] == { c0, c1 }. */ + if (s1 == c1) + { + if (*s == c0) + return (uint8_t *) s; + else + /* Skip the search at s + 1, because s[1] = c1 < c0. */ + goto case2_skip2; + } + else + { + if (s1 == c0) + goto case2_skip1; + else + /* Skip the search at s + 1, because s[1] != c0. */ + goto case2_skip2; + } + case2_skip2: + s++; + s1 = s[1]; + if (s[1] == 0) + break; + case2_skip1: + s++; + s1 = s[1]; + if (s[1] == 0) + break; + } + } + break; - for (;;) - { - /* Here s[0] != 0, s[1] != 0, s[2] != 0. - Test whether s[0..2] == { c0, c1, c2 }. */ - if (s2 == c2) - { - if (s[1] == c1 && *s == c0) - return (uint8_t *) s; - else - /* If c2 != c1: - Skip the search at s + 1, because s[2] == c2 != c1. - Skip the search at s + 2, because s[2] == c2 < c0. */ - if (c2 == c1) + case 3: + if (*s == 0 || s[1] == 0 || s[2] == 0) + break; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + /* Search for { c0, c1, c2 }. */ + uint8_t s2 = s[2]; + + for (;;) + { + /* Here s[0] != 0, s[1] != 0, s[2] != 0. + Test whether s[0..2] == { c0, c1, c2 }. */ + if (s2 == c2) + { + if (s[1] == c1 && *s == c0) + return (uint8_t *) s; + else + /* If c2 != c1: + Skip the search at s + 1, because s[2] == c2 != c1. + Skip the search at s + 2, because s[2] == c2 < c0. */ + if (c2 == c1) + goto case3_skip1; + else + goto case3_skip3; + } + else + { + if (s2 == c1) goto case3_skip1; + else if (s2 == c0) + /* Skip the search at s + 1, because s[2] != c1. */ + goto case3_skip2; else + /* Skip the search at s + 1, because s[2] != c1. + Skip the search at s + 2, because s[2] != c0. */ goto case3_skip3; - } - else - { - if (s2 == c1) - goto case3_skip1; - else if (s2 == c0) - /* Skip the search at s + 1, because s[2] != c1. */ - goto case3_skip2; - else - /* Skip the search at s + 1, because s[2] != c1. - Skip the search at s + 2, because s[2] != c0. */ - goto case3_skip3; - } - case3_skip3: - s++; - s2 = s[2]; - if (s[2] == 0) - break; - case3_skip2: - s++; - s2 = s[2]; - if (s[2] == 0) - break; - case3_skip1: - s++; - s2 = s[2]; - if (s[2] == 0) - break; - } - } - break; - - case 4: - if (*s == 0 || s[1] == 0 || s[2] == 0 || s[3] == 0) + } + case3_skip3: + s++; + s2 = s[2]; + if (s[2] == 0) + break; + case3_skip2: + s++; + s2 = s[2]; + if (s[2] == 0) + break; + case3_skip1: + s++; + s2 = s[2]; + if (s[2] == 0) + break; + } + } break; - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - uint8_t c3 = c[3]; - /* Search for { c0, c1, c2, c3 }. */ - uint8_t s3 = s[3]; - for (;;) - { - /* Here s[0] != 0, s[1] != 0, s[2] != 0, s[3] != 0. - Test whether s[0..3] == { c0, c1, c2, c3 }. */ - if (s3 == c3) - { - if (s[2] == c2 && s[1] == c1 && *s == c0) - return (uint8_t *) s; - else - /* If c3 != c2: - Skip the search at s + 1, because s[3] == c3 != c2. - If c3 != c1: - Skip the search at s + 2, because s[3] == c3 != c1. - Skip the search at s + 3, because s[3] == c3 < c0. */ - if (c3 == c2) + case 4: + if (*s == 0 || s[1] == 0 || s[2] == 0 || s[3] == 0) + break; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + uint8_t c3 = c[3]; + /* Search for { c0, c1, c2, c3 }. */ + uint8_t s3 = s[3]; + + for (;;) + { + /* Here s[0] != 0, s[1] != 0, s[2] != 0, s[3] != 0. + Test whether s[0..3] == { c0, c1, c2, c3 }. */ + if (s3 == c3) + { + if (s[2] == c2 && s[1] == c1 && *s == c0) + return (uint8_t *) s; + else + /* If c3 != c2: + Skip the search at s + 1, because s[3] == c3 != c2. + If c3 != c1: + Skip the search at s + 2, because s[3] == c3 != c1. + Skip the search at s + 3, because s[3] == c3 < c0. */ + if (c3 == c2) + goto case4_skip1; + else if (c3 == c1) + goto case4_skip2; + else + goto case4_skip4; + } + else + { + if (s3 == c2) goto case4_skip1; - else if (c3 == c1) + else if (s3 == c1) + /* Skip the search at s + 1, because s[3] != c2. */ goto case4_skip2; + else if (s3 == c0) + /* Skip the search at s + 1, because s[3] != c2. + Skip the search at s + 2, because s[3] != c1. */ + goto case4_skip3; else + /* Skip the search at s + 1, because s[3] != c2. + Skip the search at s + 2, because s[3] != c1. + Skip the search at s + 3, because s[3] != c0. */ goto case4_skip4; - } - else - { - if (s3 == c2) - goto case4_skip1; - else if (s3 == c1) - /* Skip the search at s + 1, because s[3] != c2. */ - goto case4_skip2; - else if (s3 == c0) - /* Skip the search at s + 1, because s[3] != c2. - Skip the search at s + 2, because s[3] != c1. */ - goto case4_skip3; - else - /* Skip the search at s + 1, because s[3] != c2. - Skip the search at s + 2, because s[3] != c1. - Skip the search at s + 3, because s[3] != c0. */ - goto case4_skip4; - } - case4_skip4: - s++; - s3 = s[3]; - if (s[3] == 0) - break; - case4_skip3: - s++; - s3 = s[3]; - if (s[3] == 0) - break; - case4_skip2: - s++; - s3 = s[3]; - if (s[3] == 0) - break; - case4_skip1: - s++; - s3 = s[3]; - if (s[3] == 0) - break; - } + } + case4_skip4: + s++; + s3 = s[3]; + if (s[3] == 0) + break; + case4_skip3: + s++; + s3 = s[3]; + if (s[3] == 0) + break; + case4_skip2: + s++; + s3 = s[3]; + if (s[3] == 0) + break; + case4_skip1: + s++; + s3 = s[3]; + if (s[3] == 0) + break; + } + } + break; } - break; - } + } return NULL; } diff --git a/lib/unistr/u8-strcmp.c b/lib/unistr/u8-strcmp.c index f2ce1cd4..1deb3879 100644 --- a/lib/unistr/u8-strcmp.c +++ b/lib/unistr/u8-strcmp.c @@ -1,5 +1,5 @@ /* Compare UTF-8 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strcoll.c b/lib/unistr/u8-strcoll.c index 550fd8a2..f0f5862f 100644 --- a/lib/unistr/u8-strcoll.c +++ b/lib/unistr/u8-strcoll.c @@ -1,5 +1,5 @@ /* Compare UTF-8 strings using the collation rules of the current locale. - Copyright (C) 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This file is free software. diff --git a/lib/unistr/u8-strcpy.c b/lib/unistr/u8-strcpy.c index 080ae83b..0354d6b2 100644 --- a/lib/unistr/u8-strcpy.c +++ b/lib/unistr/u8-strcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strcspn.c b/lib/unistr/u8-strcspn.c index 196f9087..ee10b336 100644 --- a/lib/unistr/u8-strcspn.c +++ b/lib/unistr/u8-strcspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strdup.c b/lib/unistr/u8-strdup.c index e62bada6..da4f6dbb 100644 --- a/lib/unistr/u8-strdup.c +++ b/lib/unistr/u8-strdup.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strlen.c b/lib/unistr/u8-strlen.c index 4bf35379..5ac6b940 100644 --- a/lib/unistr/u8-strlen.c +++ b/lib/unistr/u8-strlen.c @@ -1,5 +1,5 @@ /* Determine length of UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-strmblen.c b/lib/unistr/u8-strmblen.c index 253afb43..603b4277 100644 --- a/lib/unistr/u8-strmblen.c +++ b/lib/unistr/u8-strmblen.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2025 Free Software + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u8-strmbtouc.c b/lib/unistr/u8-strmbtouc.c index 48c4d6c1..b3bbf060 100644 --- a/lib/unistr/u8-strmbtouc.c +++ b/lib/unistr/u8-strmbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2025 Free Software + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. diff --git a/lib/unistr/u8-strncat.c b/lib/unistr/u8-strncat.c index 3bbcc0d7..7bf11e6e 100644 --- a/lib/unistr/u8-strncat.c +++ b/lib/unistr/u8-strncat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-8 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strncmp.c b/lib/unistr/u8-strncmp.c index 97162e08..27c03bdf 100644 --- a/lib/unistr/u8-strncmp.c +++ b/lib/unistr/u8-strncmp.c @@ -1,5 +1,5 @@ /* Compare UTF-8 strings. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strncpy.c b/lib/unistr/u8-strncpy.c index cc37f225..91fd0a74 100644 --- a/lib/unistr/u8-strncpy.c +++ b/lib/unistr/u8-strncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strnlen.c b/lib/unistr/u8-strnlen.c index c62bac3a..a161add2 100644 --- a/lib/unistr/u8-strnlen.c +++ b/lib/unistr/u8-strnlen.c @@ -1,5 +1,5 @@ /* Determine bounded length of UTF-8 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strpbrk.c b/lib/unistr/u8-strpbrk.c index 3adc03f9..6e19129f 100644 --- a/lib/unistr/u8-strpbrk.c +++ b/lib/unistr/u8-strpbrk.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strrchr.c b/lib/unistr/u8-strrchr.c index 4f364fa6..c4fcee99 100644 --- a/lib/unistr/u8-strrchr.c +++ b/lib/unistr/u8-strrchr.c @@ -1,5 +1,5 @@ /* Search character in UTF-8 string. - Copyright (C) 1999, 2002, 2006-2007, 2009-2025 Free Software Foundation, + Copyright (C) 1999, 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. @@ -38,7 +38,6 @@ u8_strrchr (const uint8_t *s, ucs4_t uc) /* Calling u8_strlen and then searching from the other end would cause more memory accesses. Avoid that, at the cost of a few more comparisons. */ uint8_t *result = NULL; - uint8_t c[6]; if (uc < 0x80) { @@ -53,61 +52,65 @@ u8_strrchr (const uint8_t *s, ucs4_t uc) } } else - switch (u8_uctomb_aux (c, uc, 6)) - { - case 2: - if (*s) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; + { + uint8_t c[6]; + + switch (u8_uctomb_aux (c, uc, 6)) + { + case 2: + if (*s) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[1] == 0) - break; - if (*s == c0 && s[1] == c1) - result = (uint8_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[1] == 0) + break; + if (*s == c0 && s[1] == c1) + result = (uint8_t *) s; + } + } + break; - case 3: - if (*s && s[1]) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; + case 3: + if (*s && s[1]) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[2] == 0) - break; - if (*s == c0 && s[1] == c1 && s[2] == c2) - result = (uint8_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[2] == 0) + break; + if (*s == c0 && s[1] == c1 && s[2] == c2) + result = (uint8_t *) s; + } + } + break; - case 4: - if (*s && s[1] && s[2]) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - uint8_t c3 = c[3]; + case 4: + if (*s && s[1] && s[2]) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + uint8_t c3 = c[3]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[3] == 0) - break; - if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) - result = (uint8_t *) s; - } - } - break; - } + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[3] == 0) + break; + if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) + result = (uint8_t *) s; + } + } + break; + } + } return result; } diff --git a/lib/unistr/u8-strspn.c b/lib/unistr/u8-strspn.c index 918983cc..c9e5cef3 100644 --- a/lib/unistr/u8-strspn.c +++ b/lib/unistr/u8-strspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strstr.c b/lib/unistr/u8-strstr.c index eb30108e..23c64608 100644 --- a/lib/unistr/u8-strstr.c +++ b/lib/unistr/u8-strstr.c @@ -1,5 +1,5 @@ /* Substring test for UTF-8 strings. - Copyright (C) 1999, 2002, 2006, 2010-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2010-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-strtok.c b/lib/unistr/u8-strtok.c index bfd7032f..8428b751 100644 --- a/lib/unistr/u8-strtok.c +++ b/lib/unistr/u8-strtok.c @@ -1,5 +1,5 @@ /* Tokenize UTF-8 string. - Copyright (C) 1999, 2002, 2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. diff --git a/lib/unistr/u8-to-u16.c b/lib/unistr/u8-to-u16.c index 64bd7a69..301a0916 100644 --- a/lib/unistr/u8-to-u16.c +++ b/lib/unistr/u8-to-u16.c @@ -1,5 +1,5 @@ /* Convert UTF-8 string to UTF-16 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software. @@ -40,11 +40,10 @@ DST_UNIT * FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) { const SRC_UNIT *s_end = s + n; + /* Output string accumulator. */ DST_UNIT *result; size_t allocated; - size_t length; - if (resultbuf != NULL) { result = resultbuf; @@ -55,18 +54,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) result = NULL; allocated = 0; } - length = 0; + size_t length = 0; /* Invariants: result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ while (s < s_end) { - ucs4_t uc; - int count; - /* Fetch a Unicode character from the input string. */ - count = u8_mbtoucr (&uc, s, s_end - s); + ucs4_t uc; + int count = u8_mbtoucr (&uc, s, s_end - s); if (count < 0) { if (!(result == resultbuf || result == NULL)) @@ -87,11 +84,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) } if (count == -2) { - DST_UNIT *memory; - allocated = (allocated > 0 ? 2 * allocated : 12); if (length + 2 > allocated) allocated = length + 2; + + DST_UNIT *memory; if (result == resultbuf || result == NULL) memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); else @@ -132,9 +129,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) else if (result != resultbuf && length < allocated) { /* Shrink the allocated memory if possible. */ - DST_UNIT *memory; - - memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); + DST_UNIT *memory = + (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) result = memory; } diff --git a/lib/unistr/u8-to-u32.c b/lib/unistr/u8-to-u32.c index 1f029ead..10e6a278 100644 --- a/lib/unistr/u8-to-u32.c +++ b/lib/unistr/u8-to-u32.c @@ -1,5 +1,5 @@ /* Convert UTF-8 string to UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify @@ -32,11 +32,10 @@ DST_UNIT * FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) { const SRC_UNIT *s_end = s + n; + /* Output string accumulator. */ DST_UNIT *result; size_t allocated; - size_t length; - if (resultbuf != NULL) { result = resultbuf; @@ -47,18 +46,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) result = NULL; allocated = 0; } - length = 0; + size_t length = 0; /* Invariants: result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ while (s < s_end) { - ucs4_t uc; - int count; - /* Fetch a Unicode character from the input string. */ - count = u8_mbtoucr (&uc, s, s_end - s); + ucs4_t uc; + int count = u8_mbtoucr (&uc, s, s_end - s); if (count < 0) { if (!(result == resultbuf || result == NULL)) @@ -71,11 +68,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Store it in the output string. */ if (length + 1 > allocated) { - DST_UNIT *memory; - allocated = (allocated > 0 ? 2 * allocated : 12); if (length + 1 > allocated) allocated = length + 1; + + DST_UNIT *memory; if (result == resultbuf || result == NULL) memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); else @@ -113,9 +110,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) else if (result != resultbuf && length < allocated) { /* Shrink the allocated memory if possible. */ - DST_UNIT *memory; - - memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); + DST_UNIT *memory = + (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) result = memory; } diff --git a/lib/unistr/u8-uctomb-aux.c b/lib/unistr/u8-uctomb-aux.c index d0b5b7bb..59d78d3f 100644 --- a/lib/unistr/u8-uctomb-aux.c +++ b/lib/unistr/u8-uctomb-aux.c @@ -1,5 +1,5 @@ /* Conversion UCS-4 to UTF-8. - Copyright (C) 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify diff --git a/lib/unistr/u8-uctomb.c b/lib/unistr/u8-uctomb.c index 89ca2c07..eafec47e 100644 --- a/lib/unistr/u8-uctomb.c +++ b/lib/unistr/u8-uctomb.c @@ -1,5 +1,5 @@ /* Store a character in UTF-8 string. - Copyright (C) 2002, 2005-2006, 2009-2025 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2026 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This file is free software: you can redistribute it and/or modify |
