root/maint/gnulib/lib/unicase/ulc-casexfrm.c

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

DEFINITIONS

This source file includes following definitions.
  1. ulc_casexfrm

   1 /* Locale dependent transformation for case insensitive comparison of 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 #include <config.h>
  27 
  28 /* Specification.  */
  29 #include "unicase.h"
  30 
  31 #include <errno.h>
  32 #include <stdlib.h>
  33 
  34 #include "uniconv.h"
  35 
  36 char *
  37 ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
     /* [previous][next][first][last][top][bottom][index][help] */
  38               uninorm_t nf,
  39               char *resultbuf, size_t *lengthp)
  40 {
  41   uint8_t convbuf[2048 / sizeof (uint8_t)];
  42   uint8_t *conv;
  43   size_t conv_length;
  44   char *result;
  45 
  46   /* Convert the string to UTF-8.  */
  47   conv_length = sizeof (convbuf) / sizeof (uint8_t);
  48   conv =
  49     u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL,
  50                            convbuf, &conv_length);
  51   if (conv == NULL)
  52     /* errno is set here.  */
  53     return NULL;
  54 
  55   /* Case-fold and normalize.  */
  56   result = u8_casexfrm (conv, conv_length, iso639_language, nf,
  57                         resultbuf, lengthp);
  58   if (result == NULL)
  59     {
  60       if (conv != convbuf)
  61         {
  62           int saved_errno = errno;
  63           free (conv);
  64           errno = saved_errno;
  65         }
  66       return NULL;
  67     }
  68 
  69   if (conv != convbuf)
  70     free (conv);
  71   return result;
  72 }

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