[goffice] GOFormat: simplify code using new generators.



commit 10817c427a9b6962d954a53ea39f68d5e2eff425
Author: Morten Welinder <terra gnome org>
Date:   Thu May 28 13:08:56 2009 -0400

    GOFormat: simplify code using new generators.
---
 ChangeLog               |    4 ++
 goffice/utils/formats.c |   75 ++++++++++++-----------------------------------
 2 files changed, 23 insertions(+), 56 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 371394d..3c65993 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-05-28  Morten Welinder  <terra gnome org>
 
+	* 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.
+
 	* goffice/utils/go-format.c (go_format_locale_currency): New
 	function.
 
diff --git a/goffice/utils/formats.c b/goffice/utils/formats.c
index dfac8ff..13f89c3 100644
--- a/goffice/utils/formats.c
+++ b/goffice/utils/formats.c
@@ -196,67 +196,30 @@ guess_date_sep (void)
 void
 go_currency_date_format_init (void)
 {
-	gboolean precedes, space_sep;
-	char const *curr = go_locale_get_currency (&precedes, &space_sep)->str;
-	char *pre, *post, *pre_rep, *post_rep;
+	GOFormatCurrency const *currency = go_format_locale_currency ();
 	GHashTable *dt_hash;
 	GOFormat *fmt;
 	guint N;
+	int i;
 
-	/*
-	 *  1. "$*  "	Yes, it is needed (because we use match[])
-	 *  2. "$*  "	This one is like \1, but doesn't have the \{0,1\}
-	 *  3. "$"
-	 *  4. "#,##0.00"
-	 *  5. ".00"
-	 *  6. "*  $"	Same here.
-	 *  7. "*  $"
-	 *  8. "$"
-	 */
-
-	if (precedes) {
-		post_rep = post = (char *)"";
-		pre_rep = (char *)"* ";
-		pre = g_strconcat ("\"", curr,
-				   (space_sep ? "\" " : "\""), NULL);
-	} else {
-		pre_rep = pre = (char *)"";
-		post_rep = (char *)"* ";
-		post = g_strconcat ((space_sep ? " \"" : "\""),
-				    curr, "\"", NULL);
+	for (i = 0; i < 6; i++) {
+		int num_decimals = (i >= 3) ? 2 : 0;
+		gboolean negative_red = (i % 3 == 2);
+		gboolean negative_paren = (i % 3 >= 1);
+		GString *str = g_string_new (NULL);
+		go_format_generate_currency_str (str, num_decimals, TRUE,
+						 negative_red, negative_paren,
+						 currency, FALSE);
+		fmts_currency[i] = g_string_free (str, FALSE);
 	}
 
-	fmts_currency [0] = g_strdup_printf (
-		"%s#,##0%s",
-		pre, post);
-	fmts_currency [1] = g_strdup_printf (
-		"%s#,##0%s_);(%s#,##0%s)",
-		pre, post, pre, post);
-	fmts_currency [2] = g_strdup_printf (
-		"%s#,##0%s_);[Red](%s#,##0%s)",
-		pre, post, pre, post);
-	fmts_currency [3] = g_strdup_printf (
-		"%s#,##0.00%s",
-		pre, post);
-	fmts_currency [4] = g_strdup_printf (
-		"%s#,##0.00%s_);(%s#,##0.00%s)",
-		pre, post, pre, post);
-	fmts_currency [5] = g_strdup_printf (
-		"%s#,##0.00%s_);[Red](%s#,##0.00%s)",
-		pre, post, pre, post);
-
-	fmts_accounting [0] = g_strdup_printf (
-		"_(%s%s#,##0%s%s_);_(%s%s(#,##0)%s%s;_(%s%s\"-\"%s%s_);_(@_)",
-		pre, pre_rep, post_rep, post,
-		pre, pre_rep, post_rep, post,
-		pre, pre_rep, post_rep, post);
-	fmts_accounting [2] = g_strdup_printf (
-		"_(%s%s#,##0.00%s%s_);_(%s%s(#,##0.00)%s%s;_(%s%s\"-\"??%s%s_);_(@_)",
-		pre, pre_rep, post_rep, post,
-		pre, pre_rep, post_rep, post,
-		pre, pre_rep, post_rep, post);
-
-	g_free (*pre ? pre : post);
+	for (i = 0; i < 4; i += 2) {
+		int num_decimals = (i >= 2) ? 2 : 0;
+		GString *str = g_string_new (NULL);
+		go_format_generate_accounting_str (str, num_decimals,
+						   currency);
+		fmts_accounting[i] = g_string_free (str, FALSE);
+	}
 
 	/* ---------------------------------------- */
 



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