[goffice] Formats: recogize formats like "0E+000"



commit ebe2e2b5a2a8a133645dbeeaa796119dd6714cff
Author: Morten Welinder <terra gnome org>
Date:   Fri Aug 5 11:46:46 2011 -0400

    Formats: recogize formats like "0E+000"

 ChangeLog                 |    6 ++++++
 NEWS                      |    3 +++
 goffice/utils/go-format.c |   22 +++++++++++++++++++---
 goffice/utils/go-format.h |    3 +++
 4 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 33a6fbc..5fb79f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2011-08-05  Morten Welinder  <terra gnome org>
 
+	* goffice/utils/go-format.c (go_format_get_details): Deduce
+	exponent_digits.
+	(go_format_generate_scientific_str): Add right number of exponent
+	digits.
+	(go_format_details_init): Reset exponent_digits.
+
 	* goffice/data/go-data.c (go_data_preferred_fmt): Constify.  Fixes
 	#635072.  All callers adjusted.
 
diff --git a/NEWS b/NEWS
index c9dd19a..33fe4c8 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@ Jean:
 	* Port to gtk+-3.0.
 	* Add a plugin directory for extern plugins, independent from micro version.
 
+Morten:
+	* Recognize scientific formats with longer exponents.
+
 --------------------------------------------------------------------------
 goffice 0.8.17:
 
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index b3be4d0..995ca49 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -5253,8 +5253,12 @@ go_format_generate_scientific_str (GString *dst, GOFormatDetails const *details)
 
 	if (details->use_markup)
 		g_string_append (dst, "EE0");
-	else
-		g_string_append (dst, "E+00");
+	else {
+		/* Maximum not terribly important. */
+		int digits = CLAMP (details->exponent_digits, 1, 10);
+		g_string_append (dst, "E+");
+		go_string_append_c_n (dst, '0', digits);
+	}
 }
 #endif
 
@@ -5501,6 +5505,7 @@ go_format_details_init (GOFormatDetails *details, GOFormatFamily family)
 				  family == GO_FORMAT_CURRENCY);
 	details->magic = GO_FORMAT_MAGIC_NONE;
 	details->exponent_step = 1;
+	details->exponent_digits = 2;
 	details->min_digits = 1;
 }
 #endif
@@ -5618,12 +5623,23 @@ go_format_get_details (GOFormat const *fmt,
 				      (comma[3] == '0' || comma[3] == '#'));
 
 		if (dst->family == GO_FORMAT_SCIENTIFIC) {
-			const char *mend = dot ? dot : strchr (str, 'E');
+			const char *epos = strchr (str, 'E');
+			const char *mend = dot ? dot : epos;
 			dst->use_markup = (strstr (str, "EE0") != NULL);
 			dst->exponent_step = mend - str;
 			dst->simplify_mantissa = mend != str && mend[-1] == '#';
 			if (dst->simplify_mantissa)
 				dst->min_digits = 0;
+
+			dst->exponent_digits = 0;
+			if (dst->use_markup) epos++;
+			epos++;
+			if (epos[0] == '+' || epos[0] == '-')
+				epos++;
+			while (epos[0] == '0' || epos[0] == '#' || epos[0] == '?') {
+				epos++;
+				dst->exponent_digits++;
+			}
 		}
 
 		if (exact != NULL) {
diff --git a/goffice/utils/go-format.h b/goffice/utils/go-format.h
index b82e3b3..43790d6 100644
--- a/goffice/utils/go-format.h
+++ b/goffice/utils/go-format.h
@@ -92,8 +92,11 @@ typedef struct {
 
 	/* SCIENTIFIC: */
 	int exponent_step;
+	int exponent_digits;
 	gboolean use_markup;
 	gboolean simplify_mantissa;
+
+	int expansion[30];
 } GOFormatDetails;
 
 /*************************************************************************/



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