Blame glib/pcre/pcre_string_utils.c

Packit ae235b
/*************************************************
Packit ae235b
*      Perl-Compatible Regular Expressions       *
Packit ae235b
*************************************************/
Packit ae235b
Packit ae235b
/* PCRE is a library of functions to support regular expressions whose syntax
Packit ae235b
and semantics are as close as possible to those of the Perl 5 language.
Packit ae235b
Packit ae235b
                       Written by Philip Hazel
Packit ae235b
           Copyright (c) 1997-2012 University of Cambridge
Packit ae235b
Packit ae235b
-----------------------------------------------------------------------------
Packit ae235b
Redistribution and use in source and binary forms, with or without
Packit ae235b
modification, are permitted provided that the following conditions are met:
Packit ae235b
Packit ae235b
    * Redistributions of source code must retain the above copyright notice,
Packit ae235b
      this list of conditions and the following disclaimer.
Packit ae235b
Packit ae235b
    * Redistributions in binary form must reproduce the above copyright
Packit ae235b
      notice, this list of conditions and the following disclaimer in the
Packit ae235b
      documentation and/or other materials provided with the distribution.
Packit ae235b
Packit ae235b
    * Neither the name of the University of Cambridge nor the names of its
Packit ae235b
      contributors may be used to endorse or promote products derived from
Packit ae235b
      this software without specific prior written permission.
Packit ae235b
Packit ae235b
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit ae235b
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit ae235b
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit ae235b
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit ae235b
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit ae235b
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit ae235b
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit ae235b
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit ae235b
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit ae235b
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit ae235b
POSSIBILITY OF SUCH DAMAGE.
Packit ae235b
-----------------------------------------------------------------------------
Packit ae235b
*/
Packit ae235b
Packit ae235b
Packit ae235b
/* This module contains an internal function that is used to match an extended
Packit ae235b
class. It is used by both pcre_exec() and pcre_def_exec(). */
Packit ae235b
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include "pcre_internal.h"
Packit ae235b
Packit ae235b
#ifndef COMPILE_PCRE8
Packit ae235b
Packit ae235b
/*************************************************
Packit ae235b
*           Compare string utilities             *
Packit ae235b
*************************************************/
Packit ae235b
Packit ae235b
/* The following two functions compares two strings. Basically an strcmp
Packit ae235b
for non 8 bit characters.
Packit ae235b
Packit ae235b
Arguments:
Packit ae235b
  str1        first string
Packit ae235b
  str2        second string
Packit ae235b
Packit ae235b
Returns:      0 if both string are equal (like strcmp), 1 otherwise
Packit ae235b
*/
Packit ae235b
Packit ae235b
int
Packit ae235b
PRIV(strcmp_uc_uc)(const pcre_uchar *str1, const pcre_uchar *str2)
Packit ae235b
{
Packit ae235b
pcre_uchar c1;
Packit ae235b
pcre_uchar c2;
Packit ae235b
Packit ae235b
while (*str1 != '\0' || *str2 != '\0')
Packit ae235b
  {
Packit ae235b
  c1 = *str1++;
Packit ae235b
  c2 = *str2++;
Packit ae235b
  if (c1 != c2)
Packit ae235b
    return ((c1 > c2) << 1) - 1;
Packit ae235b
  }
Packit ae235b
/* Both length and characters must be equal. */
Packit ae235b
return 0;
Packit ae235b
}
Packit ae235b
Packit ae235b
int
Packit ae235b
PRIV(strcmp_uc_c8)(const pcre_uchar *str1, const char *str2)
Packit ae235b
{
Packit ae235b
const pcre_uint8 *ustr2 = (pcre_uint8 *)str2;
Packit ae235b
pcre_uchar c1;
Packit ae235b
pcre_uchar c2;
Packit ae235b
Packit ae235b
while (*str1 != '\0' || *ustr2 != '\0')
Packit ae235b
  {
Packit ae235b
  c1 = *str1++;
Packit ae235b
  c2 = (pcre_uchar)*ustr2++;
Packit ae235b
  if (c1 != c2)
Packit ae235b
    return ((c1 > c2) << 1) - 1;
Packit ae235b
  }
Packit ae235b
/* Both length and characters must be equal. */
Packit ae235b
return 0;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* The following two functions compares two, fixed length
Packit ae235b
strings. Basically an strncmp for non 8 bit characters.
Packit ae235b
Packit ae235b
Arguments:
Packit ae235b
  str1        first string
Packit ae235b
  str2        second string
Packit ae235b
  num         size of the string
Packit ae235b
Packit ae235b
Returns:      0 if both string are equal (like strcmp), 1 otherwise
Packit ae235b
*/
Packit ae235b
Packit ae235b
int
Packit ae235b
PRIV(strncmp_uc_uc)(const pcre_uchar *str1, const pcre_uchar *str2, unsigned int num)
Packit ae235b
{
Packit ae235b
pcre_uchar c1;
Packit ae235b
pcre_uchar c2;
Packit ae235b
Packit ae235b
while (num-- > 0)
Packit ae235b
  {
Packit ae235b
  c1 = *str1++;
Packit ae235b
  c2 = *str2++;
Packit ae235b
  if (c1 != c2)
Packit ae235b
    return ((c1 > c2) << 1) - 1;
Packit ae235b
  }
Packit ae235b
/* Both length and characters must be equal. */
Packit ae235b
return 0;
Packit ae235b
}
Packit ae235b
Packit ae235b
int
Packit ae235b
PRIV(strncmp_uc_c8)(const pcre_uchar *str1, const char *str2, unsigned int num)
Packit ae235b
{
Packit ae235b
const pcre_uint8 *ustr2 = (pcre_uint8 *)str2;
Packit ae235b
pcre_uchar c1;
Packit ae235b
pcre_uchar c2;
Packit ae235b
Packit ae235b
while (num-- > 0)
Packit ae235b
  {
Packit ae235b
  c1 = *str1++;
Packit ae235b
  c2 = (pcre_uchar)*ustr2++;
Packit ae235b
  if (c1 != c2)
Packit ae235b
    return ((c1 > c2) << 1) - 1;
Packit ae235b
  }
Packit ae235b
/* Both length and characters must be equal. */
Packit ae235b
return 0;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* The following function returns with the length of
Packit ae235b
a zero terminated string. Basically an strlen for non 8 bit characters.
Packit ae235b
Packit ae235b
Arguments:
Packit ae235b
  str         string
Packit ae235b
Packit ae235b
Returns:      length of the string
Packit ae235b
*/
Packit ae235b
Packit ae235b
unsigned int
Packit ae235b
PRIV(strlen_uc)(const pcre_uchar *str)
Packit ae235b
{
Packit ae235b
unsigned int len = 0;
Packit ae235b
while (*str++ != 0)
Packit ae235b
  len++;
Packit ae235b
return len;
Packit ae235b
}
Packit ae235b
Packit ae235b
#endif /* COMPILE_PCRE8 */
Packit ae235b
Packit ae235b
/* End of pcre_string_utils.c */