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

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. FUNC

   1 /* Test whether a Unicode string is invariant under a given case mapping.
   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,
     /* [previous][next][first][last][top][bottom][index][help] */
  28       UNIT * (*mapping) (const UNIT *s, size_t n, const char *iso639_language,
  29                          uninorm_t nf,
  30                          UNIT *resultbuf, size_t *lengthp),
  31       const char *iso639_language,
  32       bool *resultp)
  33 {
  34   UNIT normsbuf[2048 / sizeof (UNIT)];
  35   UNIT *norms;
  36   size_t norms_length;
  37   UNIT mappedbuf[2048 / sizeof (UNIT)];
  38   UNIT *mapped;
  39   size_t mapped_length;
  40 
  41   /* Apply canonical decomposition to S.  */
  42   norms_length = sizeof (normsbuf) / sizeof (UNIT);
  43   norms = U_NORMALIZE (UNINORM_NFD, s, n, normsbuf, &norms_length);
  44   if (norms == NULL)
  45     /* errno is set here.  */
  46     return -1;
  47 
  48   /* Apply mapping.  */
  49   mapped_length = sizeof (mappedbuf) / sizeof (UNIT);
  50   mapped = mapping (norms, norms_length, iso639_language, NULL,
  51                     mappedbuf, &mapped_length);
  52   if (mapped == NULL)
  53     {
  54       if (norms != normsbuf)
  55         {
  56           int saved_errno = errno;
  57           free (norms);
  58           errno = saved_errno;
  59         }
  60       return -1;
  61     }
  62 
  63   /* Compare.  */
  64   *resultp = (mapped_length == norms_length
  65               && U_CMP (mapped, norms, norms_length) == 0);
  66 
  67   if (mapped != mappedbuf)
  68     free (mapped);
  69   if (norms != normsbuf)
  70     free (norms);
  71   return 0;
  72 }

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