dbus/dbus dbus-string.c, 1.75, 1.76 dbus-string.h, 1.41,
1.42 dbus-string-util.c, 1.4, 1.5
Ralf Habacker
rhabacker at kemper.freedesktop.org
Tue Dec 12 15:46:29 PST 2006
Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv30017/dbus
Modified Files:
dbus-string.c dbus-string.h dbus-string-util.c
Log Message:
* 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.
Index: dbus-string.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- dbus-string.c 21 Oct 2006 18:17:02 -0000 1.75
+++ dbus-string.c 12 Dec 2006 23:46:27 -0000 1.76
@@ -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 at freenet.de>
*
* Licensed under the Academic Free License version 2.1
*
@@ -1790,6 +1791,72 @@
}
/**
+ * 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
Index: dbus-string.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- dbus-string.h 1 Oct 2006 03:18:47 -0000 1.41
+++ dbus-string.h 12 Dec 2006 23:46:27 -0000 1.42
@@ -2,6 +2,7 @@
/* dbus-string.h String utility class (internal to D-Bus implementation)
*
* Copyright (C) 2002, 2003 Red Hat, Inc.
+ * Copyright (C) 2006 Ralf Habacker <ralf.habacker at freenet.de>
*
* Licensed under the Academic Free License version 2.1
*
@@ -215,6 +216,10 @@
int start,
const char *substr,
int *found);
+dbus_bool_t _dbus_string_find_eol (const DBusString *str,
+ int start,
+ int *found,
+ int *found_len);
dbus_bool_t _dbus_string_find_to (const DBusString *str,
int start,
int end,
Index: dbus-string-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string-util.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dbus-string-util.c 1 Oct 2006 03:18:47 -0000 1.4
+++ dbus-string-util.c 12 Dec 2006 23:46:27 -0000 1.5
@@ -2,6 +2,7 @@
/* dbus-string-util.c Would be in dbus-string.c, but not used in libdbus
*
* Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
+ * Copyright (C) 2006 Ralf Habacker <ralf.habacker at freenet.de>
*
* Licensed under the Academic Free License version 2.1
*
@@ -702,8 +703,45 @@
test_roundtrips (test_hex_roundtrip);
_dbus_string_free (&str);
+
+ {
+ int found,found_len;
+ _dbus_string_init_const (&str, "012\r\n567\n90");
+
+ if (!_dbus_string_find_eol(&str, 0, &found, &found_len) || found != 3 || found_len != 2)
+ _dbus_assert_not_reached ("Did not find '\\r\\n'");
+ if (found != 3 || found_len != 2)
+ _dbus_assert_not_reached ("invalid return values");
+
+ if (!_dbus_string_find_eol(&str, 5, &found, &found_len))
+ _dbus_assert_not_reached ("Did not find '\\n'");
+ if (found != 8 || found_len != 1)
+ _dbus_assert_not_reached ("invalid return values");
+
+ if (_dbus_string_find_eol(&str, 9, &found, &found_len))
+ _dbus_assert_not_reached ("Found not expected '\\n'");
+ else if (found != 11 || found_len != 0)
+ _dbus_assert_not_reached ("invalid return values '\\n'");
+
+ _dbus_string_free (&str);
+ }
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
More information about the dbus-commit
mailing list