root/maint/gnulib/lib/unistr/u16-strchr.c

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

DEFINITIONS

This source file includes following definitions.
  1. u16_strchr

   1 /* Search character in UTF-16 string.
   2    Copyright (C) 1999, 2002, 2006-2007, 2009-2021 Free Software Foundation,
   3    Inc.
   4    Written by Bruno Haible <bruno@clisp.org>, 2002.
   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 #include <config.h>
  28 
  29 /* Specification.  */
  30 #include "unistr.h"
  31 
  32 uint16_t *
  33 u16_strchr (const uint16_t *s, ucs4_t uc)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35   uint16_t c[2];
  36 
  37   if (uc < 0x10000)
  38     {
  39       uint16_t c0 = uc;
  40 
  41       for (;; s++)
  42         {
  43           if (*s == c0)
  44             break;
  45           if (*s == 0)
  46             goto notfound;
  47         }
  48       return (uint16_t *) s;
  49     }
  50   else
  51     switch (u16_uctomb_aux (c, uc, 2))
  52       {
  53       case 2:
  54         if (*s == 0)
  55           goto notfound;
  56         {
  57           uint16_t c0 = c[0];
  58           uint16_t c1 = c[1];
  59 
  60           for (;; s++)
  61             {
  62               if (s[1] == 0)
  63                 goto notfound;
  64               if (*s == c0 && s[1] == c1)
  65                 break;
  66             }
  67           return (uint16_t *) s;
  68         }
  69       }
  70 notfound:
  71   return NULL;
  72 }

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