summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Elstner <daniel@src.gnome.org>2007-08-12 21:09:00 +0000
committerDaniel Elstner <daniel@src.gnome.org>2007-08-12 21:09:00 +0000
commit132b0ceb8c30ef82a6c11635eff8e7b41feba357 (patch)
tree544411b77209837210bc68cba9c00e8617d4f30d
parente915ec4b7e60652c080e907f87d7b0c02026b5d4 (diff)
downloadglibmm-132b0ceb8c30ef82a6c11635eff8e7b41feba357.tar.gz
Add -I$(top_builddir) in order to allow <config.h> to be included.
* build_shared/Makefile_build.am_fragment (all_includes): Add -I$(top_builddir) in order to allow <config.h> to be included. * glib/glibmm/ustring.{cc,h}: Include <config.h> for the definition of SIZEOF_WCHAR_T. (ustring::FormatStream::stream): Replace accessor with template method that passes its argument onto the stream. Add overload for "const char*" to enable the use of UTF-8 string literals as arguments to ustring::format(). (ustring::FormatStream::FormatStream): Handle exceptions on failure to initialize the locale gracefully. (ustring::format): Adapt to the modified stream() method. (operator<<): Add missing call to ustring::raw() to get the number of bytes instead of code points. Oops. svn path=/trunk/; revision=433
-rw-r--r--ChangeLog17
-rw-r--r--build_shared/Makefile_build.am_fragment2
-rw-r--r--glib/glibmm/ustring.cc26
-rw-r--r--glib/glibmm/ustring.h58
4 files changed, 78 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 30345d40..b798d206 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2007-08-12 Daniel Elstner <danielk@openismus.com>
+ * build_shared/Makefile_build.am_fragment (all_includes): Add
+ -I$(top_builddir) in order to allow <config.h> to be included.
+
+ * glib/glibmm/ustring.{cc,h}: Include <config.h> for the
+ definition of SIZEOF_WCHAR_T.
+ (ustring::FormatStream::stream): Replace accessor with template
+ method that passes its argument onto the stream. Add overload
+ for "const char*" to enable the use of UTF-8 string literals as
+ arguments to ustring::format().
+ (ustring::FormatStream::FormatStream): Handle exceptions on
+ failure to initialize the locale gracefully.
+ (ustring::format): Adapt to the modified stream() method.
+ (operator<<): Add missing call to ustring::raw() to get the
+ number of bytes instead of code points. Oops.
+
+2007-08-12 Daniel Elstner <danielk@openismus.com>
+
* glib/glibmm/ustring.{cc,h}: Add preliminary implementation of
a message compose and format API (bug #399216). The API design
is not final and still open for discussion.
diff --git a/build_shared/Makefile_build.am_fragment b/build_shared/Makefile_build.am_fragment
index 95a39412..7a8bef44 100644
--- a/build_shared/Makefile_build.am_fragment
+++ b/build_shared/Makefile_build.am_fragment
@@ -41,7 +41,7 @@ endif
common_ldflags = -version-info $(LIBGLIBMM_SO_VERSION) $(no_undefined)
-all_includes = -I$(top_builddir)/glib -I$(top_srcdir)/glib \
+all_includes = -I$(top_builddir)/glib -I$(top_srcdir)/glib -I$(top_builddir) \
$(sublib_cflags) $(GTHREAD_CFLAGS)
extra_defines = -DG_LOG_DOMAIN=\"$(sublib_name)\" $(extra_win32_defines) \
diff --git a/glib/glibmm/ustring.cc b/glib/glibmm/ustring.cc
index 5397659b..57e6ea21 100644
--- a/glib/glibmm/ustring.cc
+++ b/glib/glibmm/ustring.cc
@@ -28,10 +28,13 @@
#include <iostream>
#include <cstring>
+#include <config.h>
#include <glibmmconfig.h>
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+# include <stdexcept>
+#endif
GLIBMM_USING_STD(find)
-
namespace
{
@@ -1251,8 +1254,20 @@ ustring::FormatStream::FormatStream()
:
stream_ ()
{
- // Use the default locale of the environment.
+ // Try to use the default locale of the environment,
+ // but don't abort if it cannot be initialized.
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ try
+ {
+ stream_.imbue(std::locale(""));
+ }
+ catch (const std::runtime_error& error)
+ {
+ g_warning("%s: %s", G_STRFUNC, error.what());
+ }
+#else
stream_.imbue(std::locale(""));
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
}
ustring::FormatStream::~FormatStream()
@@ -1333,8 +1348,8 @@ std::istream& operator>>(std::istream& is, Glib::ustring& utf8_string)
std::ostream& operator<<(std::ostream& os, const Glib::ustring& utf8_string)
{
GError* error = 0;
- const ScopedPtr<char> buf (g_locale_from_utf8(utf8_string.data(),
- utf8_string.size(), 0, 0, &error));
+ const ScopedPtr<char> buf (g_locale_from_utf8(utf8_string.raw().data(),
+ utf8_string.raw().size(), 0, 0, &error));
if (error)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -1413,6 +1428,9 @@ std::wostream& operator<<(std::wostream& os, const ustring& utf8_string)
const ScopedPtr<gunichar2> buf (g_utf8_to_utf16(utf8_string.raw().data(),
utf8_string.raw().size(), 0, 0, &error));
#else
+ // TODO: For some reason the conversion from UTF-8 to WCHAR_T doesn't work
+ // with g_convert(), while iconv on the command line handles it just fine.
+ // Maybe a bug in GLib?
const ScopedPtr<char> buf (g_convert(utf8_string.raw().data(), utf8_string.raw().size(),
"WCHAR_T", "UTF-8", 0, 0, &error));
#endif /* !(__STDC_ISO_10646__ || G_OS_WIN32) */
diff --git a/glib/glibmm/ustring.h b/glib/glibmm/ustring.h
index 5d5dbd89..230a349f 100644
--- a/glib/glibmm/ustring.h
+++ b/glib/glibmm/ustring.h
@@ -698,20 +698,9 @@ private:
//The Tru64 compiler needs these partial specializations to be declared here,
//as well as defined later. That's probably correct. murrayc.
- template <class In>
- struct SequenceToString<In, char>;
-
- template <class In>
- struct SequenceToString<In, gunichar>;
+ template <class In> struct SequenceToString<In, char>;
+ template <class In> struct SequenceToString<In, gunichar>;
- /*
- template <>
- struct ustring::SequenceToString<Glib::ustring::iterator, gunichar>;
-
- template <>
- struct ustring::SequenceToString<Glib::ustring::const_iterator, gunichar>;
- */
-
class FormatStream;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
@@ -770,7 +759,8 @@ public:
FormatStream();
~FormatStream();
- StreamType& stream() { return stream_; }
+ template <class T> inline void stream(const T& value);
+ inline void stream(const char* value);
ustring to_string() const;
};
@@ -941,6 +931,19 @@ ustring::SequenceToString<In,gunichar>::SequenceToString(In pbegin, In pend)
}
}
+/**** Glib::ustring::FormatStream ******************************************/
+
+template <class T> inline
+void ustring::FormatStream::stream(const T& value)
+{
+ stream_ << value;
+}
+
+inline
+void ustring::FormatStream::stream(const char* value)
+{
+ stream_ << ustring(value);
+}
/**** Glib::ustring ********************************************************/
@@ -1086,7 +1089,7 @@ template <class T1> inline // static
ustring ustring::format(const T1& a1)
{
ustring::FormatStream buf;
- buf.stream() << a1;
+ buf.stream(a1);
return buf.to_string();
}
@@ -1094,7 +1097,8 @@ template <class T1, class T2> inline // static
ustring ustring::format(const T1& a1, const T2& a2)
{
ustring::FormatStream buf;
- buf.stream() << a1 << a2;
+ buf.stream(a1);
+ buf.stream(a2);
return buf.to_string();
}
@@ -1102,7 +1106,9 @@ template <class T1, class T2, class T3> inline // static
ustring ustring::format(const T1& a1, const T2& a2, const T3& a3)
{
ustring::FormatStream buf;
- buf.stream() << a1 << a2 << a3;
+ buf.stream(a1);
+ buf.stream(a2);
+ buf.stream(a3);
return buf.to_string();
}
@@ -1110,7 +1116,10 @@ template <class T1, class T2, class T3, class T4> inline // static
ustring ustring::format(const T1& a1, const T2& a2, const T3& a3, const T1& a4)
{
ustring::FormatStream buf;
- buf.stream() << a1 << a2 << a3 << a4;
+ buf.stream(a1);
+ buf.stream(a2);
+ buf.stream(a3);
+ buf.stream(a4);
return buf.to_string();
}
@@ -1118,7 +1127,11 @@ template <class T1, class T2, class T3, class T4, class T5> inline // static
ustring ustring::format(const T1& a1, const T2& a2, const T3& a3, const T1& a4, const T2& a5)
{
ustring::FormatStream buf;
- buf.stream() << a1 << a2 << a3 << a4 << a5;
+ buf.stream(a1);
+ buf.stream(a2);
+ buf.stream(a3);
+ buf.stream(a4);
+ buf.stream(a5);
return buf.to_string();
}
@@ -1127,7 +1140,12 @@ ustring ustring::format(const T1& a1, const T2& a2, const T3& a3, const T1& a4,
const T3& a6)
{
ustring::FormatStream buf;
- buf.stream() << a1 << a2 << a3 << a4 << a5 << a6;
+ buf.stream(a1);
+ buf.stream(a2);
+ buf.stream(a3);
+ buf.stream(a4);
+ buf.stream(a5);
+ buf.stream(a6);
return buf.to_string();
}