Commit f2e17db6 authored by Ralf Habacker's avatar Ralf Habacker

* dbus/dbus-string.c (_dbus_string_pop_line),

	bus/desktop-file.c (parse_section_start,
	parse_comment_or_blank,parse_key_value,): uses
	_dbus_string_find_eol() to support platform independent eol style.
parent ea18bc0d
......@@ -360,15 +360,15 @@ is_blank_line (BusDesktopFileParser *parser)
static void
parse_comment_or_blank (BusDesktopFileParser *parser)
{
int line_end;
int line_end, eol_len;
if (!_dbus_string_find (&parser->data, parser->pos, "\n", &line_end))
if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len))
line_end = parser->len;
if (line_end == parser->len)
parser->pos = parser->len;
else
parser->pos = line_end + 1;
parser->pos = line_end + eol_len;
parser->line_num += 1;
}
......@@ -393,12 +393,12 @@ is_valid_section_name (const char *name)
static dbus_bool_t
parse_section_start (BusDesktopFileParser *parser, DBusError *error)
{
int line_end;
int line_end, eol_len;
char *section_name;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (!_dbus_string_find (&parser->data, parser->pos, "\n", &line_end))
if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len))
line_end = parser->len;
if (line_end - parser->pos <= 2 ||
......@@ -438,7 +438,7 @@ parse_section_start (BusDesktopFileParser *parser, DBusError *error)
if (line_end == parser->len)
parser->pos = parser->len;
else
parser->pos = line_end + 1;
parser->pos = line_end + eol_len;
parser->line_num += 1;
......@@ -450,7 +450,7 @@ parse_section_start (BusDesktopFileParser *parser, DBusError *error)
static dbus_bool_t
parse_key_value (BusDesktopFileParser *parser, DBusError *error)
{
int line_end;
int line_end, eol_len;
int key_start, key_end;
int value_start;
int p;
......@@ -460,7 +460,7 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error)
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (!_dbus_string_find (&parser->data, parser->pos, "\n", &line_end))
if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len))
line_end = parser->len;
p = parser->pos;
......@@ -483,7 +483,7 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error)
if (line_end == parser->len)
parser->pos = parser->len;
else
parser->pos = line_end + 1;
parser->pos = line_end + eol_len;
parser->line_num += 1;
......@@ -568,7 +568,7 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error)
if (line_end == parser->len)
parser->pos = parser->len;
else
parser->pos = line_end + 1;
parser->pos = line_end + eol_len;
parser->line_num += 1;
......
......@@ -2088,52 +2088,22 @@ dbus_bool_t
_dbus_string_pop_line (DBusString *source,
DBusString *dest)
{
int eol;
dbus_bool_t have_newline;
int eol, eol_len;
_dbus_string_set_length (dest, 0);
eol = 0;
if (_dbus_string_find (source, 0, "\n", &eol))
{
have_newline = TRUE;
eol += 1; /* include newline */
}
else
{
if (!_dbus_string_find_eol (source, 0, &eol, &eol_len))
eol = _dbus_string_get_length (source);
have_newline = FALSE;
}
if (eol == 0)
return FALSE; /* eof */
if (!_dbus_string_move_len (source, 0, eol,
dest, 0))
{
return FALSE;
}
if (!_dbus_string_move_len (source, 0, eol + eol_len, dest, 0))
return FALSE;
/* dump the newline and the \r if we have one */
if (have_newline)
{
dbus_bool_t have_cr;
_dbus_assert (_dbus_string_get_length (dest) > 0);
if (_dbus_string_get_length (dest) > 1 &&
_dbus_string_get_byte (dest,
_dbus_string_get_length (dest) - 2) == '\r')
have_cr = TRUE;
else
have_cr = FALSE;
_dbus_string_set_length (dest,
_dbus_string_get_length (dest) -
(have_cr ? 2 : 1));
}
return TRUE;
/* remove line ending */
return _dbus_string_set_length(dest, eol);
}
#ifdef DBUS_BUILD_TESTS
......
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