summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-string.c
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2006-12-12 23:46:27 +0000
committerRalf Habacker <ralf.habacker@freenet.de>2006-12-12 23:46:27 +0000
commitcb39e60e1639fb982a46aa1625e3adec2bf0df46 (patch)
treee6fc06cf77553206c45b06953fa8088560066694 /dbus/dbus-string.c
parent60bf9558682754eee076b79bacf0a9815c60b94b (diff)
* dbus/dbus-string.[ch] (_dbus_string_find_eol): new function.
* dbus/dbus-string-util.c (_dbus_string_test): added testcases for _dbus_string_find_eol(). Approved by: Havoc Pennington.
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r--dbus/dbus-string.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index a218ed5d..5ae8ac3f 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -2,6 +2,7 @@
/* dbus-string.c String utility class (internal to D-Bus implementation)
*
* Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
+ * Copyright (C) 2006 Ralf Habacker <ralf.habacker@freenet.de>
*
* Licensed under the Academic Free License version 2.1
*
@@ -1790,6 +1791,72 @@ _dbus_string_find (const DBusString *str,
}
/**
+ * Finds end of line ("\r\n" or "\n") in the string,
+ * returning #TRUE and filling in the byte index
+ * where the eol string was found, if it was found.
+ * Returns #FALSE if eol wasn't found.
+ *
+ * @param str the string
+ * @param start where to start looking
+ * @param found return location for where eol was found or string length otherwise
+ * @param found_len return length of found eol string or zero otherwise
+ * @returns #TRUE if found
+ */
+dbus_bool_t
+_dbus_string_find_eol (const DBusString *str,
+ int start,
+ int *found,
+ int *found_len)
+{
+ int i;
+
+ DBUS_CONST_STRING_PREAMBLE (str);
+ _dbus_assert (start <= real->len);
+ _dbus_assert (start >= 0);
+
+ i = start;
+ while (i < real->len)
+ {
+ if (real->str[i] == '\r')
+ {
+ if ((i+1) < real->len && real->str[i+1] == '\n') /* "\r\n" */
+ {
+ if (found)
+ *found = i;
+ if (found_len)
+ *found_len = 2;
+ return TRUE;
+ }
+ else /* only "\r" */
+ {
+ if (found)
+ *found = i;
+ if (found_len)
+ *found_len = 1;
+ return TRUE;
+ }
+ }
+ else if (real->str[i] == '\n') /* only "\n" */
+ {
+ if (found)
+ *found = i;
+ if (found_len)
+ *found_len = 1;
+ return TRUE;
+ }
+ ++i;
+ }
+
+ if (found)
+ *found = real->len;
+
+ if (found_len)
+ *found_len = 0;
+
+ return FALSE;
+}
+
+/**
* Finds the given substring in the string,
* up to a certain position,
* returning #TRUE and filling in the byte index