Skip to content

Commit 9c5b59a

Browse files
committed
Remove dependency on glibmm and don't use Glib::ustring
For now, the API uses an xmlpp::ustring where it previously used Glib::ustring.
1 parent 7daf137 commit 9c5b59a

File tree

93 files changed

+629
-828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+629
-828
lines changed

configure.ac

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ MM_AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
3535
LT_PREREQ([2.2.6])
3636
LT_INIT([dlopen win32-dll disable-static])
3737

38-
AC_SUBST([LIBXMLXX_MODULES], ['libxml-2.0 >= 2.7.7 glibmm-2.64 >= 2.63.1'])
38+
AC_SUBST([LIBXMLXX_MODULES], ['libxml-2.0 >= 2.7.7'])
3939
PKG_CHECK_MODULES([LIBXMLXX], [$LIBXMLXX_MODULES])
4040

4141
AC_LANG([C++])
@@ -44,8 +44,6 @@ LIBXMLXX_CXX_HAS_EXCEPTION_PTR
4444

4545
MM_ARG_ENABLE_DOCUMENTATION
4646
MM_ARG_WITH_TAGFILE_DOC([libstdc++.tag], [mm-common-libstdc++])
47-
MM_ARG_WITH_TAGFILE_DOC([libsigc++-3.0.tag], [sigc++-3.0])
48-
MM_ARG_WITH_TAGFILE_DOC([glibmm-2.64.tag], [glibmm-2.64])
4947

