[libxml++] Use std::string for filenames



commit 0d7d0c96dba53f3bd0d854b5dfb736d39eade4ff
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Tue Sep 29 10:50:58 2015 +0200

    Use std::string for filenames
    
    Since filenames are not necessarily UTF-8 encoded, store them in std::strings
    instead of Glib::ustrings. Bug #754673.

 libxml++/document.cc                      |    6 +++---
 libxml++/document.h                       |   18 ++++++++++++++----
 libxml++/parsers/domparser.cc             |    4 ++--
 libxml++/parsers/domparser.h              |    4 ++--
 libxml++/parsers/parser.h                 |    3 ++-
 libxml++/parsers/saxparser.cc             |    2 +-
 libxml++/parsers/saxparser.h              |    2 +-
 libxml++/relaxngschema.cc                 |    4 ++--
 libxml++/relaxngschema.h                  |    4 ++--
 libxml++/schemabase.h                     |    3 ++-
 libxml++/validators/dtdvalidator.cc       |   10 +++++-----
 libxml++/validators/dtdvalidator.h        |    6 +++---
 libxml++/validators/relaxngvalidator.cc   |    6 +++---
 libxml++/validators/relaxngvalidator.h    |    6 +++---
 libxml++/validators/schemavalidatorbase.h |    4 ++--
 libxml++/validators/validator.h           |    3 ++-
 libxml++/validators/xsdvalidator.cc       |    6 +++---
 libxml++/validators/xsdvalidator.h        |    6 +++---
 libxml++/xsdschema.cc                     |    4 ++--
 libxml++/xsdschema.h                      |    4 ++--
 20 files changed, 59 insertions(+), 46 deletions(-)
---
diff --git a/libxml++/document.cc b/libxml++/document.cc
index c3ced5c..e8ddd74 100644
--- a/libxml++/document.cc
+++ b/libxml++/document.cc
@@ -320,12 +320,12 @@ ProcessingInstructionNode* Document::add_processing_instruction(
   return static_cast<ProcessingInstructionNode*>(node->_private);
 }
 
-void Document::write_to_file(const Glib::ustring& filename, const Glib::ustring& encoding)
+void Document::write_to_file(const std::string& filename, const Glib::ustring& encoding)
 {
   do_write_to_file(filename, encoding, false);
 }
 
-void Document::write_to_file_formatted(const Glib::ustring& filename, const Glib::ustring& encoding)
+void Document::write_to_file_formatted(const std::string& filename, const Glib::ustring& encoding)
 {
   do_write_to_file(filename, encoding, true);
 }
