[glibmm] Bug #613250 - Overload Glib::ustring::FormatStream::stream for char *



commit 94cde38dd2beb67bb97a37245168ce3a14b51ae2
Author: Debarshi Ray <debarshir src gnome org>
Date:   Sat Mar 20 00:16:12 2010 +0200

    Bug #613250 - Overload Glib::ustring::FormatStream::stream for char *

 ChangeLog             |   12 ++++++++++--
 glib/glibmm/ustring.h |   30 ++++++++++++++++++++----------
 2 files changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6ab47a5..fdc2dfd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,16 @@
+2010-03-20  Debarshi Ray  <debarshir src gnome org>
+
+	Bug #613250 - Overload Glib::ustring::FormatStream::stream for char *.
+
+    * glib/glibmm/ustring.[h|cc]: Add a FormatStream::stream(char*) override
+    because otherwise the templated stream() is called, which results in
+    corrupted data.
+
 2010-03-24  Murray Cumming  <murrayc murrayc com>
 
     ThemedIcon: Added get_names().
 
-	* gio/src/themedicon.[hg|ccg]: Add get_names() manually because we have 
+	* gio/src/themedicon.[hg|ccg]: Add get_names() manually because we have
     a strange error when trying to use _WRAP_METHOD() for it.
     Bug #612584 (Markus Schwab)
 
@@ -10,7 +18,7 @@
 
     MemoryInputStream: Correct data loss/corruption with binary data.
 
-	* gio/src/memoryinputstream.ccg: add_data(): Use g_memdup() instead of 
+	* gio/src/memoryinputstream.ccg: add_data(): Use g_memdup() instead of
     g_strdup() on data that could have a null in the middle.
     Bug #609552 (Holger Seelig)
 
diff --git a/glib/glibmm/ustring.h b/glib/glibmm/ustring.h
index 948b927..047682d 100644
--- a/glib/glibmm/ustring.h
+++ b/glib/glibmm/ustring.h
@@ -244,7 +244,7 @@ public:
   /*! Default constructor, which creates an empty string.
    */
   ustring();
-  
+
   ~ustring();
 
   /*! Construct a ustring as a copy of another ustring.
@@ -254,7 +254,7 @@ public:
 
   /*! Assign the value of another string to this string.
    * @param other A source string.
-   */ 
+   */
   ustring& operator=(const ustring& other);
 
   /*! Swap contents with another string.
@@ -288,19 +288,19 @@ public:
   /*! Construct a ustring as multiple characters.
    * @param n Number of characters.
    * @param uc UCS-4 code point to use.
-   */  
+   */
   ustring(size_type n, gunichar uc);
 
   /*! Construct a ustring as multiple characters.
    * @param n Number of characters.
    * @param c ASCII character to use.
-   */  
+   */
   ustring(size_type n, char c);
 
   /*! Construct a ustring as a copy of a range.
    * @param pbegin Start of range.
    * @param pend End of range.
-   */  
+   */
   template <class In> ustring(In pbegin, In pend);
 
 
@@ -496,7 +496,7 @@ public:
   /** Returns the number of characters in the string, not including any null-termination.
    * @result The number of UTF-8 characters.
    *
-   * @see bytes(), empty() 
+   * @see bytes(), empty()
    */
   size_type size()   const;
 
@@ -505,7 +505,7 @@ public:
   /** This is the same as size().
    */
   size_type length() const;
-  
+
   /** Returns the number of bytes in the string, not including any null-termination.
    * @result The number of bytes.
    *
@@ -807,7 +807,7 @@ private:
   template <class In, class ValueType = typename Glib::IteratorTraits<In>::value_type>
 #endif
   struct SequenceToString;
-  
+
   //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>;
@@ -873,7 +873,12 @@ public:
   ~FormatStream();
 
   template <class T> inline void stream(const T& value);
+
   inline void stream(const char* value);
+
+  //This overload exists to avoid the templated stream() being called for non-const char*.
+  inline void stream(char* value);
+
   ustring to_string() const;
 };
 
@@ -1058,6 +1063,12 @@ void ustring::FormatStream::stream(const char* value)
   stream_ << ustring(value);
 }
 
+inline
+void ustring::FormatStream::stream(char* value)
+{
+  stream_ << ustring(value);
+}
+
 /**** Glib::ustring ********************************************************/
 
 template <class In>
@@ -1262,7 +1273,7 @@ public:
 
 /** A template specialization for Stringify<const char*>,
  * because the regular template has ambiguous constructor overloads for char*.
- */ 
+ */
 template <>
 class ustring::Stringify<const char*>
 {
@@ -1602,4 +1613,3 @@ inline ustring operator+(char lhs, const ustring& rhs)
 
 
 #endif /* _GLIBMM_USTRING_H */
-



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