summaryrefslogtreecommitdiff
path: root/lib/unicase/u-casemap.h
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2026-03-08 17:28:33 +0100
committerJörg Frings-Fürst <debian@jff.email>2026-03-08 17:28:33 +0100
commit5f59a34ab747dde8ede7357f3431bf06bd6002fe (patch)
tree056a4477fd870d454d5be5868cddab829a47f4d2 /lib/unicase/u-casemap.h
parent27dae84ed92f1ef0300263091972338d12e78348 (diff)
New upstream version 1.4.2upstream/1.4.2upstream
Diffstat (limited to 'lib/unicase/u-casemap.h')
-rw-r--r--lib/unicase/u-casemap.h150
1 files changed, 70 insertions, 80 deletions
diff --git a/lib/unicase/u-casemap.h b/lib/unicase/u-casemap.h
index fba36655..abb67820 100644
--- a/lib/unicase/u-casemap.h
+++ b/lib/unicase/u-casemap.h
@@ -1,5 +1,5 @@
/* Case mapping for UTF-8/UTF-16/UTF-32 strings (locale dependent).
- 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.
@@ -35,10 +35,7 @@ FUNC (const UNIT *s, size_t n,
{
/* The result being accumulated. */
UNIT *result;
- size_t length;
size_t allocated;
-
- /* Initialize the accumulator. */
if (nf != NULL || resultbuf == NULL)
{
result = NULL;
@@ -49,7 +46,7 @@ FUNC (const UNIT *s, size_t n,
result = resultbuf;
allocated = *lengthp;
}
- length = 0;
+ size_t length = 0;
{
const UNIT *s_end = s + n;
@@ -97,10 +94,10 @@ FUNC (const UNIT *s, size_t n,
{
/* Does the context apply? */
int context = rule->context;
- bool applies;
-
if (context < 0)
context = - context;
+
+ bool applies;
switch (context)
{
case SCC_ALWAYS:
@@ -281,15 +278,65 @@ FUNC (const UNIT *s, size_t n,
found_mapping:
/* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */
- {
- unsigned int i;
+ for (unsigned int i = 0; i < mapped_count; i++)
+ {
+ ucs4_t muc = mapped_uc[i];
- for (i = 0; i < mapped_count; i++)
+ /* Append muc to the result accumulator. */
+ if (length < allocated)
+ {
+ int ret = U_UCTOMB (result + length, muc, allocated - length);
+ if (ret == -1)
+ {
+ errno = EINVAL;
+ goto fail;
+ }
+ if (ret >= 0)
+ {
+ length += ret;
+ goto done_appending;
+ }
+ }
{
- ucs4_t muc = mapped_uc[i];
-
- /* Append muc to the result accumulator. */
- if (length < allocated)
+ size_t old_allocated = allocated;
+ size_t new_allocated = 2 * old_allocated;
+ if (new_allocated < 64)
+ new_allocated = 64;
+ if (new_allocated < old_allocated) /* integer overflow? */
+ abort ();
+ {
+ UNIT *larger_result;
+ if (result == NULL)
+ {
+ larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
+ if (larger_result == NULL)
+ {
+ errno = ENOMEM;
+ goto fail;
+ }
+ }
+ else if (result == resultbuf)
+ {
+ larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
+ if (larger_result == NULL)
+ {
+ errno = ENOMEM;
+ goto fail;
+ }
+ U_CPY (larger_result, resultbuf, length);
+ }
+ else
+ {
+ larger_result =
+ (UNIT *) realloc (result, new_allocated * sizeof (UNIT));
+ if (larger_result == NULL)
+ {
+ errno = ENOMEM;
+ goto fail;
+ }
+ }
+ result = larger_result;
+ allocated = new_allocated;
{
int ret = U_UCTOMB (result + length, muc, allocated - length);
if (ret == -1)
@@ -297,69 +344,15 @@ FUNC (const UNIT *s, size_t n,
errno = EINVAL;
goto fail;
}
- if (ret >= 0)
- {
- length += ret;
- goto done_appending;
- }
- }
- {
- size_t old_allocated = allocated;
- size_t new_allocated = 2 * old_allocated;
- if (new_allocated < 64)
- new_allocated = 64;
- if (new_allocated < old_allocated) /* integer overflow? */
- abort ();
- {
- UNIT *larger_result;
- if (result == NULL)
- {
- larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
- if (larger_result == NULL)
- {
- errno = ENOMEM;
- goto fail;
- }
- }
- else if (result == resultbuf)
- {
- larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
- if (larger_result == NULL)
- {
- errno = ENOMEM;
- goto fail;
- }
- U_CPY (larger_result, resultbuf, length);
- }
- else
- {
- larger_result =
- (UNIT *) realloc (result, new_allocated * sizeof (UNIT));
- if (larger_result == NULL)
- {
- errno = ENOMEM;
- goto fail;
- }
- }
- result = larger_result;
- allocated = new_allocated;
- {
- int ret = U_UCTOMB (result + length, muc, allocated - length);
- if (ret == -1)
- {
- errno = EINVAL;
- goto fail;
- }
- if (ret < 0)
- abort ();
- length += ret;
- goto done_appending;
- }
+ if (ret < 0)
+ abort ();
+ length += ret;
+ goto done_appending;
}
}
- done_appending: ;
}
- }
+ done_appending: ;
+ }
if (!uc_is_case_ignorable (uc))
last_char_except_ignorable = uc;
@@ -377,9 +370,8 @@ FUNC (const UNIT *s, size_t n,
if (nf != NULL)
{
/* Finally, normalize the result. */
- UNIT *normalized_result;
-
- normalized_result = U_NORMALIZE (nf, result, length, resultbuf, lengthp);
+ UNIT *normalized_result =
+ U_NORMALIZE (nf, result, length, resultbuf, lengthp);
if (normalized_result == NULL)
goto fail;
@@ -403,9 +395,7 @@ FUNC (const UNIT *s, size_t n,
else if (result != resultbuf && length < allocated)
{
/* Shrink the allocated memory if possible. */
- UNIT *memory;
-
- memory = (UNIT *) realloc (result, length * sizeof (UNIT));
+ UNIT *memory = (UNIT *) realloc (result, length * sizeof (UNIT));
if (memory != NULL)
result = memory;
}