@@ -351,7 +351,7 @@ void Document::write_to_stream_formatted(std::ostream& output, const Glib::ustri
 }
 
 void Document::do_write_to_file(
-    const Glib::ustring& filename,
+    const std::string& filename,
     const Glib::ustring& encoding,
     bool format)
 {
diff --git a/libxml++/document.h b/libxml++/document.h
index e49eda9..07c25c2 100644
--- a/libxml++/document.h
+++ b/libxml++/document.h
@@ -16,8 +16,19 @@
 #include <libxml++/nodes/element.h>
 #include <libxml++/dtd.h>
 
+#include <string>
 #include <ostream>
 
+/* std::string or Glib::ustring in function prototypes in libxml++?
+ *
+ * If it's propagated to a libxml2 function that takes a xmlChar*, it's
+ * UTF-8 encoded, and Glib::ustring is the right choice.
+ *
+ * If it's propagated to a libxml2 function that takes a char*, it's not
+ * necessarily UTF-8 encoded, and std::string is usually the right choice.
+ * Most of these strings are filenames or URLs.
+ */
+
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 extern "C" {
   struct _xmlDoc;
@@ -153,13 +164,12 @@ public:
   ProcessingInstructionNode* add_processing_instruction(
     const Glib::ustring& name, const Glib::ustring& content);
 
-  //TODO: Use std::string for filenames.
   /** Write the document to a file.
    * @param filename
    * @param encoding If not provided, UTF-8 is used
    * @throws xmlpp::exception
    */
-  void write_to_file(const Glib::ustring& filename, const Glib::ustring& encoding = Glib::ustring());
+  void write_to_file(const std::string& filename, const Glib::ustring& encoding = Glib::ustring());
 
   /** Write the document to a file.
    * The output is formatted by inserting whitespaces, which is easier to read for a human,
@@ -168,7 +178,7 @@ public:
    * @param encoding If not provided, UTF-8 is used
    * @throws xmlpp::exception
    */
-  void write_to_file_formatted(const Glib::ustring& filename, const Glib::ustring& encoding = 
Glib::ustring());
+  void write_to_file_formatted(const std::string& filename, const Glib::ustring& encoding = Glib::ustring());
 
   /** Write the document to the memory.
    * @param encoding If not provided, UTF-8 is used
@@ -251,7 +261,7 @@ protected:
   _xmlEntity* get_entity(const Glib::ustring& name);
 
 private:
-  void do_write_to_file(const Glib::ustring& filename, const Glib::ustring& encoding, bool format);
+  void do_write_to_file(const std::string& filename, const Glib::ustring& encoding, bool format);
   Glib::ustring do_write_to_string(const Glib::ustring& encoding, bool format);
   void do_write_to_stream(std::ostream& output, const Glib::ustring& encoding, bool format);
 
diff --git a/libxml++/parsers/domparser.cc b/libxml++/parsers/domparser.cc
index e8ba7ed..2628a53 100644
--- a/libxml++/parsers/domparser.cc
+++ b/libxml++/parsers/domparser.cc
@@ -26,7 +26,7 @@ DomParser::DomParser()
   doc_ = new Document();
 }
 
-DomParser::DomParser(const Glib::ustring& filename, bool validate)
+DomParser::DomParser(const std::string& filename, bool validate)
 : doc_(nullptr)
 {
   set_validate(validate);
@@ -38,7 +38,7 @@ DomParser::~DomParser()
   release_underlying();
 }
 
-void DomParser::parse_file(const Glib::ustring& filename)
+void DomParser::parse_file(const std::string& filename)
 {
   release_underlying(); //Free any existing document.
 
diff --git a/libxml++/parsers/domparser.h b/libxml++/parsers/domparser.h
index 3977e58..df13a9c 100644
--- a/libxml++/parsers/domparser.h
+++ b/libxml++/parsers/domparser.h
@@ -31,7 +31,7 @@ public:
    * @throws xmlpp::parse_error
    * @throws xmlpp::validity_error
    */
-  explicit DomParser(const Glib::ustring& filename, bool validate = false);
+  explicit DomParser(const std::string& filename, bool validate = false);
   ~DomParser() override;
 
   /** Parse an XML document from a file.
@@ -42,7 +42,7 @@ public:
    * @throws xmlpp::parse_error
    * @throws xmlpp::validity_error
    */
-  void parse_file(const Glib::ustring& filename) override;
+  void parse_file(const std::string& filename) override;
 
   /** Parse an XML document from a string.
    * If the parser already contains a document, that document and all its nodes
diff --git a/libxml++/parsers/parser.h b/libxml++/parsers/parser.h
index 6cf9b58..802a159 100644
--- a/libxml++/parsers/parser.h
+++ b/libxml++/parsers/parser.h
@@ -15,6 +15,7 @@
 #include <libxml++/exceptions/validity_error.h>
 #include <libxml++/exceptions/internal_error.h>
 
+#include <string>
 #include <istream>
 #include <cstdarg> // va_list
 #include <memory> // std::unique_ptr
@@ -142,7 +143,7 @@ public:
    * @throw exception
    * @param filename The path to the file.
    */
-  virtual void parse_file(const Glib::ustring& filename) = 0;
+  virtual void parse_file(const std::string& filename) = 0;
 
   /** Parse an XML document from raw memory.
    * @throw exception
diff --git a/libxml++/parsers/saxparser.cc b/libxml++/parsers/saxparser.cc
index 20fc5d8..bb41549 100644
--- a/libxml++/parsers/saxparser.cc
+++ b/libxml++/parsers/saxparser.cc
@@ -178,7 +178,7 @@ void SaxParser::parse()
   }
 }
 
-void SaxParser::parse_file(const Glib::ustring& filename)
+void SaxParser::parse_file(const std::string& filename)
 {
   if(context_)
   {
diff --git a/libxml++/parsers/saxparser.h b/libxml++/parsers/saxparser.h
index 90e845d..c3aa1bf 100644
--- a/libxml++/parsers/saxparser.h
+++ b/libxml++/parsers/saxparser.h
@@ -86,7 +86,7 @@ public:
    * @throws xmlpp::parse_error
    * @throws xmlpp::validity_error
    */
-  void parse_file(const Glib::ustring& filename) override;
+  void parse_file(const std::string& filename) override;
 
   /** Parse an XML document from a string.
    * @param contents The XML document as a string.
diff --git a/libxml++/relaxngschema.cc b/libxml++/relaxngschema.cc
index 96bd880..cf35ba8 100644
--- a/libxml++/relaxngschema.cc
+++ b/libxml++/relaxngschema.cc
@@ -61,7 +61,7 @@ RelaxNGSchema::RelaxNGSchema(_xmlRelaxNG* schema)
   pimpl_->schema = schema;
 }
 
-RelaxNGSchema::RelaxNGSchema(const Glib::ustring& filename)
+RelaxNGSchema::RelaxNGSchema(const std::string& filename)
 : pimpl_(new Impl)
 {
   parse_file(filename);
@@ -78,7 +78,7 @@ RelaxNGSchema::~RelaxNGSchema()
   release_underlying();
 }
 
-void RelaxNGSchema::parse_file(const Glib::ustring& filename)
+void RelaxNGSchema::parse_file(const std::string& filename)
 {
   parse_context(xmlRelaxNGNewParserCtxt(filename.c_str()));
 }
diff --git a/libxml++/relaxngschema.h b/libxml++/relaxngschema.h
index ffe2eaa..b658cfd 100644
--- a/libxml++/relaxngschema.h
+++ b/libxml++/relaxngschema.h
@@ -57,7 +57,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  explicit RelaxNGSchema(const Glib::ustring& filename);
+  explicit RelaxNGSchema(const std::string& filename);
 
   /** Create a schema from an XML document.
    * @param document A preparsed document tree, containing the schema definition.
@@ -75,7 +75,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  void parse_file(const Glib::ustring& filename) override;
+  void parse_file(const std::string& filename) override;
 
   /** Parse a schema definition from a string.
    * The schema must be defined with XML syntax. The compact syntax is not supported.
diff --git a/libxml++/schemabase.h b/libxml++/schemabase.h
index 8f61226..e0f3461 100644
--- a/libxml++/schemabase.h
+++ b/libxml++/schemabase.h
@@ -20,6 +20,7 @@
 #define __LIBXMLPP_SCHEMABASE_H
 
 #include <libxml++/noncopyable.h>
+#include <string>
 
 namespace Glib
 {
@@ -45,7 +46,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  virtual void parse_file(const Glib::ustring& filename) = 0;
+  virtual void parse_file(const std::string& filename) = 0;
 
   /** Parse a schema definition from a string.
    * If another schema has been parsed before, that schema is replaced by the new one.
diff --git a/libxml++/validators/dtdvalidator.cc b/libxml++/validators/dtdvalidator.cc
index 14f9126..d91fb05 100644
--- a/libxml++/validators/dtdvalidator.cc
+++ b/libxml++/validators/dtdvalidator.cc
@@ -26,16 +26,16 @@ DtdValidator::DtdValidator()
 {
 }
 
-DtdValidator::DtdValidator(const Glib::ustring& file)
+DtdValidator::DtdValidator(const std::string& filename)
 : context_(nullptr), dtd_(nullptr)
 {
-  parse_subset("",file);
+  parse_subset("", filename);
 }
 
 DtdValidator::DtdValidator(const Glib::ustring& external, const Glib::ustring& system)
 : context_(nullptr), dtd_(nullptr)
 {
-  parse_subset(external,system);
+  parse_subset(external, system);
 }
 
 DtdValidator::~DtdValidator()
@@ -43,9 +43,9 @@ DtdValidator::~DtdValidator()
   release_underlying();
 }
 
-void DtdValidator::parse_file(const Glib::ustring& filename)
+void DtdValidator::parse_file(const std::string& filename)
 {
-  parse_subset("",filename);
+  parse_subset("", filename);
 }
 
 void DtdValidator::parse_subset(const Glib::ustring& external, const Glib::ustring& system)
diff --git a/libxml++/validators/dtdvalidator.h b/libxml++/validators/dtdvalidator.h
index 0ee0c71..ac546a7 100644
--- a/libxml++/validators/dtdvalidator.h
+++ b/libxml++/validators/dtdvalidator.h
@@ -23,10 +23,10 @@ public:
   DtdValidator();
 
   /** Create a validator and parse an external subset (DTD file) immediately.
-   * @param file The URL of the DTD.
+   * @param filename The URL of the DTD.
    * @throws xmlpp::parse_error
    */
-  explicit DtdValidator(const Glib::ustring& file);
+  explicit DtdValidator(const std::string& filename);
 
   /** Create a validator and parse an external subset (DTD file) immediately.
    * @param external The external ID of the DTD.
@@ -50,7 +50,7 @@ public:
    * @param filename The URL of the DTD.
    * @throws xmlpp::parse_error
    */
-  void parse_file(const Glib::ustring& filename) override;
+  void parse_file(const std::string& filename) override;
 
   /** Parse a DTD from a string.
    * If the validator already contains a DTD, that DTD is deleted.
diff --git a/libxml++/validators/relaxngvalidator.cc b/libxml++/validators/relaxngvalidator.cc
index 8e92365..4cd9a9c 100644
--- a/libxml++/validators/relaxngvalidator.cc
+++ b/libxml++/validators/relaxngvalidator.cc
@@ -42,7 +42,7 @@ RelaxNGValidator::RelaxNGValidator()
 {
 }
 
-RelaxNGValidator::RelaxNGValidator(const Glib::ustring& filename)
+RelaxNGValidator::RelaxNGValidator(const std::string& filename)
 : pimpl_(new Impl)
 {
   parse_file(filename);
@@ -65,7 +65,7 @@ RelaxNGValidator::~RelaxNGValidator()
   release_underlying();
 }
 
-void RelaxNGValidator::parse_file(const Glib::ustring& filename)
+void RelaxNGValidator::parse_file(const std::string& filename)
 {
   set_schema(new RelaxNGSchema(filename), true);
 }
@@ -159,7 +159,7 @@ void RelaxNGValidator::validate(const Document* document)
   }
 }
 
-void RelaxNGValidator::validate(const Glib::ustring& filename)
+void RelaxNGValidator::validate(const std::string& filename)
 {
   // There is no xmlRelaxNGValidateFile().
   DomParser parser(filename);
diff --git a/libxml++/validators/relaxngvalidator.h b/libxml++/validators/relaxngvalidator.h
index a12b710..7d87309 100644
--- a/libxml++/validators/relaxngvalidator.h
+++ b/libxml++/validators/relaxngvalidator.h
@@ -50,7 +50,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  explicit RelaxNGValidator(const Glib::ustring& filename);
+  explicit RelaxNGValidator(const std::string& filename);
 
   /** Create a validator and parse a schema definition document.
    * @param document A preparsed document tree, containing the schema definition.
@@ -80,7 +80,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  void parse_file(const Glib::ustring& filename) override;
+  void parse_file(const std::string& filename) override;
 
   /** Parse a schema definition from a string.
    * The schema must be defined with XML syntax. The compact syntax is not supported.
@@ -145,7 +145,7 @@ public:
    * @throws xmlpp::parse_error
    * @throws xmlpp::validity_error
    */
-  void validate(const Glib::ustring& filename) override;
+  void validate(const std::string& filename) override;
 
 protected:
   void initialize_context() override;
diff --git a/libxml++/validators/schemavalidatorbase.h b/libxml++/validators/schemavalidatorbase.h
index f5b7f86..274ad94 100644
--- a/libxml++/validators/schemavalidatorbase.h
+++ b/libxml++/validators/schemavalidatorbase.h
@@ -46,7 +46,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  virtual void parse_file(const Glib::ustring& filename) = 0;
+  virtual void parse_file(const std::string& filename) = 0;
 
   /** Parse a schema definition from a string.
    * If the validator already contains a schema, that schema is released
@@ -86,7 +86,7 @@ public:
    * @throws xmlpp::parse_error
    * @throws xmlpp::validity_error
    */
-  virtual void validate(const Glib::ustring& filename) = 0;
+  virtual void validate(const std::string& filename) = 0;
 
 protected:
   void initialize_context() override;
diff --git a/libxml++/validators/validator.h b/libxml++/validators/validator.h
index e25a176..1528501 100644
--- a/libxml++/validators/validator.h
+++ b/libxml++/validators/validator.h
@@ -16,6 +16,7 @@
 #include <libxml++/exceptions/validity_error.h>
 #include <libxml++/exceptions/internal_error.h>
 #include <exception> // std::exception_ptr
+#include <string>
 
 extern "C" {
   struct _xmlValidCtxt;
@@ -37,7 +38,7 @@ public:
    * @param filename The URL of the schema or the DTD.
    * @throws xmlpp::parse_error
    */
-  virtual void parse_file(const Glib::ustring& filename) = 0;
+  virtual void parse_file(const std::string& filename) = 0;
 
   /** Parse a schema definition or a DTD from a string.
    * @param contents The schema definition or the DTD as a string.
diff --git a/libxml++/validators/xsdvalidator.cc b/libxml++/validators/xsdvalidator.cc
index 44be9a0..9d496a0 100644
--- a/libxml++/validators/xsdvalidator.cc
+++ b/libxml++/validators/xsdvalidator.cc
@@ -39,7 +39,7 @@ XsdValidator::XsdValidator()
 {
 }
 
-XsdValidator::XsdValidator(const Glib::ustring& filename)
+XsdValidator::XsdValidator(const std::string& filename)
 : pimpl_(new Impl)
 {
   parse_file(filename);
@@ -62,7 +62,7 @@ XsdValidator::~XsdValidator()
   release_underlying();
 }
 
-void XsdValidator::parse_file(const Glib::ustring& filename)
+void XsdValidator::parse_file(const std::string& filename)
 {
   set_schema(new XsdSchema(filename), true);
 }
@@ -157,7 +157,7 @@ void XsdValidator::validate(const Document* document)
   }
 }
 
-void XsdValidator::validate(const Glib::ustring& filename)
+void XsdValidator::validate(const std::string& filename)
 {
   if (!*this)
     throw internal_error("XsdValidator::validate(): Must have a schema to validate file.");
diff --git a/libxml++/validators/xsdvalidator.h b/libxml++/validators/xsdvalidator.h
index 2269afb..ff4840b 100644
--- a/libxml++/validators/xsdvalidator.h
+++ b/libxml++/validators/xsdvalidator.h
@@ -46,7 +46,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  explicit XsdValidator(const Glib::ustring& filename);
+  explicit XsdValidator(const std::string& filename);
 
   /** Create a validator and parse a schema definition document.
    * @param document A preparsed document tree, containing the schema definition.
@@ -73,7 +73,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  void parse_file(const Glib::ustring& filename) override;
+  void parse_file(const std::string& filename) override;
 
   /** Parse a schema definition from a string.
    * If the validator already contains a schema, that schema is released
@@ -135,7 +135,7 @@ public:
    * @throws xmlpp::internal_error
    * @throws xmlpp::validity_error
    */
-  void validate(const Glib::ustring& filename) override;
+  void validate(const std::string& filename) override;
 
 protected:
   void initialize_context() override;
diff --git a/libxml++/xsdschema.cc b/libxml++/xsdschema.cc
index 94a9238..4ad470e 100644
--- a/libxml++/xsdschema.cc
+++ b/libxml++/xsdschema.cc
@@ -60,7 +60,7 @@ XsdSchema::XsdSchema(_xmlSchema* schema)
   pimpl_->schema = schema;
 }
 
-XsdSchema::XsdSchema(const Glib::ustring& filename)
+XsdSchema::XsdSchema(const std::string& filename)
 : pimpl_(new Impl)
 {
   parse_file(filename);
@@ -77,7 +77,7 @@ XsdSchema::~XsdSchema()
   release_underlying();
 }
 
-void XsdSchema::parse_file(const Glib::ustring& filename)
+void XsdSchema::parse_file(const std::string& filename)
 {
   xmlResetLastError();
   release_underlying();
diff --git a/libxml++/xsdschema.h b/libxml++/xsdschema.h
index 8220e4e..2c26c11 100644
--- a/libxml++/xsdschema.h
+++ b/libxml++/xsdschema.h
@@ -53,7 +53,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  explicit XsdSchema(const Glib::ustring& filename);
+  explicit XsdSchema(const std::string& filename);
 
   /** Create a schema from an XML document.
    * @param document A preparsed document tree, containing the schema definition.
@@ -68,7 +68,7 @@ public:
    * @param filename The URL of the schema.
    * @throws xmlpp::parse_error
    */
-  void parse_file(const Glib::ustring& filename) override;
+  void parse_file(const std::string& filename) override;
 
   /** Parse a schema definition from a string.
    * If another schema has been parsed before, that schema is replaced by the new one.


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