From 0e3ec9cec0f6740acd39d6e6983f419e20461282 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Fri, 11 Jul 2008 11:32:30 -0400 Subject: Add new function _dbus_string_split_on_byte It allows you to turn a string like KEY=VALUE into two strings key and value. --- dbus/dbus-string-util.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'dbus/dbus-string-util.c') diff --git a/dbus/dbus-string-util.c b/dbus/dbus-string-util.c index 492c5289..aed94878 100644 --- a/dbus/dbus-string-util.c +++ b/dbus/dbus-string-util.c @@ -846,6 +846,31 @@ _dbus_string_test (void) _dbus_string_free (&str); } + + { + const char two_strings[] = "one\ttwo"; + + if (!_dbus_string_init (&str)) + _dbus_assert_not_reached ("no memory"); + + if (!_dbus_string_init (&other)) + _dbus_assert_not_reached ("no memory"); + + if (!_dbus_string_append (&str, two_strings)) + _dbus_assert_not_reached ("no memory"); + + if (!_dbus_string_split_on_byte (&str, '\t', &other)) + _dbus_assert_not_reached ("no memory or delimiter not found"); + + if (strcmp (_dbus_string_get_data (&str), "one") != 0) + _dbus_assert_not_reached ("left side after split on tab is wrong"); + + if (strcmp (_dbus_string_get_data (&other), "two") != 0) + _dbus_assert_not_reached ("right side after split on tab is wrong"); + + _dbus_string_free (&str); + _dbus_string_free (&other); + } return TRUE; } -- cgit