From c9049f94d77b1fe100b53848b545e5b1e61d7df3 Mon Sep 17 00:00:00 2001 From: hniksic Date: Sun, 26 Jun 2005 15:18:01 -0700 Subject: [PATCH] [svn] Handle negative numbers in with_thousand_seps. --- src/ChangeLog | 4 ++++ src/utils.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0a5ed0ac..9fca8864 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2005-06-27 Hrvoje Niksic + + * utils.c (with_thousand_seps): Handle negative numbers. + 2005-06-26 Hrvoje Niksic * progress.c (create_image): Mark the "eta" string for translation. diff --git a/src/utils.c b/src/utils.c index 64612006..96d4767c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1192,7 +1192,6 @@ get_grouping_data (const char **sep, const char **grouping) *grouping = cached_grouping; } - /* Return a printed representation of N with thousand separators. This should respect locale settings, with the exception of the "C" locale which mandates no separator, but we use one anyway. @@ -1216,12 +1215,19 @@ with_thousand_seps (wgint n) int i = 0, groupsize; const char *atgroup; + bool negative = n < 0; + /* Initialize grouping data. */ get_grouping_data (&sep, &grouping); seplen = strlen (sep); atgroup = grouping; groupsize = *atgroup++; + /* This will overflow on WGINT_MIN, but we're not using this to + print negative numbers anyway. */ + if (negative) + n = -n; + /* Write the number into the buffer, backwards, inserting the separators as necessary. */ *--p = '\0'; @@ -1243,6 +1249,9 @@ with_thousand_seps (wgint n) groupsize = *atgroup++; } } + if (negative) + *--p = '-'; + return p; }