From c3d19b850f631fcdcaf70b6e6bb33a0ea46771a1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 5 Jun 2006 14:16:47 +0000 Subject: [PATCH] Add some tests involving leading whitespace. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-06-05 Matthias Clasen * tests/strtod-test.c: Add some tests involving leading whitespace. * glib/gstrfuncs.c (g_ascii_formatd): Skip leading whitespace. (#343899, Øystein Johansen) --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-12 | 8 ++++++++ glib/gstrfuncs.c | 12 +++++++++++- tests/strtod-test.c | 36 ++++++++++++++++++++++++++++++++++-- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 00d589f80..9f7f1497a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-06-05 Matthias Clasen + + * tests/strtod-test.c: Add some tests involving + leading whitespace. + + * glib/gstrfuncs.c (g_ascii_formatd): Skip leading + whitespace. (#343899, Øystein Johansen) + 2006-06-01 Matthias Clasen * glib/gmain.h: diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 00d589f80..9f7f1497a 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2006-06-05 Matthias Clasen + + * tests/strtod-test.c: Add some tests involving + leading whitespace. + + * glib/gstrfuncs.c (g_ascii_formatd): Skip leading + whitespace. (#343899, Øystein Johansen) + 2006-06-01 Matthias Clasen * glib/gmain.h: diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 260853ab4..1150c46bc 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -30,6 +30,7 @@ #include "config.h" +#define __G_STRFUNCS_C__ #define _GNU_SOURCE /* For stpcpy */ #include @@ -94,6 +95,7 @@ g_strdup (const gchar *str) else new_str = NULL; + g_mem_mark_type (new_str, G_MEM_TYPE_STRING, 0); return new_str; } @@ -129,6 +131,7 @@ g_strndup (const gchar *str, else new_str = NULL; + g_mem_mark_type (new_str, G_MEM_TYPE_STRING, 0); return new_str; } @@ -187,6 +190,7 @@ g_strdup_vprintf (const gchar *format, g_vasprintf (&string, format, args); + g_mem_mark_type (string, G_MEM_TYPE_STRING, 0); return string; } @@ -355,6 +359,7 @@ g_ascii_strtod (const gchar *nptr, decimal_point[1] != 0) { p = nptr; + /* Skip leading space */ while (g_ascii_isspace (*p)) p++; @@ -568,6 +573,9 @@ g_ascii_formatd (gchar *buffer, { p = buffer; + while (g_ascii_isspace (*p)) + p++; + if (*p == '+' || *p == '-') p++; @@ -1582,7 +1590,8 @@ g_ascii_strdown (const gchar *str, result = g_strndup (str, len); for (s = result; *s; s++) *s = g_ascii_tolower (*s); - + + g_mem_mark_type (result, G_MEM_TYPE_STRING, 0); return result; } @@ -1614,6 +1623,7 @@ g_ascii_strup (const gchar *str, for (s = result; *s; s++) *s = g_ascii_toupper (*s); + g_mem_mark_type (result, G_MEM_TYPE_STRING, 0); return result; } diff --git a/tests/strtod-test.c b/tests/strtod-test.c index a5a4a2376..8da7f377b 100644 --- a/tests/strtod-test.c +++ b/tests/strtod-test.c @@ -10,11 +10,12 @@ #include #include +static char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"}; + void test_string (char *number, double res, gboolean check_end, int correct_len) { double d; - char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"}; int l; char *dummy; @@ -59,6 +60,19 @@ test_string (char *number, double res, gboolean check_end, int correct_len) } +static void +test_number (gdouble num, gchar *fmt, gchar *str) +{ + int l; + gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; + + for (l = 0; l < G_N_ELEMENTS (locales); l++) + { + g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num); + g_assert (strcmp (buf, str) == 0); + } +} + int main () { @@ -108,7 +122,25 @@ main () d = -pow (2.0, -1024.1); g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL)); - + /* for #343899 */ + test_string (" 0.75", 0.75, FALSE, 0); + test_string (" +0.75", 0.75, FALSE, 0); + test_string (" -0.75", -0.75, FALSE, 0); + test_string ("\f0.75", 0.75, FALSE, 0); + test_string ("\n0.75", 0.75, FALSE, 0); + test_string ("\r0.75", 0.75, FALSE, 0); + test_string ("\t0.75", 0.75, FALSE, 0); +#if 0 + /* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */ + test_string ("\v0.75", 0.75, FALSE, 0); +#endif + + /* for #343899 */ + test_number (0.75, "%0.2f", "0.75"); + test_number (0.75, "%5.2f", " 0.75"); + test_number (-0.75, "%0.2f", "-0.75"); + test_number (-0.75, "%5.2f", "-0.75"); + test_number (1e99, "%.0e", "1e+99"); return 0; } -- 2.34.1