From 03800cc0500eda075cfe1f21d50ec98ea1b271b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Tue, 11 Nov 2008 14:41:08 +0000 Subject: [PATCH] [INTERPRETER] * NEW: Format() now pad numbers with spaces according to the number of '#' characters before the decimal point. git-svn-id: svn://localhost/gambas/trunk@1696 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_local.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/main/gbx/gbx_local.c b/main/gbx/gbx_local.c index b3a79d1e1..bda7d029f 100644 --- a/main/gbx/gbx_local.c +++ b/main/gbx/gbx_local.c @@ -203,17 +203,22 @@ static void add_currency(const char *sym) } -static void add_zero(int zero, int *before) +static void add_char(char c, int count, int *before) { - while (zero > 0) + while (count > 0) { - put_char('0'); - zero--; + put_char(c); + count--; add_thousand_sep(before); } } +static void add_zero(int count, int *before) +{ + add_char('0', count, before); +} + static int search(const char *src, int len, const char *list, int start, boolean not) { @@ -936,13 +941,13 @@ _FORMAT: /* les chiffres avant la virgule */ - thousand = Max(before_zero, number_exp); + thousand = Max(before, Max(before_zero, number_exp)); thousand_ptr = comma ? &thousand : NULL; if (number_exp > 0) { - if (before_zero > number_exp) - add_zero(before_zero - number_exp, thousand_ptr); + add_char(' ', before - Max(before_zero, number_exp), thousand_ptr); + add_zero(before_zero - number_exp, thousand_ptr); add_string(buf_start, Min(number_exp, ndigit), thousand_ptr); @@ -951,8 +956,8 @@ _FORMAT: } else { - if (before_zero > 0) - add_zero(before_zero, thousand_ptr); + add_char(' ', before - before_zero, thousand_ptr); + add_zero(before_zero, thousand_ptr); } /* la virgule */