Skip to content

Commit 0d7d0c9

Browse files
author
Kjell Ahlstedt
committed
Use std::string for filenames
Since filenames are not necessarily UTF-8 encoded, store them in std::strings instead of Glib::ustrings. Bug #754673.
1 parent 480e92f commit 0d7d0c9

20 files changed

+59
-46
lines changed

libxml++/document.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ ProcessingInstructionNode* Document::add_processing_instruction(
320320
return static_cast<ProcessingInstructionNode*>(node->_private);
321321
}
322322

323-
void Document::write_to_file(const Glib::ustring& filename, const Glib::ustring& encoding)
323+
void Document::write_to_file(const std::string& filename, const Glib::ustring& encoding)
324324
{
325325
do_write_to_file(filename, encoding, false);
326326
}
327327

328-
void Document::write_to_file_formatted(const Glib::ustring& filename, const Glib::ustring& encoding)
328+
void Document::write_to_file_formatted(const std::string& filename, const Glib::ustring& encoding)
329329
{
330330
do_write_to_file(filename, encoding, true);
331331
}
@@ -351,7 +351,7 @@ void Document::write_to_stream_formatted(std::ostream& output, const Glib::ustri
351351
}
352352

353353
void Document::do_write_to_file(
354-
const Glib::ustring& filename,
354+
const std::string& filename,
355355
const Glib::ustring& encoding,
356356
bool format)
357357
{

libxml++/document.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@
1616
#include <libxml++/nodes/element.h>
1717
#include <libxml++/dtd.h>
1818

19+
#include <string>
1920
#include <ostream>
2021

22+
/* std::string or Glib::ustring in function prototypes in libxml++?
23+
*
24+
* If it's propagated to a libxml2 function that takes a xmlChar*, it's
25+
* UTF-8 encoded, and Glib::ustring is the right choice.
26+
*
27+
* If it's propagated to a libxml2 function that takes a char*, it's not
28+
* necessarily UTF-8 encoded, and std::string is usually the right choice.
29+
* Most of these strings are filenames or URLs.
30+
*/
31+
2132
#ifndef DOXYGEN_SHOULD_SKIP_THIS
2233
extern "C" {
2334
struct _xmlDoc;
@@ -153,13 +164,12 @@ class Document : NonCopyable
153164
ProcessingInstructionNode* add_processing_instruction(
154165
const Glib::ustring& name, const Glib::ustring& content);
155166

156-
//TODO: Use std::string for filenames.
157167
/** Write the document to a file.
158168
* @param filename
159169
* @param encoding If not provided, UTF-8 is used
160170
* @throws xmlpp::exception
161171
*/
162-
void write_to_file(const Glib::ustring& filename, const Glib::ustring& encoding = Glib::ustring());
172+
void write_to_file(const std::string& filename, const Glib::ustring& encoding = Glib::ustring());
163173

164174
/** Write the document to a file.
165175
* The output is formatted by inserting whitespaces, which is easier to read for a human,
@@ -168,7 +178,7 @@ class Document : NonCopyable
168178
* @param encoding If not provided, UTF-8 is used
169179
* @throws xmlpp::exception
170180
*/
171-
void write_to_file_formatted(const Glib::ustring& filename, const Glib::ustring& encoding = Glib::ustring());
181+
void write_to_file_formatted(const std::string& filename, const Glib::ustring& encoding = Glib::ustring());
172182

173183
/** Write the document to the memory.
174184
* @param encoding If not provided, UTF-8 is used
@@ -251,7 +261,7 @@ class Document : NonCopyable
251261
_xmlEntity* get_entity(const Glib::ustring& name);
252262

253263
private:
254-
void do_write_to_file(const Glib::ustring& filename, const Glib::ustring& encoding, bool format);
264+
void do_write_to_file(const std::string& filename, const Glib::ustring& encoding, bool format);
255265
Glib::ustring do_write_to_string(const Glib::ustring& encoding, bool format);
256266
void do_write_to_stream(std::ostream& output, const Glib::ustring& encoding, bool format);
257267

libxml++/parsers/domparser.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ DomParser::DomParser()
2626
doc_ = new Document();
2727
}
2828

29-
DomParser::DomParser(const Glib::ustring& filename, bool validate)
29+
DomParser::DomParser(const std::string& filename, bool validate)
3030
: doc_(nullptr)
3131
{
3232
set_validate(validate);
@@ -38,7 +38,7 @@ DomParser::~DomParser()
3838
release_underlying();
3939
}
4040

41-
void DomParser::parse_file(const Glib::ustring& filename)
41+
void DomParser::parse_file(const std::string& filename)
4242
{
4343
release_underlying(); //Free any existing document.
4444

libxml++/parsers/domparser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DomParser : public Parser
3131
* @throws xmlpp::parse_error
3232
* @throws xmlpp::validity_error
3333
*/
34-
explicit DomParser(const Glib::ustring& filename, bool validate = false);
34+
explicit DomParser(const std::string& filename, bool validate = false);
3535
~DomParser() override;
3636

3737
/** Parse an XML document from a file.
@@ -42,7 +42,7 @@ class DomParser : public Parser
4242
* @throws xmlpp::parse_error
4343
* @throws xmlpp::validity_error
4444
*/
45-
void parse_file(const Glib::ustring& filename) override;
45+
void parse_file(const std::string& filename) override;
4646

4747
/** Parse an XML document from a string.
4848
* If the parser already contains a document, that document and all its nodes

libxml++/parsers/parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <libxml++/exceptions/validity_error.h>
1616
#include <libxml++/exceptions/internal_error.h>
1717

18+
#include <string>
1819
#include <istream>
1920
#include <cstdarg> // va_list
2021
#include <memory> // std::unique_ptr
@@ -142,7 +143,7 @@ class Parser : NonCopyable
142143
* @throw exception
143144
* @param filename The path to the file.
144145
*/
145-
virtual void parse_file(const Glib::ustring& filename) = 0;
146+
virtual void parse_file(const std::string& filename) = 0;
146147

147148
/** Parse an XML document from raw memory.
148149
* @throw exception

libxml++/parsers/saxparser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void SaxParser::parse()
178178
}
179179
}
180180

181-
void SaxParser::parse_file(const Glib::ustring& filename)
181+
void SaxParser::parse_file(const std::string& filename)
182182
{
183183
if(context_)
184184
{

libxml++/parsers/saxparser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class SaxParser : public Parser
8686
* @throws xmlpp::parse_error
8787
* @throws xmlpp::validity_error
8888
*/
89-
void parse_file(const Glib::ustring& filename) override;
89+
void parse_file(const std::string& filename) override;
9090

9191
/** Parse an XML document from a string.
9292
* @param contents The XML document as a string.

libxml++/relaxngschema.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ RelaxNGSchema::RelaxNGSchema(_xmlRelaxNG* schema)
6161
pimpl_->schema = schema;
6262
}
6363

64-
RelaxNGSchema::RelaxNGSchema(const Glib::ustring& filename)
64+
RelaxNGSchema::RelaxNGSchema(const std::string& filename)
6565
: pimpl_(new Impl)
6666
{
6767
parse_file(filename);
@@ -78,7 +78,7 @@ RelaxNGSchema::~RelaxNGSchema()
7878
release_underlying();
7979
}
8080

81-
void RelaxNGSchema::parse_file(const Glib::ustring& filename)
81+
void RelaxNGSchema::parse_file(const std::string& filename)
8282
{
8383
parse_context(xmlRelaxNGNewParserCtxt(filename.c_str()));
8484
}

libxml++/relaxngschema.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class RelaxNGSchema : public SchemaBase
5757
* @param filename The URL of the schema.
5858
* @throws xmlpp::parse_error
5959
*/
60-
explicit RelaxNGSchema(const Glib::ustring& filename);
60+
explicit RelaxNGSchema(const std::string& filename);
6161

6262
/** Create a schema from an XML document.
6363
* @param document A preparsed document tree, containing the schema definition.
@@ -75,7 +75,7 @@ class RelaxNGSchema : public SchemaBase
7575
* @param filename The URL of the schema.
7676
* @throws xmlpp::parse_error
7777
*/
78-
void parse_file(const Glib::ustring& filename) override;
78+
void parse_file(const std::string& filename) override;
7979

8080
/** Parse a schema definition from a string.
8181
* The schema must be defined with XML syntax. The compact syntax is not supported.

libxml++/schemabase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define __LIBXMLPP_SCHEMABASE_H
2121

2222
#include <libxml++/noncopyable.h>
23+
#include <string>
2324

2425
namespace Glib
2526
{
@@ -45,7 +46,7 @@ class SchemaBase : NonCopyable
4546
* @param filename The URL of the schema.
4647
* @throws xmlpp::parse_error
4748
*/
48-
virtual void parse_file(const Glib::ustring& filename) = 0;
49+
virtual void parse_file(const std::string& filename) = 0;
4950

5051
/** Parse a schema definition from a string.
5152
* If another schema has been parsed before, that schema is replaced by the new one.

libxml++/validators/dtdvalidator.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ DtdValidator::DtdValidator()
2626
{
2727
}
2828

29-
DtdValidator::DtdValidator(const Glib::ustring& file)
29+
DtdValidator::DtdValidator(const std::string& filename)
3030
: context_(nullptr), dtd_(nullptr)
3131
{
32-
parse_subset("",file);
32+
parse_subset("", filename);
3333
}
3434

3535
DtdValidator::DtdValidator(const Glib::ustring& external, const Glib::ustring& system)
3636
: context_(nullptr), dtd_(nullptr)
3737
{
38-
parse_subset(external,system);
38+
parse_subset(external, system);
3939
}
4040

4141
DtdValidator::~DtdValidator()
4242
{
4343
release_underlying();
4444
}
4545

46-
void DtdValidator::parse_file(const Glib::ustring& filename)
46+
void DtdValidator::parse_file(const std::string& filename)
4747
{
48-
parse_subset("",filename);
48+
parse_subset("", filename);
4949
}
5050

5151
void DtdValidator::parse_subset(const Glib::ustring& external, const Glib::ustring& system)

libxml++/validators/dtdvalidator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class DtdValidator : public Validator
2323
DtdValidator();
2424

2525
/** Create a validator and parse an external subset (DTD file) immediately.
26-
* @param file The URL of the DTD.
26+
* @param filename The URL of the DTD.
2727
* @throws xmlpp::parse_error
2828
*/
29-
explicit DtdValidator(const Glib::ustring& file);
29+
explicit DtdValidator(const std::string& filename);
3030

3131
/** Create a validator and parse an external subset (DTD file) immediately.
3232
* @param external The external ID of the DTD.
@@ -50,7 +50,7 @@ class DtdValidator : public Validator
5050
* @param filename The URL of the DTD.
5151
* @throws xmlpp::parse_error
5252
*/
53-
void parse_file(const Glib::ustring& filename) override;
53+
void parse_file(const std::string& filename) override;
5454

5555
/** Parse a DTD from a string.
5656
* If the validator already contains a DTD, that DTD is deleted.

libxml++/validators/relaxngvalidator.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ RelaxNGValidator::RelaxNGValidator()
4242
{
4343
}
4444

45-
RelaxNGValidator::RelaxNGValidator(const Glib::ustring& filename)
45+
RelaxNGValidator::RelaxNGValidator(const std::string& filename)
4646
: pimpl_(new Impl)
4747
{
4848
parse_file(filename);
@@ -65,7 +65,7 @@ RelaxNGValidator::~RelaxNGValidator()
6565
release_underlying();
6666
}
6767

68-
void RelaxNGValidator::parse_file(const Glib::ustring& filename)
68+
void RelaxNGValidator::parse_file(const std::string& filename)
6969
{
7070
set_schema(new RelaxNGSchema(filename), true);
7171
}
@@ -159,7 +159,7 @@ void RelaxNGValidator::validate(const Document* document)
159159
}
160160
}
161161

162-
void RelaxNGValidator::validate(const Glib::ustring& filename)
162+
void RelaxNGValidator::validate(const std::string& filename)
163163
{
164164
// There is no xmlRelaxNGValidateFile().
165165
DomParser parser(filename);

libxml++/validators/relaxngvalidator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class RelaxNGValidator : public SchemaValidatorBase
5050
* @param filename The URL of the schema.
5151
* @throws xmlpp::parse_error
5252
*/
53-
explicit RelaxNGValidator(const Glib::ustring& filename);
53+
explicit RelaxNGValidator(const std::string& filename);
5454

5555
/** Create a validator and parse a schema definition document.
5656
* @param document A preparsed document tree, containing the schema definition.
@@ -80,7 +80,7 @@ class RelaxNGValidator : public SchemaValidatorBase
8080
* @param filename The URL of the schema.
8181
* @throws xmlpp::parse_error
8282
*/
83-
void parse_file(const Glib::ustring& filename) override;
83+
void parse_file(const std::string& filename) override;
8484

8585
/** Parse a schema definition from a string.
8686
* The schema must be defined with XML syntax. The compact syntax is not supported.
@@ -145,7 +145,7 @@ class RelaxNGValidator : public SchemaValidatorBase
145145
* @throws xmlpp::parse_error
146146
* @throws xmlpp::validity_error
147147
*/
148-
void validate(const Glib::ustring& filename) override;
148+
void validate(const std::string& filename) override;
149149

150150
protected:
151151
void initialize_context() override;

libxml++/validators/schemavalidatorbase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SchemaValidatorBase : public Validator
4646
* @param filename The URL of the schema.
4747
* @throws xmlpp::parse_error
4848
*/
49-
virtual void parse_file(const Glib::ustring& filename) = 0;
49+
virtual void parse_file(const std::string& filename) = 0;
5050

5151
/** Parse a schema definition from a string.
5252
* If the validator already contains a schema, that schema is released
@@ -86,7 +86,7 @@ class SchemaValidatorBase : public Validator
8686
* @throws xmlpp::parse_error
8787
* @throws xmlpp::validity_error
8888
*/
89-
virtual void validate(const Glib::ustring& filename) = 0;
89+
virtual void validate(const std::string& filename) = 0;
9090

9191
protected:
9292
void initialize_context() override;

libxml++/validators/validator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <libxml++/exceptions/validity_error.h>
1717
#include <libxml++/exceptions/internal_error.h>
1818
#include <exception> // std::exception_ptr
19+
#include <string>
1920

2021
extern "C" {
2122
struct _xmlValidCtxt;
@@ -37,7 +38,7 @@ class Validator : NonCopyable
3738
* @param filename The URL of the schema or the DTD.
3839
* @throws xmlpp::parse_error
3940
*/
40-
virtual void parse_file(const Glib::ustring& filename) = 0;
41+
virtual void parse_file(const std::string& filename) = 0;
4142

4243
/** Parse a schema definition or a DTD from a string.
4344
* @param contents The schema definition or the DTD as a string.

libxml++/validators/xsdvalidator.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ XsdValidator::XsdValidator()
3939
{
4040
}
4141

42-
XsdValidator::XsdValidator(const Glib::ustring& filename)
42+
XsdValidator::XsdValidator(const std::string& filename)
4343
: pimpl_(new Impl)
4444
{
4545
parse_file(filename);
@@ -62,7 +62,7 @@ XsdValidator::~XsdValidator()
6262
release_underlying();
6363
}
6464

65-
void XsdValidator::parse_file(const Glib::ustring& filename)
65+
void XsdValidator::parse_file(const std::string& filename)
6666
{
6767
set_schema(new XsdSchema(filename), true);
6868
}
@@ -157,7 +157,7 @@ void XsdValidator::validate(const Document* document)
157157
}
158158
}
159159

160-
void XsdValidator::validate(const Glib::ustring& filename)
160+
void XsdValidator::validate(const std::string& filename)
161161
{
162162
if (!*this)
163163
throw internal_error("XsdValidator::validate(): Must have a schema to validate file.");

libxml++/validators/xsdvalidator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class XsdValidator : public SchemaValidatorBase
4646
* @param filename The URL of the schema.
4747
* @throws xmlpp::parse_error
4848
*/
49-
explicit XsdValidator(const Glib::ustring& filename);
49+
explicit XsdValidator(const std::string& filename);
5050

5151
/** Create a validator and parse a schema definition document.
5252
* @param document A preparsed document tree, containing the schema definition.
@@ -73,7 +73,7 @@ class XsdValidator : public SchemaValidatorBase
7373
* @param filename The URL of the schema.
7474
* @throws xmlpp::parse_error
7575
*/
76-
void parse_file(const Glib::ustring& filename) override;
76+
void parse_file(const std::string& filename) override;
7777

7878
/** Parse a schema definition from a string.
7979
* If the validator already contains a schema, that schema is released
@@ -135,7 +135,7 @@ class XsdValidator : public SchemaValidatorBase
135135
* @throws xmlpp::internal_error
136136
* @throws xmlpp::validity_error
137137
*/
138-
void validate(const Glib::ustring& filename) override;
138+
void validate(const std::string& filename) override;
139139

140140
protected:
141141
void initialize_context() override;

0 commit comments

Comments
 (0)