Commit b69119c1 authored by Simon McVittie's avatar Simon McVittie

_dbus_string_append_double, _dbus_string_parse_double: remove

They're unused, except by their own regression tests.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39759Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Lennart Poettering's avatarLennart Poettering <lennart@poettering.net>
parent 7a33565d
......@@ -229,7 +229,6 @@ _dbus_string_test (void)
DBusString other;
int i, a, end;
long v;
double d;
int lens[] = { 0, 1, 2, 3, 4, 5, 10, 16, 17, 18, 25, 31, 32, 33, 34, 35, 63, 64, 65, 66, 67, 68, 69, 70, 71, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136 };
char *s;
......@@ -601,22 +600,6 @@ _dbus_string_test (void)
_dbus_assert (v == 27);
_dbus_assert (end == i);
_dbus_string_free (&str);
if (!_dbus_string_init (&str))
_dbus_assert_not_reached ("failed to init string");
if (!_dbus_string_append_double (&str, 50.3))
_dbus_assert_not_reached ("failed to append float");
i = _dbus_string_get_length (&str);
if (!_dbus_string_parse_double (&str, 0, &d, &end))
_dbus_assert_not_reached ("failed to parse float");
_dbus_assert (d > (50.3 - 1e-6) && d < (50.3 + 1e-6));
_dbus_assert (end == i);
_dbus_string_free (&str);
/* Test find */
......
......@@ -150,8 +150,6 @@ dbus_bool_t _dbus_string_append_int (DBusString *str,
long value);
dbus_bool_t _dbus_string_append_uint (DBusString *str,
unsigned long value);
dbus_bool_t _dbus_string_append_double (DBusString *str,
double value);
dbus_bool_t _dbus_string_append_byte (DBusString *str,
unsigned char byte);
dbus_bool_t _dbus_string_append_printf (DBusString *str,
......@@ -210,10 +208,6 @@ dbus_bool_t _dbus_string_parse_uint (const DBusString *str,
int start,
unsigned long *value_return,
int *end_return);
dbus_bool_t _dbus_string_parse_double (const DBusString *str,
int start,
double *value,
int *end_return);
dbus_bool_t _dbus_string_find (const DBusString *str,
int start,
const char *substr,
......
......@@ -131,10 +131,6 @@ check_path_absolute (const char *path,
dbus_bool_t
_dbus_sysdeps_test (void)
{
DBusString str;
double val;
int pos;
#ifdef DBUS_WIN
check_dirname ("foo\\bar", "foo");
check_dirname ("foo\\\\bar", "foo");
......@@ -176,32 +172,6 @@ _dbus_sysdeps_test (void)
check_dirname ("", ".");
#endif
_dbus_string_init_const (&str, "3.5");
if (!_dbus_string_parse_double (&str,
0, &val, &pos))
{
_dbus_warn ("Failed to parse double");
exit (1);
}
if (ABS(3.5 - val) > 1e-6)
{
_dbus_warn ("Failed to parse 3.5 correctly, got: %f", val);
exit (1);
}
if (pos != 3)
{
_dbus_warn ("_dbus_string_parse_double of \"3.5\" returned wrong position %d", pos);
exit (1);
}
_dbus_string_init_const (&str, "0xff");
if (_dbus_string_parse_double (&str,
0, &val, &pos))
{
_dbus_warn ("Should not have parsed hex as double\n");
exit (1);
}
#ifdef DBUS_WIN
check_path_absolute ("c:/", TRUE);
check_path_absolute ("c:/foo", TRUE);
......
......@@ -412,45 +412,6 @@ _dbus_string_append_uint (DBusString *str,
return TRUE;
}
#ifdef DBUS_BUILD_TESTS
/**
* Appends a double to a DBusString.
*
* @param str the string
* @param value the floating point value
* @returns #FALSE if not enough memory or other failure.
*/
dbus_bool_t
_dbus_string_append_double (DBusString *str,
double value)
{
#define MAX_DOUBLE_LEN 64 /* this is completely made up :-/ */
int orig_len;
char *buf;
int i;
orig_len = _dbus_string_get_length (str);
if (!_dbus_string_lengthen (str, MAX_DOUBLE_LEN))
return FALSE;
buf = _dbus_string_get_data_len (str, orig_len, MAX_DOUBLE_LEN);
snprintf (buf, MAX_LONG_LEN, "%g", value);
i = 0;
while (*buf)
{
++buf;
++i;
}
_dbus_string_shorten (str, MAX_DOUBLE_LEN - i);
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Parses an integer contained in a DBusString. Either return parameter
* may be #NULL if you aren't interested in it. The integer is parsed
......@@ -529,223 +490,6 @@ _dbus_string_parse_uint (const DBusString *str,
return TRUE;
}
#ifdef DBUS_BUILD_TESTS
static dbus_bool_t
ascii_isspace (char c)
{
return (c == ' ' ||
c == '\f' ||
c == '\n' ||
c == '\r' ||
c == '\t' ||
c == '\v');
}
#endif /* DBUS_BUILD_TESTS */
#ifdef DBUS_BUILD_TESTS
static dbus_bool_t
ascii_isdigit (char c)
{
return c >= '0' && c <= '9';
}
#endif /* DBUS_BUILD_TESTS */
#ifdef DBUS_BUILD_TESTS
static dbus_bool_t
ascii_isxdigit (char c)
{
return (ascii_isdigit (c) ||
(c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F'));
}
#endif /* DBUS_BUILD_TESTS */
#ifdef DBUS_BUILD_TESTS
/* Calls strtod in a locale-independent fashion, by looking at
* the locale data and patching the decimal comma to a point.
*
* Relicensed from glib.
*/
static double
ascii_strtod (const char *nptr,
char **endptr)
{
/* FIXME: The Win32 C library's strtod() doesn't handle hex.
* Presumably many Unixes don't either.
*/
char *fail_pos;
double val;
struct lconv *locale_data;
const char *decimal_point;
int decimal_point_len;
const char *p, *decimal_point_pos;
const char *end = NULL; /* Silence gcc */
fail_pos = NULL;
#if HAVE_LOCALECONV
locale_data = localeconv ();
decimal_point = locale_data->decimal_point;
#else
decimal_point = ".";
#endif
decimal_point_len = strlen (decimal_point);
_dbus_assert (decimal_point_len != 0);
decimal_point_pos = NULL;
if (decimal_point[0] != '.' ||
decimal_point[1] != 0)
{
p = nptr;
/* Skip leading space */
while (ascii_isspace (*p))
p++;
/* Skip leading optional sign */
if (*p == '+' || *p == '-')
p++;
if (p[0] == '0' &&
(p[1] == 'x' || p[1] == 'X'))
{
p += 2;
/* HEX - find the (optional) decimal point */
while (ascii_isxdigit (*p))
p++;
if (*p == '.')
{
decimal_point_pos = p++;
while (ascii_isxdigit (*p))
p++;
if (*p == 'p' || *p == 'P')
p++;
if (*p == '+' || *p == '-')
p++;
while (ascii_isdigit (*p))
p++;
end = p;
}
}
else
{
while (ascii_isdigit (*p))
p++;
if (*p == '.')
{
decimal_point_pos = p++;
while (ascii_isdigit (*p))
p++;
if (*p == 'e' || *p == 'E')
p++;
if (*p == '+' || *p == '-')
p++;
while (ascii_isdigit (*p))
p++;
end = p;
}
}
/* For the other cases, we need not convert the decimal point */
}
/* Set errno to zero, so that we can distinguish zero results
and underflows */
_dbus_set_errno_to_zero ();
if (decimal_point_pos)
{
char *copy, *c;
/* We need to convert the '.' to the locale specific decimal point */
copy = dbus_malloc (end - nptr + 1 + decimal_point_len);
c = copy;
memcpy (c, nptr, decimal_point_pos - nptr);
c += decimal_point_pos - nptr;
memcpy (c, decimal_point, decimal_point_len);
c += decimal_point_len;
memcpy (c, decimal_point_pos + 1, end - (decimal_point_pos + 1));
c += end - (decimal_point_pos + 1);
*c = 0;
val = strtod (copy, &fail_pos);
if (fail_pos)
{
if (fail_pos > decimal_point_pos)
fail_pos = (char *)nptr + (fail_pos - copy) - (decimal_point_len - 1);
else
fail_pos = (char *)nptr + (fail_pos - copy);
}
dbus_free (copy);
}
else
val = strtod (nptr, &fail_pos);
if (endptr)
*endptr = fail_pos;
return val;
}
#endif /* DBUS_BUILD_TESTS */
#ifdef DBUS_BUILD_TESTS
/**
* Parses a floating point number contained in a DBusString. Either
* return parameter may be #NULL if you aren't interested in it. The
* integer is parsed and stored in value_return. Return parameters are
* not initialized if the function returns #FALSE.
*
* @param str the string
* @param start the byte index of the start of the float
* @param value_return return location of the float value or #NULL
* @param end_return return location of the end of the float, or #NULL
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_string_parse_double (const DBusString *str,
int start,
double *value_return,
int *end_return)
{
double v;
const char *p;
char *end;
p = _dbus_string_get_const_data_len (str, start,
_dbus_string_get_length (str) - start);
/* parsing hex works on linux but isn't portable, so intercept it
* here to get uniform behavior.
*/
if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X'))
return FALSE;
end = NULL;
_dbus_set_errno_to_zero ();
v = ascii_strtod (p, &end);
if (end == NULL || end == p || errno != 0)
return FALSE;
if (value_return)
*value_return = v;
if (end_return)
*end_return = start + (end - p);
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
/** @} */ /* DBusString group */
/**
......
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