root/maint/gnulib/lib/unicase/u-casecoll.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. FUNC

   1 /* Locale dependent, case and normalization insensitive comparison of Unicode
   2    strings.
   3    Copyright (C) 2009-2021 Free Software Foundation, Inc.
   4    Written by Bruno Haible <bruno@clisp.org>, 2009.
   5 
   6    This file is free software.
   7    It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
   8    You can redistribute it and/or modify it under either
   9      - the terms of the GNU Lesser General Public License as published
  10        by the Free Software Foundation; either version 3, or (at your
  11        option) any later version, or
  12      - the terms of the GNU General Public License as published by the
  13        Free Software Foundation; either version 2, or (at your option)
  14        any later version, or
  15      - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
  16 
  17    This file is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20    Lesser General Public License and the GNU General Public License
  21    for more details.
  22 
  23    You should have received a copy of the GNU Lesser General Public
  24    License and of the GNU General Public License along with this
  25    program.  If not, see <https://www.gnu.org/licenses/>.  */
  26 
  27 int
  28 FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
     /* [previous][next][first][last][top][bottom][index][help] */
  29       const char *iso639_language, uninorm_t nf, int *resultp)
  30 {
  31   char buf1[2048];
  32   char buf2[2048];
  33   char *transformed1;
  34   size_t transformed1_length;
  35   char *transformed2;
  36   size_t transformed2_length;
  37   int cmp;
  38 
  39   /* Normalize and transform S1.  */
  40   transformed1_length = sizeof (buf1);
  41   transformed1 =
  42     U_CASEXFRM (s1, n1, iso639_language, nf, buf1, &transformed1_length);
  43   if (transformed1 == NULL)
  44     /* errno is set here.  */
  45     return -1;
  46 
  47   /* Normalize and transform S2.  */
  48   transformed2_length = sizeof (buf2);
  49   transformed2 =
  50     U_CASEXFRM (s2, n2, iso639_language, nf, buf2, &transformed2_length);
  51   if (transformed2 == NULL)
  52     {
  53       if (transformed1 != buf1)
  54         {
  55           int saved_errno = errno;
  56           free (transformed1);
  57           errno = saved_errno;
  58         }
  59       return -1;
  60     }
  61 
  62   /* Compare the transformed strings.  */
  63   cmp = memcmp2 (transformed1, transformed1_length,
  64                  transformed2, transformed2_length);
  65   if (cmp < 0)
  66     cmp = -1;
  67   else if (cmp > 0)
  68     cmp = 1;
  69 
  70   if (transformed2 != buf2)
  71     free (transformed2);
  72   if (transformed1 != buf1)
  73     free (transformed1);
  74   *resultp = cmp;
  75   return 0;
  76 }

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