]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
_dbus_string_to_lower(): new function
authorRalf Habacker <ralf.habacker@freenet.de>
Fri, 12 Feb 2010 07:47:33 +0000 (08:47 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Fri, 12 Feb 2010 07:47:33 +0000 (08:47 +0100)
dbus/dbus-string.c
dbus/dbus-string.h

index d9cf18ed079af951890ea04ddc1cf4900024cdff..227f1411891f37d7c1ef061ffad4991cfce0fdcc 100644 (file)
@@ -26,6 +26,8 @@
 #include "dbus-string.h"
 /* we allow a system header here, for speed/convenience */
 #include <string.h>
+#include <ctype.h>
+
 /* for vsnprintf */
 #include <stdio.h>
 #define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
@@ -2748,6 +2750,41 @@ _dbus_string_validate_ascii (const DBusString *str,
   return TRUE;
 }
 
+/**
+ * converts the given range of the string to lower case 
+ *
+ * @param str the string
+ * @param start first byte index to convert
+ * @param len number of bytes to convert
+ * @returns #TRUE if the byte range exists
+ */
+dbus_bool_t
+_dbus_string_to_lower (const DBusString *str,
+                       int               start,
+                       int               len)
+{
+  unsigned char *s;
+  unsigned char *end;
+  DBUS_CONST_STRING_PREAMBLE (str);
+  _dbus_assert (start >= 0);
+  _dbus_assert (start <= real->len);
+  _dbus_assert (len >= 0);
+  
+  if (len > real->len - start)
+    return FALSE;
+  
+  s = real->str + start;
+  end = s + len;
+  while (s != end)
+    {
+      if (isupper(*s))
+        *s = tolower(*s);
+      ++s;
+    }
+  
+  return TRUE;
+}
+
 /**
  * Checks that the given range of the string is valid UTF-8. If the
  * given range is not entirely contained in the string, returns
index 7c3011191d914e9a5a9586982a3465711397281d..dbea33306e5ae9d5d66870b258cdfac56d83b4e3 100644 (file)
@@ -43,7 +43,11 @@ typedef struct DBusString DBusString;
 
 struct DBusString
 {
+#ifdef _DEBUG
+  char *dummy1; /**< placeholder */
+#else
   const void *dummy1; /**< placeholder */
+#endif
   int   dummy2;       /**< placeholder */
   int   dummy3;       /**< placeholder */
   int   dummy4;       /**< placeholder */
@@ -284,6 +288,9 @@ dbus_bool_t   _dbus_string_hex_decode            (const DBusString  *source,
                                                  int               *end_return,
                                                   DBusString        *dest,
                                                   int                insert_at);
+dbus_bool_t   _dbus_string_to_lower              (const DBusString *str,
+                                                  int               start,
+                                                  int               len);
 dbus_bool_t   _dbus_string_validate_ascii        (const DBusString  *str,
                                                   int                start,
                                                   int                len);