[goffice] GOFormat: improve quoting of currencies.



commit c4f995a883ddf8d503c3204ff7bb1b7789420805
Author: Morten Welinder <terra gnome org>
Date:   Thu May 28 15:54:18 2009 -0400

    GOFormat: improve quoting of currencies.
---
 ChangeLog                 |    5 +++++
 goffice/utils/formats.c   |   24 +++++++++++++-----------
 goffice/utils/go-format.c |   23 +++++++++++++++++++++--
 3 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3c65993..1d37aba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,13 @@
 2009-05-28  Morten Welinder  <terra gnome org>
 
+	* goffice/utils/go-format.c (go_format_generate_accounting_str):
+	Improve quoting.
+
 	* goffice/utils/formats.c (go_currency_date_format_init): Simplify
 	using go_format_locale_currency, go_format_generate_currency_str,
 	and go_format_generate_accounting_str.
+	(go_currency_date_format_init): Generate all members of
+	fmts_accounting.
 
 	* goffice/utils/go-format.c (go_format_locale_currency): New
 	function.
diff --git a/goffice/utils/formats.c b/goffice/utils/formats.c
index 13f89c3..197506c 100644
--- a/goffice/utils/formats.c
+++ b/goffice/utils/formats.c
@@ -53,9 +53,9 @@ fmts_currency [] = {
 static char const *
 fmts_accounting [] = {
 	NULL, /* "_($* #,##0_);_($* (#,##0);_($* \"-\"_);_(@_)", */
-	"_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)",
+	NULL, /* "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)", */
 	NULL, /* "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)", */
-	"_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)",
+	NULL, /* "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)", */
 	NULL
 };
 
@@ -213,11 +213,12 @@ go_currency_date_format_init (void)
 		fmts_currency[i] = g_string_free (str, FALSE);
 	}
 
-	for (i = 0; i < 4; i += 2) {
+	for (i = 0; i < 4; i++) {
 		int num_decimals = (i >= 2) ? 2 : 0;
+		gboolean no_currency = (i & 1);
 		GString *str = g_string_new (NULL);
-		go_format_generate_accounting_str (str, num_decimals,
-						   currency);
+		go_format_generate_accounting_str
+			(str, num_decimals, no_currency ? NULL : currency);
 		fmts_accounting[i] = g_string_free (str, FALSE);
 	}
 
@@ -321,13 +322,14 @@ go_currency_date_format_shutdown (void)
 	int i;
 
 	for (i = 0; i < 6; i++) {
-		g_free ((char *)(fmts_currency [i]));
-		fmts_currency [i] = NULL;
+		g_free ((char *)(fmts_currency[i]));
+		fmts_currency[i] = NULL;
+	}
+
+	for (i = 0; i < 4; i++) {
+		g_free ((char *)(fmts_accounting[i]));
+		fmts_accounting[i] = NULL;
 	}
-	g_free ((char *)(fmts_accounting[0]));
-	fmts_accounting [0] = NULL;
-	g_free ((char *)(fmts_accounting[2]));
-	fmts_accounting[2] = NULL;
 
 	for (i = 0; fmts_date[i]; i++) {
 		g_free ((char*)(fmts_date[i]));
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 2c84b36..d67e61b 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -354,6 +354,11 @@ typedef struct {
 #define UNICODE_PI 0x03c0
 #define UNICODE_TIMES 0x00D7
 #define UNICODE_MINUS 0x2212
+#define UNICODE_EURO 0x20ac
+#define UNICODE_POUNDS1 0x00a3
+#define UNICODE_POUNDS2 0x20a4
+#define UNICODE_YEN 0x00a5
+#define UNICODE_YEN_WIDE 0xffe5
 
 GOFormatFamily
 go_format_get_family (GOFormat const *fmt)
@@ -5018,13 +5023,27 @@ go_format_generate_accounting_str (GString *dst,
 	GString *sym = g_string_new (NULL);
 	GString *q = g_string_new (NULL);
 	const char *symstr;
-	const char *quote;
+	const char *quote = "\"";
 
 	if (!currency)
 		currency = &go_format_currencies[0];
 
 	symstr = currency->symbol;
-	quote = symstr[0] != '[' ? "\"" : "";
+	switch (g_utf8_get_char (symstr)) {
+	case '$':
+	case UNICODE_POUNDS1:
+	case UNICODE_YEN:
+	case UNICODE_EURO:
+		if ((g_utf8_next_char (symstr))[0])
+			break;  /* Something follows.  */
+		/* Fall through.  */
+	case 0:
+	case '[':
+		quote = "";
+		break;
+	default:
+		break;
+	}
 
 	go_format_generate_number_str (num, num_decimals, TRUE,
 				       FALSE, FALSE, NULL, NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]