Re: g_strncasecmp in glib



On Wed, 4 Nov 1998, Phil Schwan wrote:

> Does anyone mind if I commit this patch?  Is there some reason that
> I'm not aware of that there's not already a g_strncasecmp?
> 
> -Phil
> 
> ------------------------------------------------------------------
> "In film you will find four basic story lines. Man versus man, man
> versus nature, nature versus nature, and dog versus vampire."
>         - Steven Spielberg
> 
> 
> diff -ru glib-old/configure.in glib/configure.in
> --- glib-old/configure.in	Mon Nov  2 02:04:36 1998
> +++ glib/configure.in	Wed Nov  4 17:33:59 1998
> @@ -233,7 +233,7 @@
>  AC_CHECK_HEADERS(values.h, AC_DEFINE(HAVE_VALUES_H))
>  
>  # Check for some functions
> -AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp)
> +AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp strncasecmp)
>  
>  # Check for sys_errlist
>  AC_MSG_CHECKING(for sys_errlist)
> diff -ru glib-old/glib.h glib/glib.h
> --- glib-old/glib.h	Tue Nov  3 09:52:23 1998
> +++ glib/glib.h	Wed Nov  4 17:15:31 1998
> @@ -1402,6 +1402,9 @@
>  gchar*	 g_strsignal		(gint	      signum);
>  gint	 g_strcasecmp		(const gchar *s1,
>  				 const gchar *s2);
> +gint	 g_strncasecmp		(const gchar *s1,
> +				 const gchar *s2,
> +				 guint 	      n);
>  void	 g_strdown		(gchar	     *string);
>  void	 g_strup		(gchar	     *string);
>  void	 g_strreverse		(gchar	     *string);
> diff -ru glib-old/gstrfuncs.c glib/gstrfuncs.c
> --- glib-old/gstrfuncs.c	Sat Oct 31 23:19:50 1998
> +++ glib/gstrfuncs.c	Wed Nov  4 17:40:05 1998
> @@ -975,6 +975,38 @@
>  #endif
>  }
>  
> +gint
> +g_strncasecmp (const gchar *s1,
> +	       const gchar *s2,
> +	       guint n)
> +{
> +#ifdef HAVE_STRNCASECMP
> +  return strncasecmp (s1, s2, n);
> +#else
> +  gint c1, c2;
> +  
> +  g_return_val_if_fail (s1 != NULL, 0);
> +  g_return_val_if_fail (s2 != NULL, 0);
> +
> +  while (n-- && *s1 && *s2)
> +    {
> +      /* According to A. Cox, some platforms have islower's that
> +       * don't work right on non-uppercase
> +       */
> +      c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1;
> +      c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2;
> +      if (c1 != c2)
> +	return (c1 - c2);
> +      s1++; s2++;
> +    }
> +
> +  if (n)
> +    return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
> +  else
> +    return 0;
> +#endif
> +}
> +
>  gchar*
>  g_strdelimit (gchar	  *string,
>  	      const gchar *delimiters,
> 

this looks perfecly ok to me. please commit it as is.

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]