[goffice] GOFormat: improve inc/dec precision for standard formats.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [goffice] GOFormat: improve inc/dec precision for standard formats.
- Date: Sun, 31 May 2009 20:44:55 -0400 (EDT)
commit 09eb3b5f42ae48fff28467f62c77ebc07af6d59c
Author: Morten Welinder <terra gnome org>
Date: Sun May 31 20:44:29 2009 -0400
GOFormat: improve inc/dec precision for standard formats.
---
ChangeLog | 7 ++++++
NEWS | 1 +
goffice/utils/go-format.c | 53 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5f99b3c..527c16f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-05-31 Morten Welinder <terra gnome org>
+
+ * goffice/utils/go-format.c (go_format_inc_precision,
+ go_format_dec_precision): Use go_format_get_details and
+ go_format_generate_str. That handles accounting formats and is
+ less hacky.
+
2009-05-31 Andreas J. Guelzow <aguelzow pyrshep ca>
* goffice/utils/go-format.c (go_format_output_fraction_to_odf):
diff --git a/NEWS b/NEWS
index 0595cec..b1aa286 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Andreas:
Morten:
* Add functions to generate number formats.
* Make format classification function public.
+ * Fix inc/dec precision for accounting format.
--------------------------------------------------------------------------
goffice 0.7.7:
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 51c91fc..028b261 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -3916,7 +3916,32 @@ go_format_inc_precision (GOFormat const *fmt)
GString *res = g_string_new (NULL);
const char *str = fmt->format;
gssize last_zero = -1;
+ GOFormatDetails details;
+ gboolean exact;
+ go_format_get_details (fmt, &details, &exact);
+ if (exact) {
+ switch (details.family) {
+ case GO_FORMAT_NUMBER:
+ case GO_FORMAT_SCIENTIFIC:
+ case GO_FORMAT_CURRENCY:
+ case GO_FORMAT_ACCOUNTING:
+ case GO_FORMAT_PERCENTAGE:
+ if (details.num_decimals >= 30)
+ return NULL;
+ details.num_decimals++;
+ go_format_generate_str (res, &details);
+ return make_frobbed_format (g_string_free (res, FALSE),
+ fmt);
+ case GO_FORMAT_GENERAL:
+ case GO_FORMAT_TEXT:
+ return NULL;
+ default:
+ break;
+ }
+ }
+
+ /* Fall-back. */
while (1) {
const char *tstr = str;
GOFormatTokenType tt;
@@ -3998,7 +4023,32 @@ go_format_dec_precision (GOFormat const *fmt)
{
GString *res = g_string_new (NULL);
const char *str = fmt->format;
+ GOFormatDetails details;
+ gboolean exact;
+ go_format_get_details (fmt, &details, &exact);
+ if (exact) {
+ switch (details.family) {
+ case GO_FORMAT_NUMBER:
+ case GO_FORMAT_SCIENTIFIC:
+ case GO_FORMAT_CURRENCY:
+ case GO_FORMAT_ACCOUNTING:
+ case GO_FORMAT_PERCENTAGE:
+ if (details.num_decimals <= 0)
+ return NULL;
+ details.num_decimals--;
+ go_format_generate_str (res, &details);
+ return make_frobbed_format (g_string_free (res, FALSE),
+ fmt);
+ case GO_FORMAT_GENERAL:
+ case GO_FORMAT_TEXT:
+ return NULL;
+ default:
+ break;
+ }
+ }
+
+ /* Fall-back. */
while (1) {
const char *tstr = str;
GOFormatTokenType tt;
@@ -4040,6 +4090,9 @@ go_format_toggle_1000sep (GOFormat const *fmt)
res = g_string_new (NULL);
str = fmt->format;
+ /* No need to go via go_format_get_details since we can handle
+ all the standard formats with the code below. */
+
while (1) {
const char *tstr = str;
GOFormatTokenType tt;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]