[glom] Correct use of locales when creating text representations.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom] Correct use of locales when creating text representations.
- Date: Fri, 8 Jan 2010 16:27:22 +0000 (UTC)
commit d6bea851acc272246a10093546d4777934eab02a
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Jan 8 17:26:50 2010 +0100
Correct use of locales when creating text representations.
* glom/main.cc: Set std::locale::global() to the user's current locale,
forcing us to imbue streams to whatever we actually want.
* glom/libglom/connectionpool_backends/postgres_self.cc: startup():
Do not use Utils::string_from_decimal() for the port number, because it
is meant to use the user's locale, but we need it in the C locale.
* glom/libglom/data_structure/field.cc: to_file_format(): Use
std::locale::classic() when we want the C locale, not std::locale(),
which means the user's locale, which was previously the C one by chance.
* glom/libglom/utils.cc: string_from_decimal(): Imbue the stream
as wanted.
ChangeLog | 15 +++++++++++++++
glom/import_csv/dialog_import_csv.cc | 2 +-
.../connectionpool_backends/postgres_self.cc | 5 +++--
glom/libglom/data_structure/field.cc | 2 +-
glom/libglom/utils.cc | 1 +
glom/main.cc | 6 ++++++
6 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5763258..c4b7808 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2010-01-08 Murray Cumming <murrayc murrayc com>
+
+ Correct use of locales when creating text representations.
+
+ * glom/main.cc: Set std::locale::global() to the user's current locale,
+ forcing us to imbue streams to whatever we actually want.
+ * glom/libglom/connectionpool_backends/postgres_self.cc: startup():
+ Do not use Utils::string_from_decimal() for the port number, because it
+ is meant to use the user's locale, but we need it in the C locale.
+ * glom/libglom/data_structure/field.cc: to_file_format(): Use
+ std::locale::classic() when we want the C locale, not std::locale(),
+ which means the user's locale, which was previously the C one by chance.
+ * glom/libglom/utils.cc: string_from_decimal(): Imbue the stream
+ as wanted.
+
2010-01-07 Michael Hasselmann <michaelh openismus com>
Fix potential encoding error for currency symbols
diff --git a/glom/import_csv/dialog_import_csv.cc b/glom/import_csv/dialog_import_csv.cc
index 0f0f43e..dba9168 100644
--- a/glom/import_csv/dialog_import_csv.cc
+++ b/glom/import_csv/dialog_import_csv.cc
@@ -138,7 +138,7 @@ Dialog_Import_CSV::Dialog_Import_CSV(BaseObjectType* cobject, const Glib::RefPtr
the_c_time.tm_mday = 22; //starts at 1
//Get the ISO (not current locale) text representation:
- const Glib::ustring date_text = Glom::Conversions::format_date(the_c_time, std::locale() /* ignored */, true /* iso_format */);
+ const Glib::ustring date_text = Glom::Conversions::format_date(the_c_time, std::locale::classic() /* ignored */, true /* iso_format */);
const Glib::ustring advice = Glib::ustring::compose(_("Note that the source file should contain numbers and dates in international ISO format. For instance, 22nd November 2008 should be %1."), date_text);
m_advice_label->set_text(advice);
std::cout << "DEBUG: advice=" << advice << std::endl;
diff --git a/glom/libglom/connectionpool_backends/postgres_self.cc b/glom/libglom/connectionpool_backends/postgres_self.cc
index b22a601..042ee91 100644
--- a/glom/libglom/connectionpool_backends/postgres_self.cc
+++ b/glom/libglom/connectionpool_backends/postgres_self.cc
@@ -29,6 +29,7 @@
#include <glibmm/i18n.h>
#include <libglom/gst-package.h>
+#include <sstream> //For stringstream
#ifdef G_OS_WIN32
# include <windows.h>
@@ -475,8 +476,8 @@ bool PostgresSelfHosted::startup(const SlotProgress& slot_progress, bool network
return false;
}
- const Glib::ustring port_as_text = Utils::string_from_decimal(available_port);
-
+ //TODO: Performance:
+ const std::string port_as_text = Glib::Ascii::dtostr(available_port);
// -D specifies the data directory.
// -c config_file= specifies the configuration file
diff --git a/glom/libglom/data_structure/field.cc b/glom/libglom/data_structure/field.cc
index 957ee66..4c61331 100644
--- a/glom/libglom/data_structure/field.cc
+++ b/glom/libglom/data_structure/field.cc
@@ -318,7 +318,7 @@ Glib::ustring Field::to_file_format(const Gnome::Gda::Value& value, glom_field_t
}
NumericFormat format_ignored; //Because we use ISO format.
- const Glib::ustring result = Conversions::get_text_for_gda_value(glom_type, value, std::locale() /* SQL uses the C locale */, format_ignored, true /* ISO standard */);
+ const Glib::ustring result = Conversions::get_text_for_gda_value(glom_type, value, std::locale::classic() /* SQL uses the C locale */, format_ignored, true /* ISO standard */);
//Escape " as "", as specified by the CSV RFC:
return Utils::string_replace(result, GLOM_QUOTE_FOR_FILE_FORMAT, GLOM_QUOTE_FOR_FILE_FORMAT GLOM_QUOTE_FOR_FILE_FORMAT);
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 1329b8a..0d319fe 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -594,6 +594,7 @@ Glib::ustring Utils::string_from_decimal(guint decimal)
//TODO_Performance:
std::stringstream stream;
+ stream.imbue(std::locale("")); //Use the user's current locale.
stream << decimal;
Glib::ustring result;
diff --git a/glom/main.cc b/glom/main.cc
index dab78a9..ebdea96 100644
--- a/glom/main.cc
+++ b/glom/main.cc
@@ -422,6 +422,12 @@ main(int argc, char* argv[])
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
+ // Set the locale for any streams to the user's current locale,
+ // We should not rely on the default locale of
+ // any streams (we should always do an explicit imbue()),
+ // but this is maybe a good default in case we forget.
+ std::locale::global(std::locale(""));
+
Glom::libglom_init(); //Also initializes python.
#ifdef GLOM_ENABLE_MAEMO
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]