root/maint/gnulib/lib/unicase/u-is-cased.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. FUNC

   1 /* Test whether case matters for a Unicode string.
   2    Copyright (C) 2009-2021 Free Software Foundation, Inc.
   3    Written by Bruno Haible <bruno@clisp.org>, 2009.
   4 
   5    This file is free software.
   6    It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
   7    You can redistribute it and/or modify it under either
   8      - the terms of the GNU Lesser General Public License as published
   9        by the Free Software Foundation; either version 3, or (at your
  10        option) any later version, or
  11      - the terms of the GNU General Public License as published by the
  12        Free Software Foundation; either version 2, or (at your option)
  13        any later version, or
  14      - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
  15 
  16    This file is distributed in the hope that it will be useful,
  17    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19    Lesser General Public License and the GNU General Public License
  20    for more details.
  21 
  22    You should have received a copy of the GNU Lesser General Public
  23    License and of the GNU General Public License along with this
  24    program.  If not, see <https://www.gnu.org/licenses/>.  */
  25 
  26 int
  27 FUNC (const UNIT *s, size_t n, const char *iso639_language,
     /* [previous][next][first][last][top][bottom][index][help] */
  28       bool *resultp)
  29 {
  30   UNIT normsbuf[2048 / sizeof (UNIT)];
  31   UNIT *norms;
  32   size_t norms_length;
  33   UNIT mappedbuf[2048 / sizeof (UNIT)];
  34   UNIT *mapped_toupper;
  35   UNIT *mapped_tolower;
  36   UNIT *mapped_totitle;
  37   size_t mapped_length;
  38 
  39   /* Apply canonical decomposition to S.  */
  40   norms_length = sizeof (normsbuf) / sizeof (UNIT);
  41   norms = U_NORMALIZE (UNINORM_NFD, s, n, normsbuf, &norms_length);
  42   if (norms == NULL)
  43     /* errno is set here.  */
  44     return -1;
  45 
  46   mapped_length = sizeof (mappedbuf) / sizeof (UNIT);
  47 
  48   /* Apply toupper mapping.  */
  49   mapped_toupper = U_TOUPPER (norms, norms_length, iso639_language, NULL,
  50                               mappedbuf, &mapped_length);
  51   if (mapped_toupper == NULL)
  52     goto fail;
  53 
  54   /* Compare.  */
  55   if (!(mapped_length == norms_length
  56         && U_CMP (mapped_toupper, norms, norms_length) == 0))
  57     {
  58       if (mapped_toupper != mappedbuf)
  59         free (mapped_toupper);
  60       goto yes;
  61     }
  62 
  63   /* Apply tolower mapping.  */
  64   mapped_tolower = U_TOLOWER (norms, norms_length, iso639_language, NULL,
  65                               mapped_toupper, &mapped_length);
  66   if (mapped_tolower == NULL)
  67     {
  68       if (mapped_toupper != mappedbuf)
  69         {
  70           int saved_errno = errno;
  71           free (mapped_toupper);
  72           errno = saved_errno;
  73         }
  74       goto fail;
  75     }
  76 
  77   if (mapped_toupper != mapped_tolower && mapped_toupper != mappedbuf)
  78     free (mapped_toupper);
  79 
  80   /* Compare.  */
  81   if (!(mapped_length == norms_length
  82         && U_CMP (mapped_tolower, norms, norms_length) == 0))
  83     {
  84       if (mapped_tolower != mappedbuf)
  85         free (mapped_tolower);
  86       goto yes;
  87     }
  88 
  89   /* Apply totitle mapping.  */
  90   mapped_totitle = U_TOTITLE (norms, norms_length, iso639_language, NULL,
  91                               mapped_tolower, &mapped_length);
  92   if (mapped_totitle == NULL)
  93     {
  94       if (mapped_tolower != mappedbuf)
  95         {
  96           int saved_errno = errno;
  97           free (mapped_tolower);
  98           errno = saved_errno;
  99         }
 100       goto fail;
 101     }
 102 
 103   if (mapped_tolower != mapped_totitle && mapped_tolower != mappedbuf)
 104     free (mapped_tolower);
 105 
 106   /* Compare.  */
 107   if (!(mapped_length == norms_length
 108         && U_CMP (mapped_totitle, norms, norms_length) == 0))
 109     {
 110       if (mapped_totitle != mappedbuf)
 111         free (mapped_totitle);
 112       goto yes;
 113     }
 114 
 115   if (mapped_totitle != mappedbuf)
 116     free (mapped_totitle);
 117   if (norms != normsbuf)
 118     free (norms);
 119   *resultp = false;
 120   return 0;
 121 
 122  yes:
 123   if (norms != normsbuf)
 124     free (norms);
 125   *resultp = true;
 126   return 0;
 127 
 128  fail:
 129   if (norms != normsbuf)
 130     {
 131       int saved_errno = errno;
 132       free (norms);
 133       errno = saved_errno;
 134     }
 135   return -1;
 136 }

/* [previous][next][first][last][top][bottom][index][help] */