[glom] Some bytes-versus-characters corrections.



commit 9a046ceac8f2fd3942ec4d339b76583577893ff2
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Jan 14 21:28:27 2014 +0100

    Some bytes-versus-characters corrections.

 glom/libglom/document/bakery/document.cc |   13 ++++++++++++-
 glom/libglom/document/bakery/document.h  |    2 ++
 glom/libglom/document/document.cc        |    2 --
 tests/test_selfhosting_utils.cc          |    2 +-
 4 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/glom/libglom/document/bakery/document.cc b/glom/libglom/document/bakery/document.cc
index a88b032..21b9cb3 100644
--- a/glom/libglom/document/bakery/document.cc
+++ b/glom/libglom/document/bakery/document.cc
@@ -141,7 +141,18 @@ bool Document::load_from_data(const guchar* data, std::size_t length, int& failu
   //Initialize the output parameter:
   failure_code = 0;
 
-  m_strContents = Glib::ustring((char*)data, length);
+  //We use the std::string constructor, because that takes the number
+  //of bytes, rather than the ustring constructor, which takes the number
+  //of characters.
+  try
+  {
+    m_strContents = std::string((char*)data, length);
+  }
+  catch(const std::exception& ex)
+  {
+    std::cerr << G_STRFUNC << ": Exception instantiating std::string: " << ex.what() << std::endl;
+    return false;
+  }
 
   const bool bTest = load_after(failure_code); //may be overridden.
   if(bTest)
diff --git a/glom/libglom/document/bakery/document.h b/glom/libglom/document/bakery/document.h
index d44f338..2f40a33 100644
--- a/glom/libglom/document/bakery/document.h
+++ b/glom/libglom/document/bakery/document.h
@@ -61,6 +61,8 @@ public:
 
   /* Loads data from disk, using the URI (set with set_file_uri()) then asks the View to update itself.
    * bool indicates success.
+   * @param data The bytes.
+   * @param length The number of bytes.
    * @param failure_code Used to return a custom error code that is understood by your application. This 
must be greater than zero.
    */
   bool load_from_data(const guchar* data, std::size_t length, int& failure_code);
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 4a309dc..e4b8527 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -38,8 +38,6 @@
 #include <giomm/file.h>
 #include <glibmm/miscutils.h>
 #include <glibmm/convert.h>
-#include <glibmm/shell.h>
-//#include <libglom/busy_cursor.h>
 
 #include <libglom/connectionpool.h>
 
diff --git a/tests/test_selfhosting_utils.cc b/tests/test_selfhosting_utils.cc
index bf3e4d1..cb462f6 100644
--- a/tests/test_selfhosting_utils.cc
+++ b/tests/test_selfhosting_utils.cc
@@ -382,7 +382,7 @@ bool test_create_and_selfhost_from_data(const Glib::ustring& example_file_conten
   document.set_allow_autosave(false); //To simplify things and to not depend implicitly on autosave.
 
   int failure_code = 0;
-  const bool test = document.load_from_data((const guchar*)example_file_contents.c_str(), 
example_file_contents.size(), failure_code);
+  const bool test = document.load_from_data((const guchar*)example_file_contents.c_str(), 
example_file_contents.bytes(), failure_code);
 
   if(!test)
   {


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