5048
# Evaluate the --enable-warnings=level option.
5149
MM_ARG_ENABLE_WARNINGS([LIBXMLXX_WXXFLAGS],

docs/manual/libxml++_without_code.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ url="http://libxmlplusplus.sourceforge.net">libxmlplusplus.sourceforge.net</ulin
5454
</sect1>
5555

5656
<sect1>
57-
<title>UTF-8 and Glib::ustring</title>
57+
<title>UTF-8 and xmlpp::ustring</title>
5858
<para>The libxml++ API takes, and gives, strings in the UTF-8 Unicode encoding, which can support all known languages and locales. This choice was made because, of the encodings that have this capability, UTF-8 is the most commonly accepted choice. UTF-8 is a multi-byte encoding, meaning that some characters use more than 1 byte. But for compatibility, old-fashioned 7-bit ASCII strings are unchanged when encoded as UTF-8, and UTF-8 strings do not contain null bytes which would cause old code to misjudge the number of bytes. For these reasons, you can store a UTF-8 string in a std::string object. However, the std::string API will operate on that string in terms of bytes, instead of characters.</para>
59-
<para>Because Standard C++ has no string class that can fully handle UTF-8, libxml++ uses the Glib::ustring class from the glibmm library. Glib::ustring has almost exactly the same API as std::string, but methods such as length() and operator[] deal with whole UTF-8 characters rather than raw bytes.</para>
60-
<para>There are implicit conversions between std::string and Glib::ustring, so you can use std::string wherever you see a Glib::ustring in the API, if you really don't care about any locale other than English. However, that is unlikely in today's connected world.</para>
61-
<para>glibmm also provides useful API to convert between encodings and locales.</para>
59+
<para>The libxml++ API indicates when a string should be provided as UTF-8, or will be provided as UTF-8, by using the xmlpp::ustring type alias. However, this is really just a std::string, whose operator[] and size() consider bytes, not characters.</para>
6260
</sect1>
6361

6462
<sect1>
@@ -80,7 +78,7 @@ url="http://libxmlplusplus.sourceforge.net">libxmlplusplus.sourceforge.net</ulin
8078
<chapter id="chapter-parsers">
8179
<title>Parsers</title>
8280
<para>Like the underlying libxml2 library, libxml++ allows the use of 3 parsers, depending on your needs - the DOM, SAX, and TextReader parsers. The relative advantages and behaviour of these parsers will be explained here.</para>
83-
<para>All of the parsers may parse XML documents directly from disk, a string, or a C++ std::istream. Although the libxml++ API uses only Glib::ustring, and therefore the UTF-8 encoding, libxml++ can parse documents in any encoding, converting to UTF-8 automatically. This conversion will not lose any information because UTF-8 can represent any locale.</para>
81+
<para>All of the parsers may parse XML documents directly from disk, a string, or a C++ std::istream. Although the libxml++ API uses only xmlpp::ustring, indicating the UTF-8 encoding, libxml++ can parse documents in any encoding, converting to UTF-8 automatically. This conversion will not lose any information because UTF-8 can represent any locale.</para>
8482
<para>Remember that white space is usually significant in XML documents, so the parsers might provide unexpected text nodes that contain only spaces and new lines. The parser does not know whether you care about these text nodes, but your application may choose to ignore them.</para>
8583

8684
<sect1>

examples/Makefile.am

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ check_SCRIPTS = \
5858

5959
TESTS = $(check_SCRIPTS)
6060

61-
xmlpp_test_util = testutilities.h testutilities.cc
62-
6361
dom_build_dom_build_SOURCES = \
6462
dom_build/main.cc
6563
dom_parse_entities_dom_parse_entities_SOURCES = \
66-
dom_parse_entities/main.cc $(xmlpp_test_util)
64+
dom_parse_entities/main.cc
6765
dom_parser_dom_parser_SOURCES = \
68-
dom_parser/main.cc $(xmlpp_test_util)
66+
dom_parser/main.cc
6967
dom_parser_raw_dom_parser_raw_SOURCES = \
7068
dom_parser_raw/main.cc
7169
dom_read_write_dom_read_write_SOURCES = \

examples/dom_build/main.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
int
2929
main(int /* argc */, char** /* argv */)
3030
{
31-
// Set the global C and C++ locale to the user-configured locale,
32-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
33-
std::locale::global(std::locale(""));
3431

3532
try
3633
{

examples/dom_parse_entities/main.cc

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
#include <config.h>
2222
#endif
2323

24-
#include "../testutilities.h"
2524
#include <libxml++/libxml++.h>
2625
#include <iostream>
2726
#include <fstream>
2827
#include <cstdlib>
2928

3029
void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int indentation = 0)
3130
{
32-
const Glib::ustring indent(indentation, ' ');
31+
const std::string indent(indentation, ' ');
3332
std::cout << std::endl; //Separate nodes by an empty line.
3433

3534
if (substitute_entities)
@@ -38,7 +37,7 @@ void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int
3837
const auto nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
3938
if (nodeText && !nodeText->is_white_space())
4039
{
41-
std::cout << indent << "text = " << CatchConvertError(nodeText->get_content()) << std::endl;
40+
std::cout << indent << "text = " << nodeText->get_content() << std::endl;
4241
}
4342
}
4443
else
@@ -47,9 +46,9 @@ void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int
4746
const auto nodeEntityReference = dynamic_cast<const xmlpp::EntityReference*>(node);
4847
if (nodeEntityReference)
4948
{
50-
std::cout << indent << "entity reference name = " << CatchConvertError(nodeEntityReference->get_name()) << std::endl;
51-
std::cout << indent << " resolved text = " << CatchConvertError(nodeEntityReference->get_resolved_text()) << std::endl;
52-
std::cout << indent << " original text = " << CatchConvertError(nodeEntityReference->get_original_text()) << std::endl;
49+
std::cout << indent << "entity reference name = " << nodeEntityReference->get_name() << std::endl;
50+
std::cout << indent << " resolved text = " << nodeEntityReference->get_resolved_text() << std::endl;
51+
std::cout << indent << " original text = " << nodeEntityReference->get_original_text() << std::endl;
5352
}
5453
} // end if (substitute_entities)
5554

@@ -66,10 +65,6 @@ void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int
6665

6766
int main(int argc, char* argv[])
6867
{
69-
// Set the global C++ locale to the user-specified locale. Then we can
70-
// hopefully use std::cout with UTF-8, via Glib::ustring, without exceptions.
71-
std::locale::global(std::locale(""));
72-
7368
std::string filepath;
7469
if(argc > 1 )
7570
filepath = argv[1]; //Allow the user to specify a different XML file to parse.

examples/dom_parser/main.cc

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
#include <config.h>
2222
#endif
2323

24-
#include "../testutilities.h"
2524
#include <libxml++/libxml++.h>
2625
#include <iostream>
2726
#include <cstdlib>
2827

2928
void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
3029
{
31-
const Glib::ustring indent(indentation, ' ');
30+
const std::string indent(indentation, ' ');
3231
std::cout << std::endl; //Separate nodes by an empty line.
3332

3433
const auto nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
@@ -46,8 +45,8 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
4645

4746
std::cout << indent << "Node name = ";
4847
if(!namespace_prefix.empty())
49-
std::cout << CatchConvertError(namespace_prefix) << ":";
50-
std::cout << CatchConvertError(nodename) << std::endl;
48+
std::cout << namespace_prefix << ":";
49+
std::cout << nodename << std::endl;
5150
}
5251
else if(nodeText) //Let's say when it's text. - e.g. let's say what that white space is.
5352
{
@@ -57,15 +56,15 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
5756
//Treat the various node types differently:
5857
if(nodeText)
5958
{
60-
std::cout << indent << "text = \"" << CatchConvertError(nodeText->get_content()) << "\"" << std::endl;
59+
std::cout << indent << "text = \"" << nodeText->get_content() << "\"" << std::endl;
6160
}
6261
else if(nodeComment)
6362
{
64-
std::cout << indent << "comment = " << CatchConvertError(nodeComment->get_content()) << std::endl;
63+
std::cout << indent << "comment = " << nodeComment->get_content() << std::endl;
6564
}
6665
else if(nodeContent)
6766
{
68-
std::cout << indent << "content = " << CatchConvertError(nodeContent->get_content()) << std::endl;
67+
std::cout << indent << "content = " << nodeContent->get_content() << std::endl;
6968
}
7069
else if(const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(node))
7170
{
@@ -81,9 +80,9 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
8180

8281
std::cout << indent << " Attribute ";
8382
if(!namespace_prefix.empty())
84-
std::cout << CatchConvertError(namespace_prefix) << ":";
85-
std::cout << CatchConvertError(attribute->get_name()) << " = "
86-
<< CatchConvertError(attribute->get_value()) << std::endl;
83+
std::cout << namespace_prefix << ":";
84+
std::cout << attribute->get_name() << " = "
85+
<< attribute->get_value() << std::endl;
8786
}
8887

8988
const auto attribute = nodeElement->get_attribute("title");
@@ -94,7 +93,7 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
9493
std::cout << "AttributeNode ";
9594
else if (dynamic_cast<const xmlpp::AttributeDeclaration*>(attribute))
9695
std::cout << "AttributeDeclaration ";
97-
std::cout << "title = " << CatchConvertError(attribute->get_value()) << std::endl;
96+
std::cout << "title = " << attribute->get_value() << std::endl;
9897
}
9998
}
10099

@@ -110,10 +109,6 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
110109

111110
int main(int argc, char* argv[])
112111
{
113-
// Set the global C++ locale to the user-specified locale. Then we can
114-
// hopefully use std::cout with UTF-8, via Glib::ustring, without exceptions.
115-
std::locale::global(std::locale(""));
116-
117112
bool validate = false;
118113
bool set_throw_messages = false;
119114
bool throw_messages = false;

examples/dom_parser_raw/main.cc

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <iostream>
2323
#include <fstream>
24-
#include <glibmm/convert.h>
2524
#include <stdlib.h>
2625

2726
void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
@@ -57,10 +56,6 @@ std::string read_from_disk(const std::string& filepath)
5756

5857
int main(int argc, char* argv[])
5958
{
60-
// Set the global C++ locale to the user-configured locale,
61-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
62-
std::locale::global(std::locale(""));
63-
6459
std::string filepath;
6560
if(argc > 1 )
6661
filepath = argv[1]; //Allow the user to specify a different XML file to parse.
@@ -77,26 +72,19 @@ int main(int argc, char* argv[])
7772
auto contents = read_from_disk(filepath);
7873
std::string contents_ucs2;
7974

80-
try
81-
{
82-
contents_ucs2 = Glib::convert(contents, "UCS-2", "UTF-8");
83-
}
84-
catch(const Glib::Error& ex)
85-
{
86-
std::cerr << "Glib::convert failed: " << ex.what() << std::endl;
87-
}
88-
89-
parser.parse_memory_raw((const unsigned char*)contents_ucs2.c_str(), contents_ucs2.size());
75+
// TODO: Convert to UCS2 (previously we used Glib::convert()) and pass that to parse_memory_raw().
76+
//
9077

9178
//Look at the first few bytes, to see whether it really looks like UCS2.
9279
//Because UCS2 uses 2 bytes, we would expect every second byte to be zero for our simple example:
93-
std::cout << "First 10 bytes of the UCS-2 data:" << std::endl;
94-
for(std::string::size_type i = 0; (i < 10) && (i < contents_ucs2.size()); ++i)
95-
{
96-
std::cout << std::hex << (int)contents_ucs2[i] << ", ";
97-
}
98-
std::cout << std::endl;
99-
80+
// std::cout << "First 10 bytes of the UCS-2 data:" << std::endl;
81+
// for(std::string::size_type i = 0; (i < 10) && (i < contents_ucs2.size()); ++i)
82+
// {
83+
// std::cout << std::hex << (int)contents_ucs2[i] << ", ";
84+
// }
85+
// std::cout << std::endl;
86+
87+
parser.parse_memory_raw((const unsigned char*)contents.c_str(), contents.size());
10088
if(parser)
10189
{
10290
//Walk the tree:

examples/dom_read_write/main.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
int
3131
main(int argc, char* argv[])
3232
{
33-
// Set the global C and C++ locale to the user-configured locale,
34-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
35-
std::locale::global(std::locale(""));
36-
3733
//Parse command-line arguments:
3834
std::string filepath_in;
3935
std::string filepath_out;

examples/dom_update_namespace/main.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <libxml++/libxml++.h>
2424
#include <iostream>
25+
#include <sstream>
2526
#include <cstdlib>
2627
#include <exception>
2728

@@ -176,10 +177,6 @@ void Tests::fail(const RefType& reference, const ValueType& value, const std::st
176177
int
177178
main(int /* argc */, char** /* argv */)
178179
{
179-
// Set the global C and C++ locale to the user-configured locale,
180-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
181-
std::locale::global(std::locale(""));
182-
183180
TestNamespace tests;
184181

185182
try

examples/dom_xinclude/main.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
2828
{
29-
const Glib::ustring indent(indentation, ' ');
29+
const std::string indent(indentation, ' ');
3030

3131
const auto nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
3232
const auto nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
@@ -108,10 +108,6 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
108108

109109
int main(int argc, char* argv[])
110110
{
111-
// Set the global C++ locale to the user-configured locale,
112-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
113-
std::locale::global(std::locale(""));
114-
115111
bool validate = false;
116112
bool set_throw_messages = false;
117113
bool throw_messages = false;

examples/dom_xpath/main.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <stdlib.h>
2626
#include <iostream>
2727

28-
Glib::ustring result_type_to_ustring(xmlpp::XPathResultType result_type)
28+
std::string result_type_to_ustring(xmlpp::XPathResultType result_type)
2929
{
3030
switch (result_type)
3131
{
@@ -40,7 +40,7 @@ Glib::ustring result_type_to_ustring(xmlpp::XPathResultType result_type)
4040
}
4141
}
4242

43-
bool xpath_test(const xmlpp::Node* node, const Glib::ustring& xpath)
43+
bool xpath_test(const xmlpp::Node* node, const std::string& xpath)
4444
{
4545
bool result = true;
4646
std::cout << std::endl; //Separate tests by an empty line.
@@ -103,10 +103,6 @@ bool xpath_test(const xmlpp::Node* node, const Glib::ustring& xpath)
103103

104104
int main(int argc, char* argv[])
105105
{
106-
// Set the global C++ locale to the user-configured locale,
107-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
108-
std::locale::global(std::locale(""));
109-
110106
std::string filepath;
111107
if (argc > 1)
112108
filepath = argv[1]; //Allow the user to specify a different XML file to parse.

examples/dtdvalidation/main.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828

2929
int main(int argc, char* argv[])
3030
{
31-
// Set the global C and C++ locale to the user-configured locale,
32-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
33-
std::locale::global(std::locale(""));
34-
3531
std::string dtdfilepath;
3632
if(argc > 1)
3733
dtdfilepath = argv[1]; //Allow the user to specify a different dtd file to use.

examples/import_node/main.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <iostream>
22
#include <stdexcept>
3-
#include <glibmm/ustring.h>
43
#include <cstdlib>
54
#include <libxml++/libxml++.h>
65

@@ -9,10 +8,6 @@ using namespace std;
98

109
int main (int /* argc */, char** /* argv */)
1110
{
12-
// Set the global C and C++ locale to the user-configured locale,
13-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
14-
std::locale::global(std::locale(""));
15-
1611
try
1712
{
1813
DomParser example1("example1.xml");

examples/sax_exception/main.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131

3232
int main(int /* argc */, char** /* argv */)
3333
{
34-
// Set the global C and C++ locale to the user-configured locale,
35-
// so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
36-
std::locale::global(std::locale(""));
37-
3834
MySaxParser parser;
3935

4036
try

0 commit comments

Comments
 (0)