[PATCH] _dbus_string_tolower_ascii(): new function
Ralf Habacker
ralf.habacker at freenet.de
Sat Feb 27 00:11:32 PST 2010
---
dbus/dbus-1-symbols.def.in | 1 +
dbus/dbus-string-util.c | 34 +++++++++++++++++++++++++++++++++-
dbus/dbus-string.c | 36 ++++++++++++++++++++++++++++++++++++
dbus/dbus-string.h | 3 +++
4 files changed, 73 insertions(+), 1 deletions(-)
diff --git a/dbus/dbus-1-symbols.def.in b/dbus/dbus-1-symbols.def.in
index febfd42..e943357 100644
--- a/dbus/dbus-1-symbols.def.in
+++ b/dbus/dbus-1-symbols.def.in
@@ -387,6 +387,7 @@ _dbus_string_skip_white
_dbus_string_skip_white_reverse
_dbus_string_split_on_byte
_dbus_string_steal_data
+_dbus_string_tolower_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 a3e5213..9ca5d6c 100644
--- a/dbus/dbus-string-util.c
+++ b/dbus/dbus-string-util.c
@@ -871,7 +871,39 @@ _dbus_string_test (void)
_dbus_string_free (&str);
_dbus_string_free (&other);
}
-
+
+ {
+ const char upper_string[] = "TOUPPERSTRING";
+ const char lower_string[] = "toupperstring";
+ const char lower2_string[] = "toupperSTRING";
+
+ if (!_dbus_string_init (&str))
+ _dbus_assert_not_reached ("no memory");
+
+ if (!_dbus_string_append (&str, upper_string))
+ _dbus_assert_not_reached ("no memory");
+
+ _dbus_string_tolower_ascii (&str, 0, _dbus_string_get_length(&str));
+
+ if (!_dbus_string_equal_c_str (&str, lower_string))
+ _dbus_assert_not_reached ("_dbus_string_tolower_ascii failed");
+
+ _dbus_string_free (&str);
+
+ if (!_dbus_string_init (&str))
+ _dbus_assert_not_reached ("no memory");
+
+ if (!_dbus_string_append (&str, upper_string))
+ _dbus_assert_not_reached ("no memory");
+
+ _dbus_string_tolower_ascii (&str, 0, 7);
+
+ if (!_dbus_string_equal_c_str (&str, lower2_string))
+ _dbus_assert_not_reached ("_dbus_string_tolower_ascii failed in partial conversion");
+
+ _dbus_string_free (&str);
+ }
+
return TRUE;
}
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 62a6460..a8060c6 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -2760,6 +2762,40 @@ _dbus_string_validate_ascii (const DBusString *str,
}
/**
+ * 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 always
+ */
+dbus_bool_t
+_dbus_string_tolower_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;
+ }
+
+ 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
* #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 7c30111..8d6e530 100644
--- a/dbus/dbus-string.h
+++ b/dbus/dbus-string.h
@@ -284,6 +284,9 @@ dbus_bool_t _dbus_string_hex_decode (const DBusString *source,
int *end_return,
DBusString *dest,
int insert_at);
+dbus_bool_t _dbus_string_tolower_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
--------------080203000506080801000800--
More information about the dbus
mailing list