[PATCH] New functions wcscasecmp, wcsncasecmp (was Re: [PATCH] New functions fwscanf, swscanf, vfwscanf, vswscanf, vwscanf, wscanf)

Corinna Vinschen vinschen@redhat.com
Thu Mar 12 01:22:00 GMT 2009


On Mar 11 12:53, Corinna Vinschen wrote:
> AFAICS, the only SUSv3 wide-char functions missing now are wcstold,
> wcscasecmp and wcsncasecmp.  wcstold is in discussion, but the latter
> two might be tricky...

Not so.  I just applied the below patch which adds wcscasecmp and wcsncasecmp.


Corinna


	* libc/include/wchar.h (wcscasecmp, wcsncasecmp): Declare.
	* libc/string/Makefile.am: Add wcscasecmp.c, wcsncasecmp.c
	* libc/stdio/Makefile.in: Regenerate.
	* libc/string/strings.tex: Add new documentation references.
	* libc/string/wcscasecmp.c: New file.
	* libc/string/wcsncasecmp.c: New file.

 
Index: libc/include/wchar.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/wchar.h,v
retrieving revision 1.25
diff -u -p -r1.25 wchar.h
--- libc/include/wchar.h	11 Mar 2009 11:53:22 -0000	1.25
+++ libc/include/wchar.h	11 Mar 2009 12:56:53 -0000
@@ -65,6 +65,7 @@ size_t	_EXFUN(_wcsnrtombs_r, (struct _re
 size_t	_EXFUN(wcsrtombs, (char * , const wchar_t ** , size_t, mbstate_t *));
 size_t	_EXFUN(_wcsrtombs_r, (struct _reent *, char * , const wchar_t ** , 
 			size_t, mbstate_t *));
+int	_EXFUN(wcscasecmp, (const wchar_t *, const wchar_t *));
 wchar_t	*_EXFUN(wcscat, (wchar_t * , const wchar_t *));
 wchar_t	*_EXFUN(wcschr, (const wchar_t *, wchar_t));
 int	_EXFUN(wcscmp, (const wchar_t *, const wchar_t *));
@@ -76,6 +77,7 @@ size_t  _EXFUN(wcsftime, (wchar_t *, siz
 size_t	_EXFUN(wcslcat, (wchar_t *, const wchar_t *, size_t));
 size_t	_EXFUN(wcslcpy, (wchar_t *, const wchar_t *, size_t));
 size_t	_EXFUN(wcslen, (const wchar_t *));
+int	_EXFUN(wcsncasecmp, (const wchar_t *, const wchar_t *, size_t));
 wchar_t	*_EXFUN(wcsncat, (wchar_t * , const wchar_t * , size_t));
 int	_EXFUN(wcsncmp, (const wchar_t *, const wchar_t *, size_t));
 wchar_t	*_EXFUN(wcsncpy, (wchar_t *  , const wchar_t * , size_t));
Index: libc/string/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/Makefile.am,v
retrieving revision 1.22
diff -u -p -r1.22 Makefile.am
--- libc/string/Makefile.am	12 Dec 2008 19:47:05 -0000	1.22
+++ libc/string/Makefile.am	11 Mar 2009 12:56:53 -0000
@@ -98,7 +98,9 @@ if ELIX_LEVEL_3
 ELIX_4_SOURCES =
 else
 ELIX_4_SOURCES = \
-	memmem.c
+	memmem.c \
+	wcscasecmp.c \
+	wcsncasecmp.c
 endif !ELIX_LEVEL_3
 endif !ELIX_LEVEL_2
 endif !ELIX_LEVEL_1
@@ -127,9 +129,9 @@ memchr.def	strcat.def	strerror.def	strer
 memcmp.def	strchr.def	strlen.def	strnlen.def strspn.def \
 strcasecmp.def	strncasecmp.def strcasestr.def	strlwr.def  strupr.def \
 memccpy.def 	mempcpy.def	stpcpy.def	stpncpy.def \
-wcscat.def	wcschr.def	wcscmp.def	wcscoll.def \
+wcscasecmp.def	wcscat.def	wcschr.def	wcscmp.def wcscoll.def \
 wcscpy.def	wcscspn.def	wcpcpy.def	wcpncpy.def \
-wcslcat.def	wcslcpy.def	wcslen.def	wcsncat.def \
+wcslcat.def	wcslcpy.def	wcslen.def	wcsncasecmp.def wcsncat.def \
 wcsncmp.def	wcsncpy.def	wcsnlen.def	wcspbrk.def \
 wcsrchr.def	wcsspn.def	wcsstr.def 	wcstok.def  \
 wcswidth.def	wcsxfrm.def	wcwidth.def	wmemchr.def \
Index: libc/string/strings.tex
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/strings.tex,v
retrieving revision 1.9
diff -u -p -r1.9 strings.tex
--- libc/string/strings.tex	12 Jan 2008 04:25:55 -0000	1.9
+++ libc/string/strings.tex	11 Mar 2009 12:56:53 -0000
@@ -46,6 +46,8 @@ managing areas of memory.  The correspon
 * strupr::	Convert string to upper case
 * strxfrm::     Transform string
 * swab::        Swap adjacent bytes
+* wcscasecmp::  Compare wide character strings ignoring case
+* wcsncasecmp:: Compare wide character strings ignoring case
 @end menu
 
 @page
@@ -167,3 +169,9 @@ managing areas of memory.  The correspon
 
 @page
 @include string/swab.def
+
+@page
+@include string/wcscasecmp.def
+
+@page
+@include string/wcsncasecmp.def
Index: libc/string/wcscasecmp.c
===================================================================
RCS file: libc/string/wcscasecmp.c
diff -N libc/string/wcscasecmp.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libc/string/wcscasecmp.c	11 Mar 2009 12:56:53 -0000
@@ -0,0 +1,56 @@
+/*
+FUNCTION
+	<<wcscasecmp>>---case-insensitive wide character string compare
+	
+INDEX
+	wcscasecmp
+
+ANSI_SYNOPSIS
+	#include <wchar.h>
+	int wcscasecmp(const wchar_t *<[a]>, const wchar_t *<[b]>);
+
+TRAD_SYNOPSIS
+	#include <wchar.h>
+	int wcscasecmp(<[a]>, <[b]>)
+	wchar_t *<[a]>;
+	wchar_t *<[b]>;
+
+DESCRIPTION
+	<<wcscasecmp>> compares the wide character string at <[a]> to
+	the wide character string at <[b]> in a case-insensitive manner.
+
+RETURNS 
+
+	If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
+	both are converted to uppercase), <<wcscasecmp>> returns a
+	number greater than zero.  If the two strings match,
+	<<wcscasecmp>> returns zero.  If <<*<[a]>>> sorts
+	lexicographically before <<*<[b]>>>, <<wcscasecmp>> returns a
+	number less than zero.
+
+PORTABILITY
+POSIX-1.2008
+
+<<wcscasecmp>> requires no supporting OS subroutines. It uses
+tolower() from elsewhere in this library.
+
+QUICKREF
+	wcscasecmp 
+*/
+
+#include <wchar.h>
+#include <wctype.h>
+
+int
+_DEFUN (wcscasecmp, (s1, s2),
+	_CONST wchar_t *s1 _AND
+	_CONST wchar_t *s2)
+{
+  while (*s1 != '\0' && towlower(*s1) == towlower(*s2))
+    {
+      s1++;
+      s2++;
+    }
+
+  return towlower(*s1) - towlower(*s2);
+}
Index: libc/string/wcsncasecmp.c
===================================================================
RCS file: libc/string/wcsncasecmp.c
diff -N libc/string/wcsncasecmp.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libc/string/wcsncasecmp.c	11 Mar 2009 12:56:53 -0000
@@ -0,0 +1,64 @@
+/*
+FUNCTION
+	<<wcsncasecmp>>---case-insensitive wide character string compare
+	
+INDEX
+	wcsncasecmp
+
+ANSI_SYNOPSIS
+	#include <wchar.h>
+	int wcsncasecmp(const wchar_t *<[a]>, const wchar_t * <[b]>, size_t <[length]>);
+
+TRAD_SYNOPSIS
+	#include <wchar.h>
+	int wcsncasecmp(<[a]>, <[b]>, <[length]>)
+	wchar_t *<[a]>;
+	wchar_t *<[b]>;
+	size_t <[length]>
+
+DESCRIPTION
+	<<wcsncasecmp>> compares up to <[length]> wide characters
+	from the string at <[a]> to the string at <[b]> in a 
+	case-insensitive manner.
+
+RETURNS
+
+	If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
+	both are converted to uppercase), <<wcsncasecmp>> returns a
+	number greater than zero.  If the two strings are equivalent,
+	<<wcsncasecmp>> returns zero.  If <<*<[a]>>> sorts
+	lexicographically before <<*<[b]>>>, <<wcsncasecmp>> returns a
+	number less than zero.
+
+PORTABILITY
+POSIX-1.2008
+
+<<wcsncasecmp>> requires no supporting OS subroutines. It uses
+tolower() from elsewhere in this library.
+
+QUICKREF
+	wcsncasecmp
+*/
+
+#include <wchar.h>
+#include <wctype.h>
+
+int 
+_DEFUN (wcsncasecmp, (s1, s2, n),
+	_CONST wchar_t *s1 _AND
+	_CONST wchar_t *s2 _AND
+	size_t n)
+{
+  if (n == 0)
+    return 0;
+
+  while (n-- != 0 && towlower(*s1) == towlower(*s2))
+    {
+      if (n == 0 || *s1 == '\0' || *s2 == '\0')
+	break;
+      s1++;
+      s2++;
+    }
+
+  return towlower(*s1) - towlower(*s2);
+}

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat



More information about the Newlib mailing list