summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-string.c
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@codefactory.se>2003-01-30 20:49:11 +0000
committerAnders Carlsson <andersca@codefactory.se>2003-01-30 20:49:11 +0000
commit5ebb5748c2a7587c734eeed9c66f2a1fc0635d09 (patch)
treeafd7ab44b132db9424f4ce464f4029751521ebab /dbus/dbus-string.c
parent7ba714ad7fe8256edfaad7d9a0f09aeb9611ca44 (diff)
2003-01-30 Anders Carlsson <andersca@codefactory.se>
* dbus/Makefile.am: Add dbus-address.[ch] * dbus/dbus-address.c: (dbus_address_entry_free), (dbus_address_entries_free), (create_entry), (dbus_address_entry_get_method), (dbus_address_entry_get_value), (dbus_parse_address), (_dbus_address_test): * dbus/dbus-address.h: New files for dealing with address parsing. * dbus/dbus-connection.c: Document timeout functions. * dbus/dbus-message.c: Document dbus_message_new_from_message. * dbus/dbus-server-debug.c: Document. * dbus/dbus-server.c: (dbus_server_listen): Parse address and use correct server implementation. * dbus/dbus-string.c: (_dbus_string_find_to), (_dbus_string_test): * dbus/dbus-string.h: New function with test. * dbus/dbus-test.c: (dbus_internal_symbol_do_not_use_run_tests): * dbus/dbus-test.h: Add address tests. * dbus/dbus-transport-debug.c: Document. * dbus/dbus-transport.c: (_dbus_transport_open): Parse address and use correct transport implementation.
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r--dbus/dbus-string.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index f453dcb6..05d14ba1 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -1222,6 +1222,78 @@ _dbus_string_find (const DBusString *str,
}
/**
+ * Finds the given substring in the string,
+ * up to a certain position,
+ * returning #TRUE and filling in the byte index
+ * where the substring was found, if it was found.
+ * Returns #FALSE if the substring wasn't found.
+ * Sets *start to the length of the string if the substring
+ * is not found.
+ *
+ * @param str the string
+ * @param start where to start looking
+ * @param end where to stop looking
+ * @param substr the substring
+ * @param found return location for where it was found, or #NULL
+ * @returns #TRUE if found
+ */
+dbus_bool_t
+_dbus_string_find_to (const DBusString *str,
+ int start,
+ int end,
+ const char *substr,
+ int *found)
+{
+ int i;
+ DBUS_CONST_STRING_PREAMBLE (str);
+ _dbus_assert (substr != NULL);
+ _dbus_assert (start <= real->len);
+ _dbus_assert (end <= real->len);
+ _dbus_assert (start < end);
+
+ /* we always "find" an empty string */
+ if (*substr == '\0')
+ {
+ if (found)
+ *found = 0;
+ return TRUE;
+ }
+
+ i = start;
+ while (i < real->len && i < end)
+ {
+ if (real->str[i] == substr[0])
+ {
+ int j = i + 1;
+
+ while (j < real->len && j < end)
+ {
+ if (substr[j - i] == '\0')
+ break;
+ else if (real->str[j] != substr[j - i])
+ break;
+
+ ++j;
+ }
+
+ if (substr[j - i] == '\0')
+ {
+ if (found)
+ *found = i;
+ return TRUE;
+ }
+ }
+
+ ++i;
+ }
+
+ if (found)
+ *found = end;
+
+ return FALSE;
+}
+
+/**
* Finds a blank (space or tab) in the string. Returns #TRUE
* if found, #FALSE otherwise. If a blank is not found sets
* *found to the length of the string.
@@ -2294,6 +2366,12 @@ _dbus_string_test (void)
if (_dbus_string_find (&str, 0, "q", NULL))
_dbus_assert_not_reached ("Did find 'q'");
+
+ if (!_dbus_string_find_to (&str, 0, 2, "He", NULL))
+ _dbus_assert_not_reached ("Didn't find 'He'");
+
+ if (_dbus_string_find_to (&str, 0, 2, "Hello", NULL))
+ _dbus_assert_not_reached ("Did find 'Hello'");
_dbus_string_free (&str);