addition of g_toupper and g_tolower



Ouch, I just discovered that anoncvs.gnome.org was round-robin DNS'd,
w/ mirrors being out-of-sync.  Anyways..

Instead of checking to make sure the arg passed to toupper/tolower
is correct, might as well create g_to{upper,lower}.  I made the
assumption that gutils would be the proper place for these functions.

(http://incandescent.mp3revolution.net/glib/tofncts.diff)
-- 
"... being a Linux user is sort of like living in a house inhabited
by a large family of carpenters and architects. Every morning when
you wake up, the house is a little different. Maybe there is a new
turret, or some walls have moved. Or perhaps someone has temporarily
removed the floor under your bed." - Unix for Dummies, 2nd Edition
        -- found in the .sig of Rob Riggs, rriggs tesser com
diff -urN glib/ChangeLog glib.dilinger/ChangeLog
--- glib/ChangeLog	Wed Apr  4 02:03:44 2001
+++ glib.dilinger/ChangeLog	Wed Apr  4 02:05:10 2001
@@ -1,3 +1,13 @@
+Tue Apr  3 21:58:39 2001  Andres Salomon  <dilinger mp3revolution net>
+
+	* gutils.h: added g_toupper() and g_tolower(); let this handle cases
+	where a system's toupper/tolower acts screwy when supplied w/ an
+	uppercase/lowercase char, respectively.
+
+	* gstring.c: changed to use new g_to{upper,lower}().
+
+	* gstrfuncs.c: changed to use new g_to{upper,lower}().
+
 Tue Apr  3 20:22:59 2001  Tim Janik  <timj gtk org>
 
 	* NEWS: updates.
diff -urN glib/gstrfuncs.c glib.dilinger/gstrfuncs.c
--- glib/gstrfuncs.c	Wed Apr  4 02:03:43 2001
+++ glib.dilinger/gstrfuncs.c	Wed Apr  4 02:07:37 2001
@@ -37,7 +37,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <locale.h>
-#include <ctype.h>		/* For tolower() */
 #if !defined (HAVE_STRSIGNAL) || !defined(NO_SYS_SIGLIST_DECL)
 #include <signal.h>
 #endif
@@ -972,7 +971,7 @@
   
   while (*s)
     {
-      *s = tolower (*s);
+      *s = g_tolower (*s);
       s++;
     }
   
@@ -990,7 +989,7 @@
 
   while (*s)
     {
-      *s = toupper (*s);
+      *s = g_toupper (*s);
       s++;
     }
 
@@ -1041,11 +1040,8 @@
 
   while (*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;
+      c1 = g_tolower (*s1);
+      c2 = g_tolower (*s2);
       if (c1 != c2)
 	return (c1 - c2);
       s1++; s2++;
@@ -1071,11 +1067,8 @@
   while (n && *s1 && *s2)
     {
       n -= 1;
-      /* 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;
+      c1 = g_tolower (*s1);
+      c2 = g_tolower (*s2);
       if (c1 != c2)
 	return (c1 - c2);
       s1++; s2++;
diff -urN glib/gstring.c glib.dilinger/gstring.c
--- glib/gstring.c	Wed Apr  4 02:03:43 2001
+++ glib.dilinger/gstring.c	Wed Apr  4 02:08:06 2001
@@ -535,7 +535,7 @@
 
   while (n)
     {
-      *s = tolower (*s);
+      *s = g_tolower (*s);
       s++;
       n--;
     }
@@ -556,7 +556,7 @@
 
   while (n)
     {
-      *s = toupper (*s);
+      *s = g_toupper (*s);
       s++;
       n--;
     }
diff -urN glib/gutils.h glib.dilinger/gutils.h
--- glib/gutils.h	Wed Apr  4 02:03:44 2001
+++ glib.dilinger/gutils.h	Wed Apr  4 02:10:04 2001
@@ -29,6 +29,7 @@
 
 #include <gtypes.h>
 #include <stdarg.h>
+#include <ctype.h>
 
 G_BEGIN_DECLS
 
@@ -303,6 +304,30 @@
 }
 #endif  /* G_CAN_INLINE || __G_UTILS_C__ */
 
+/*
+ * Quoting from the comp.lang.c FAQ:
+ * 13.5:
+ *   Why do some versions of toupper() act strangely if given an
+ *   upper-case letter?
+ *
+ *   A: Older versions of toupper() and tolower() did not always work as
+ *        expected in this regard.
+ *
+ * Apparently, some older libcs simply inverted the case; this is the
+ * reason for the following two functions.
+ */
+G_INLINE_FUNC gint
+g_toupper(gint c)
+{
+  return islower(c) ? toupper(c) : c;
+}
+
+G_INLINE_FUNC gint
+g_tolower(gint c)
+{
+  return isupper(c) ? tolower(c) : c;
+}
+		
 /* Glib version.
  * we prefix variable declarations so they can
  * properly get exported in windows dlls.


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