Commit 47e37899 authored by Ralf Habacker's avatar Ralf Habacker

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

parent b88edf22
......@@ -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
......
......@@ -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;
}
......
......@@ -2790,6 +2790,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
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment