[PATCH] _dbus_string_toupper_ascii(): new function, reviewed by Colin Walters.

Ralf Habacker ralf.habacker at freenet.de
Sun Feb 28 12:32:05 PST 2010


---
 dbus/dbus-1-symbols.def.in |    1 +
 dbus/dbus-string-util.c    |   32 ++++++++++++++++++++++++++++++++
 dbus/dbus-string.c         |   31 +++++++++++++++++++++++++++++++
 dbus/dbus-string.h         |    3 +++
 4 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/dbus/dbus-1-symbols.def.in b/dbus/dbus-1-symbols.def.in
index e943357..ca9eb59 100644
--- a/dbus/dbus-1-symbols.def.in
+++ b/dbus/dbus-1-symbols.def.in
@@ -388,6 +388,7 @@ _dbus_string_skip_white_reverse
 _dbus_string_split_on_byte
 _dbus_string_steal_data
 _dbus_string_tolower_ascii
+_dbus_string_toupper_ascii
 _dbus_string_validate_ascii
 _dbus_string_validate_nul
 _dbus_string_validate_utf8
diff --git a/dbus/dbus-string-util.c b/dbus/dbus-string-util.c
index 9ca5d6c..666ffbd 100644
--- a/dbus/dbus-string-util.c
+++ b/dbus/dbus-string-util.c
@@ -904,6 +904,38 @@ _dbus_string_test (void)
     _dbus_string_free (&str);
   }
 
+  {
+    const char lower_string[] = "toupperstring";
+    const char upper_string[] = "TOUPPERSTRING";
+    const char upper2_string[] = "TOUPPERstring";
+
+    if (!_dbus_string_init (&str))
+      _dbus_assert_not_reached ("no memory");
+
+    if (!_dbus_string_append (&str, lower_string))
+      _dbus_assert_not_reached ("no memory");
+
+    _dbus_string_toupper_ascii (&str, 0, _dbus_string_get_length(&str));
+
+    if (!_dbus_string_equal_c_str (&str, upper_string))
+      _dbus_assert_not_reached ("_dbus_string_toupper_ascii failed");
+
+    _dbus_string_free (&str);
+
+    if (!_dbus_string_init (&str))
+      _dbus_assert_not_reached ("no memory");
+
+    if (!_dbus_string_append (&str, lower_string))
+      _dbus_assert_not_reached ("no memory");
+
+    _dbus_string_toupper_ascii (&str, 0, 7);
+
+    if (!_dbus_string_equal_c_str (&str, upper2_string))
+      _dbus_assert_not_reached ("_dbus_string_toupper_ascii failed in partial conversion");
+
+    _dbus_string_free (&str);
+  }
+
   return TRUE;
 }
 
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 6a307b8..4d799f9 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -2791,6 +2791,37 @@ _dbus_string_tolower_ascii (const DBusString *str,
 }
 
 /**
+ * Converts the given range of the string to upper case.
+ *
+ * @param str the string
+ * @param start first byte index to convert
+ * @param len number of bytes to convert
+ */
+void
+_dbus_string_toupper_ascii (const DBusString *str,
+                            int               start,
+                            int               len)
+{
+  unsigned char *s;
+  unsigned char *end;
+  DBUS_STRING_PREAMBLE (str);
+  _dbus_assert (start >= 0);
+  _dbus_assert (start <= real->len);
+  _dbus_assert (len >= 0);
+  _dbus_assert (len <= real->len - start);
+
+  s = real->str + start;
+  end = s + len;
+
+  while (s != end)
+    {
+      if (*s >= 'a' && *s <= 'z')
+          *s += 'A' - 'a';
+      ++s;
+    }
+}
+
+/**
  * Checks that the given range of the string is valid UTF-8. If the
  * given range is not entirely contained in the string, returns
  * #FALSE. If the string contains any nul bytes in the given range,
diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h
index 5a62bdd..cfb6f16 100644
--- a/dbus/dbus-string.h
+++ b/dbus/dbus-string.h
@@ -291,6 +291,9 @@ dbus_bool_t   _dbus_string_hex_decode            (const DBusString  *source,
 void          _dbus_string_tolower_ascii         (const DBusString  *str,
                                                   int                start,
                                                   int                len);
+void          _dbus_string_toupper_ascii         (const DBusString  *str,
+                                                  int                start,
+                                                  int                len);
 dbus_bool_t   _dbus_string_validate_ascii        (const DBusString  *str,
                                                   int                start,
                                                   int                len);
-- 
1.5.6.5


--------------040209020107000402010308--


More information about the dbus mailing list