@@ -25,7 +25,8 @@ static void rapidxml_DocumentObject_dealloc(rapidxml_DocumentObject* self) {
2525
2626static int _parse (rapidxml_DocumentObject* self,
2727 Py_buffer* text_buff,
28- bool from_file, bool parse_cdata=false ) {
28+ bool from_file,
29+ bool parse_cdata) {
2930 const char * text;
3031 std::vector<char > text_vector;
3132
@@ -43,17 +44,14 @@ static int _parse(rapidxml_DocumentObject* self,
4344 }
4445 try {
4546 self->base .base .document ->clear ();
46- if (!parse_cdata){
47- (self->base .base .document
48- ->parse <rapidxml::parse_no_utf8 | rapidxml::parse_no_data_nodes>)
49- (self->base .base .document ->allocate_string (text));
50-
51- }else {
52- (self->base .base .document
53- ->parse <rapidxml::parse_declaration_node>)
54- (self->base .base .document ->allocate_string (text));
55- }
56-
47+ char * data = self->base .base .document ->allocate_string (text);
48+ if (!parse_cdata) {
49+ (self->base .base .document
50+ ->parse <rapidxml::parse_no_utf8 | rapidxml::parse_no_data_nodes>)(data);
51+ } else {
52+ (self->base .base .document
53+ ->parse <rapidxml::parse_declaration_node>)(data);
54+ }
5755 } catch (rapidxml::parse_error &e) {
5856 PyErr_SetString (rapidxml_RapidXmlError, e.what ());
5957 return 0 ;
@@ -78,7 +76,8 @@ static PyObject* rapidxml_DocumentObject_parse(rapidxml_DocumentObject* self,
7876 }
7977
8078 if (!_parse (self, &text_buff,
81- (from_file_obj != NULL ) && PyObject_IsTrue (from_file_obj), (read_cdata != NULL ) && PyObject_IsTrue (read_cdata))) {
79+ (from_file_obj != NULL ) && PyObject_IsTrue (from_file_obj),
80+ (read_cdata != NULL ) && PyObject_IsTrue (read_cdata))) {
8281 return NULL ;
8382 }
8483 Py_INCREF (Py_None);
@@ -106,7 +105,10 @@ static int rapidxml_DocumentObject_init(rapidxml_DocumentObject* self,
106105 self->base .base .underlying_obj = new rapidxml::xml_document<>();
107106 self->base .base .document = static_cast <rapidxml::xml_document<>*>(self->base .base .underlying_obj );
108107 if (text_buff.buf ) {
109- return _parse (self, &text_buff, (from_file_obj != NULL ) && PyObject_IsTrue (from_file_obj), (read_cdata != NULL ) && PyObject_IsTrue (read_cdata)) - 1 ;
108+ return (_parse (self, &text_buff,
109+ (from_file_obj != NULL ) && PyObject_IsTrue (from_file_obj),
110+ (read_cdata != NULL ) && PyObject_IsTrue (read_cdata))
111+ - 1 );
110112 }
111113 return 0 ;
112114}
0 commit comments