root/maint/gnulib/lib/uninorm/u-normcoll.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. FUNC

   1 /* Locale dependent, normalization insensitive comparison of Unicode strings.
   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 *s1, size_t n1, const UNIT *s2, size_t n2,
     /* [previous][next][first][last][top][bottom][index][help] */
  28       uninorm_t nf, int *resultp)
  29 {
  30   char buf1[2048];
  31   char buf2[2048];
  32   char *transformed1;
  33   size_t transformed1_length;
  34   char *transformed2;
  35   size_t transformed2_length;
  36   int cmp;
  37 
  38   /* Normalize and transform S1.  */
  39   transformed1_length = sizeof (buf1);
  40   transformed1 = U_NORMXFRM (s1, n1, nf, buf1, &transformed1_length);
  41   if (transformed1 == NULL)
  42     /* errno is set here.  */
  43     return -1;
  44 
  45   /* Normalize and transform S2.  */
  46   transformed2_length = sizeof (buf2);
  47   transformed2 = U_NORMXFRM (s2, n2, nf, buf2, &transformed2_length);
  48   if (transformed2 == NULL)
  49     {
  50       if (transformed1 != buf1)
  51         {
  52           int saved_errno = errno;
  53           free (transformed1);
  54           errno = saved_errno;
  55         }
  56       return -1;
  57     }
  58 
  59   /* Compare the transformed strings.  */
  60   cmp = memcmp2 (transformed1, transformed1_length,
  61                  transformed2, transformed2_length);
  62   if (cmp < 0)
  63     cmp = -1;
  64   else if (cmp > 0)
  65     cmp = 1;
  66 
  67   if (transformed2 != buf2)
  68     free (transformed2);
  69   if (transformed1 != buf1)
  70     free (transformed1);
  71   *resultp = cmp;
  72   return 0;
  73 }

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