GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixPresentation/tmp_project/PhoenixInkscape/tmp_project/PhoenixXml/src/pxml_utils.cpp
Date: 2025-03-24 18:12:43
Exec Total Coverage
Lines: 188 203 92.6%
Branches: 265 369 71.8%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 ///List of allowed char as balise name
8 #define ALLOWED_BALISE_CHAR "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:?!-"
9
10 ///List of allowed char as attribute name
11 #define ALLOWED_ATTRIBUTE_CHAR "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:-"
12
13 #include "pxml_utils.h"
14
15 ///Set the PFileParser for xml
16 /** @param fileContent : content to be parsed
17 * @param isSvg : true if the parsed file is a svg
18 * @return PFileParser
19 */
20 31128 PFileParser pxml_setXmlParser(const PString & fileContent, bool isSvg){
21 31128 PFileParser parser;
22
2/2
✓ Branch 1 taken 31128 times.
✓ Branch 4 taken 31128 times.
31128 parser.setSeparator("<>\"=");
23
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 31120 times.
31128 if(isSvg){
24
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 parser.setWhiteSpace("");
25 }else{
26
2/2
✓ Branch 1 taken 31120 times.
✓ Branch 4 taken 31120 times.
31120 parser.setWhiteSpace("\t\n ");
27 }
28
1/1
✓ Branch 1 taken 31128 times.
31128 parser.setFileContent(fileContent);
29 31128 return parser;
30 }
31
32 ///Parse a PXml with a file
33 /** @param[out] xml : PXml to be initialised
34 * @param fileName : name of the intialisation file
35 * @param isSvg : true if the parsed file is a svg
36 * @return true on success, false otherwise
37 */
38 31116 bool pxml_parserFile(PXml & xml, const PPath & fileName, bool isSvg){
39
1/1
✓ Branch 2 taken 31116 times.
31116 return pxml_parserContent(xml, fileName.loadFileContent(), isSvg);
40 }
41
42 ///Parse a PXml with a file content
43 /** @param[out] xml : PXml to be initialised
44 * @param fileContent : file content
45 * @param isSvg : true if the parsed file is a svg
46 * @return true on success, false otherwise
47 */
48 31128 bool pxml_parserContent(PXml & xml, const PString & fileContent, bool isSvg){
49
1/1
✓ Branch 1 taken 31128 times.
31128 PFileParser parser(pxml_setXmlParser(fileContent, isSvg));
50
2/2
✓ Branch 1 taken 31128 times.
✓ Branch 4 taken 31128 times.
31128 xml.setName("root");
51
52
1/1
✓ Branch 1 taken 31128 times.
62256 return pxml_parserXmlContent(xml, parser, true);
53
54 // return pxml_parserVecXml(xml.getVecChild(), parser, isSvg);
55 31128 }
56
57 ///Say if it is the end of the attribute definition of the current balise
58 /** @param[out] parent : xml parent in wich to set the isCompact attribute
59 * @param[out] parser : parser to be used
60 * @return true if the attribute end is reached, false if not
61 */
62 3345284 bool pxml_isAttributeEnd(PXml & parent, PFileParser & parser){
63
3/3
✓ Branch 2 taken 3345284 times.
✓ Branch 5 taken 4600 times.
✓ Branch 6 taken 3340684 times.
3345284 if(parser.isMatch("/>")){
64 4600 parent.setIsCompact(true);
65 4600 return true;
66
3/3
✓ Branch 2 taken 3340684 times.
✓ Branch 5 taken 2926091 times.
✓ Branch 6 taken 414593 times.
3340684 }else if(parser.isMatch(">")){
67 2926091 parent.setIsCompact(false);
68 2926091 return true;
69 }else{
70 414593 return false;
71 }
72 }
73
74 ///Parse the attribute of a xml balise
75 /** @param[out] parent : xml parent in wich to put the attribute
76 * @param[out] parser : parser to be used
77 * @return true on success, false otherwise
78 */
79 2930691 bool pxml_parserXmlAttribute(PXml & parent, PFileParser & parser){
80
1/1
✓ Branch 2 taken 2930691 times.
2930691 parser.setWhiteSpace(" \t\n");
81
5/6
✓ Branch 1 taken 414593 times.
✓ Branch 2 taken 2930691 times.
✓ Branch 4 taken 414593 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414593 times.
✓ Branch 7 taken 2930691 times.
3345284 while(!pxml_isAttributeEnd(parent, parser) && !parser.isEndOfFile()){
82
2/2
✓ Branch 1 taken 414593 times.
✓ Branch 4 taken 414593 times.
414593 PString attributeName(parser.getStrComposedOf(ALLOWED_ATTRIBUTE_CHAR));
83
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 414593 times.
414593 if(attributeName == ""){
84 std::cerr << "pxml_parserXmlAttribute : error at : " << parser.getLocation() << std::endl;
85 std::cerr << "\tcannot parse the attributes name as '"<<parser.getNextToken()<<"'" << std::endl;
86 return false;
87 }
88
3/4
✓ Branch 1 taken 414593 times.
✓ Branch 4 taken 414593 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 414593 times.
414593 if(!parser.isMatch("=")){
89 std::cerr << "pxml_parserXmlAttribute : error at : " << parser.getLocation() << std::endl;
90 std::cerr << "\texpected '=' after attribute '"<<attributeName<<"'" << std::endl;
91 return false;
92 }
93
3/4
✓ Branch 1 taken 414593 times.
✓ Branch 4 taken 414593 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 414593 times.
414593 if(!parser.isMatch("\"")){
94 std::cerr << "pxml_parserXmlAttribute : error at : " << parser.getLocation() << std::endl;
95 std::cerr << "\texpected '\"' after attribute '"<<attributeName<<"='" << std::endl;
96 return false;
97 }
98
2/2
✓ Branch 1 taken 414593 times.
✓ Branch 4 taken 414593 times.
414593 PString attributeValue(parser.getUntilKeyWithoutPatern("\""));
99
1/1
✓ Branch 1 taken 414593 times.
414593 PXmlAttr tmpAttribute;
100
1/1
✓ Branch 1 taken 414593 times.
414593 tmpAttribute.setName(attributeName);
101
1/1
✓ Branch 1 taken 414593 times.
414593 tmpAttribute.setValue(attributeValue);
102
2/2
✓ Branch 1 taken 414593 times.
✓ Branch 4 taken 414593 times.
414593 parent.getVecAttr().push_back(tmpAttribute);
103
1/2
✓ Branch 3 taken 414593 times.
✗ Branch 4 not taken.
414593 }
104
1/1
✓ Branch 2 taken 2930691 times.
2930691 parser.setWhiteSpace("");
105 2930691 return true;
106 }
107
108
109 ///Parse the content of an xml balise
110 /** @param[out] parent : xml parent in wich to put the content
111 * @param[out] parser : parser to be used
112 * @param isMainBalise : true if the parent balise if the main one, false otherwise
113 * @return true on success, false otherwise
114 */
115 2957219 bool pxml_parserXmlContent(PXml & parent, PFileParser & parser, bool isMainBalise){
116
2/2
✓ Branch 1 taken 2957219 times.
✓ Branch 4 taken 2957219 times.
2957219 parser.setSeparator("<>\"=");
117
2/2
✓ Branch 1 taken 2957219 times.
✓ Branch 4 taken 2957219 times.
2957219 parser.setWhiteSpace("");
118
4/4
✓ Branch 1 taken 2957219 times.
✓ Branch 4 taken 2957219 times.
✓ Branch 7 taken 2957219 times.
✓ Branch 10 taken 2957219 times.
5914438 PString balisePartialEnd("/" + parent.getName() + ">");
119
2/2
✓ Branch 1 taken 2957219 times.
✓ Branch 4 taken 2957219 times.
2957219 PString baliseEnd("<" + balisePartialEnd);
120
1/1
✓ Branch 1 taken 2957219 times.
2957219 PXml text;
121
1/1
✓ Branch 1 taken 2957219 times.
2957219 text.setIsText(true);
122
8/8
✓ Branch 1 taken 5896689 times.
✓ Branch 3 taken 5896644 times.
✓ Branch 4 taken 45 times.
✓ Branch 6 taken 5896644 times.
✓ Branch 8 taken 5896637 times.
✓ Branch 9 taken 7 times.
✓ Branch 10 taken 5896637 times.
✓ Branch 11 taken 52 times.
5896689 while(!parser.isMatch(baliseEnd) && !parser.isEndOfFile()){
123
2/2
✓ Branch 1 taken 5896637 times.
✓ Branch 4 taken 5896637 times.
5896637 PString textString(parser.getUntilKeyWithoutPatern("<"));
124
2/2
✓ Branch 1 taken 5894331 times.
✓ Branch 2 taken 2306 times.
5896637 if(textString != ""){ //If the next token is not a < it is a text
125
2/2
✓ Branch 1 taken 5894331 times.
✓ Branch 4 taken 5894331 times.
5894331 text.getValue() += textString;
126
3/3
✓ Branch 1 taken 5894331 times.
✓ Branch 4 taken 2954965 times.
✓ Branch 5 taken 2939366 times.
5894331 if(parent.getVecChild().size() == 0lu){
127
3/3
✓ Branch 1 taken 2954965 times.
✓ Branch 3 taken 2409087 times.
✓ Branch 4 taken 545878 times.
2954965 if(parser.isMatch(balisePartialEnd)){
128
2/2
✓ Branch 1 taken 2409087 times.
✓ Branch 4 taken 2409087 times.
2409087 parent.setValue(text.getValue());
129 2409087 return true;
130 }else{
131
2/2
✓ Branch 1 taken 545878 times.
✓ Branch 4 taken 545878 times.
545878 parent.getVecChild().push_back(text);
132 }
133 }else{
134
2/2
✓ Branch 1 taken 2939366 times.
✓ Branch 4 taken 2939366 times.
2939366 parent.getVecChild().push_back(text);
135 }
136
2/2
✓ Branch 1 taken 3485244 times.
✓ Branch 4 taken 3485244 times.
3485244 text.setValue(""); //Reset value for next one
137 }
138
3/3
✓ Branch 1 taken 3487550 times.
✓ Branch 3 taken 31121 times.
✓ Branch 4 taken 3456429 times.
3487550 if(parser.isEndOfFile()){
139
2/2
✓ Branch 0 taken 31120 times.
✓ Branch 1 taken 1 times.
31121 if(isMainBalise){
140 31120 return true;
141 }else{
142
4/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 std::cerr << "pxml_parserXmlContent : error at : " << parser.getLocation() << std::endl;
143
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
1 std::cerr << "\tunexpected end of file. We are supposed to be in the balise '"<<parent.getName()<<"'" << std::endl;
144 1 return false;
145 }
146 }
147
3/3
✓ Branch 1 taken 3456429 times.
✓ Branch 3 taken 516958 times.
✓ Branch 4 taken 2939471 times.
3456429 if(parser.isMatch(balisePartialEnd)){ //We find the end of the balise
148 516958 return true;
149 }else{ //Or it can be another balise
150
2/2
✓ Branch 1 taken 2939471 times.
✓ Branch 4 taken 2939471 times.
2939471 PString childBaliseName(parser.getStrComposedOf(ALLOWED_BALISE_CHAR));
151
1/2
✓ Branch 1 taken 2939471 times.
✗ Branch 2 not taken.
2939471 if(childBaliseName != ""){ //We find a new balise
152
1/1
✓ Branch 1 taken 2939471 times.
2939471 PXml xml;
153
1/1
✓ Branch 1 taken 2939471 times.
2939471 xml.setName(childBaliseName);
154
2/2
✓ Branch 1 taken 8778 times.
✓ Branch 2 taken 2930693 times.
2939471 if(childBaliseName == "!--"){
155
2/2
✓ Branch 1 taken 8778 times.
✓ Branch 4 taken 8778 times.
8778 parser.getUntilKeyWithoutPatern("-->"); //Skip the comment
156
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2930691 times.
2930693 }else if(childBaliseName == "?xml"){
157
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 parser.getUntilKeyWithoutPatern("?>"); //Skip the svg balise
158 }else{
159
2/3
✓ Branch 1 taken 2930691 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2930691 times.
2930691 if(!pxml_parserXmlAttribute(xml, parser)){ //Let's parse the attribute
160 std::cerr << "pxml_parserXmlContent : error at : " << parser.getLocation() << std::endl;
161 std::cerr << "\tcannot parse the attributes of balise '"<<childBaliseName<<"'" << std::endl;
162 return false;
163 }
164
3/3
✓ Branch 1 taken 2930691 times.
✓ Branch 3 taken 2926091 times.
✓ Branch 4 taken 4600 times.
2930691 if(!xml.getIsCompact()){
165 //Let's parse the content
166
3/3
✓ Branch 1 taken 2926091 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2926090 times.
2926091 if(!pxml_parserXmlContent(xml, parser, false)){
167
4/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 std::cerr << "pxml_parserXmlContent : error at : " << parser.getLocation() << std::endl;
168
4/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 std::cerr << "\tcannot parse balise '"<<childBaliseName<<"'" << std::endl;
169 1 return false;
170 }
171 }
172
2/2
✓ Branch 1 taken 2930690 times.
✓ Branch 4 taken 2930690 times.
2930690 parent.getVecChild().push_back(xml);
173 }
174
2/8
✓ Branch 1 taken 2939470 times.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
2939471 }else if(parser.isMatch("/")){
175 std::cerr << "pxml_parserXmlContent : in balise '"<<parent.getName()<<"' unexpected '</' at : " << parser.getLocation() << std::endl;
176 return false;
177 }else{ //It was just a text <
178 text.getValue() += "<";
179 }
180
2/2
✓ Branch 1 taken 2939470 times.
✓ Branch 2 taken 1 times.
2939471 }
181
2/2
✓ Branch 1 taken 2939470 times.
✓ Branch 2 taken 2957167 times.
5896637 }
182 52 return true;
183 2957219 }
184
185
186
187
188
189
190
191 ///Get the vector of childs with given name if exist
192 /** @param[out] vecMatch : vector of matched childs
193 * @param xml : xml input
194 * @param childName : name of the searched childs
195 * @return true if the childs exist, false otherwise
196 */
197 401510 bool pxml_getVecChildIfExist(PVecXml & vecMatch, const PXml & xml, const PString & childName){
198 401510 bool isFound(false);
199 401510 const PVecXml & vecChild = xml.getVecChild();
200
2/2
✓ Branch 4 taken 5969946 times.
✓ Branch 5 taken 401510 times.
6371456 for(PVecXml::const_iterator it(vecChild.begin()); it != vecChild.end(); ++it){
201
3/3
✓ Branch 2 taken 5969946 times.
✓ Branch 5 taken 2371743 times.
✓ Branch 6 taken 3598203 times.
5969946 if(it->getName() == childName){
202
1/1
✓ Branch 2 taken 2371743 times.
2371743 vecMatch.push_back(*it);
203 2371743 isFound = true;
204 }
205 }
206 401510 return isFound;
207 }
208
209 ///Get the child with given name if exist
210 /** @param[out] match : matched child
211 * @param xml : xml input
212 * @param childName : name of the searched child
213 * @return true if the child exist, false otherwise
214 */
215 1961838 bool pxml_getChildIfExist(PXml & match, const PXml & xml, const PString & childName){
216 1961838 bool isSearched(true);
217
1/1
✓ Branch 1 taken 1961838 times.
1961838 const PVecXml & vecChild = xml.getVecChild();
218 1961838 PVecXml::const_iterator it(vecChild.begin());
219
6/6
✓ Branch 2 taken 28939272 times.
✓ Branch 3 taken 1540589 times.
✓ Branch 4 taken 28518023 times.
✓ Branch 5 taken 421249 times.
✓ Branch 6 taken 28518023 times.
✓ Branch 7 taken 1961838 times.
30479861 while(it != vecChild.end() && isSearched){
220
3/3
✓ Branch 2 taken 28518023 times.
✓ Branch 5 taken 421251 times.
✓ Branch 6 taken 28096772 times.
28518023 if(it->getName() == childName){
221
1/1
✓ Branch 2 taken 421251 times.
421251 match = *it;
222 421251 isSearched = false;
223 }
224 28518023 ++it;
225 }
226 1961838 return !isSearched;
227 }
228
229 ///Get the child with given name if exist
230 /** @param xml : xml input
231 * @param childName : name of the searched child
232 * @return pointer to the existing child, NULL otherwise
233 */
234 17 PXml * pxml_getChildPtr(PXml & xml, const PString & childName){
235 17 PXml * out = NULL;
236 17 PVecXml & vecChild = xml.getVecChild();
237
5/6
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 37 times.
✓ Branch 7 taken 17 times.
✓ Branch 8 taken 37 times.
✓ Branch 9 taken 17 times.
54 for(PVecXml::iterator it(vecChild.begin()); it != vecChild.end() && out == NULL; ++it){
238
3/3
✓ Branch 2 taken 37 times.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 20 times.
37 if(it->getName() == childName){
239 17 out = &(*it);
240 }
241 }
242 17 return out;
243 }
244
245 ///Get the attribute with given name if exist
246 /** @param[out] attr : vector of matched child
247 * @param xml : xml input
248 * @param attrName : name of the searched child
249 * @return true if the attribute exists, false otherwise
250 */
251 555111 bool pxml_getAttrIfExist(PXmlAttr & attr, const PXml & xml, const PString & attrName){
252 555111 bool isSearched(true);
253
1/1
✓ Branch 1 taken 555111 times.
555111 const PVecXmlAttr & vecAttr = xml.getVecAttr();
254 555111 PVecXmlAttr::const_iterator it(vecAttr.begin());
255
6/6
✓ Branch 2 taken 482732 times.
✓ Branch 3 taken 548517 times.
✓ Branch 4 taken 476138 times.
✓ Branch 5 taken 6594 times.
✓ Branch 6 taken 476138 times.
✓ Branch 7 taken 555111 times.
1031249 while(it != vecAttr.end() && isSearched){
256
3/3
✓ Branch 2 taken 476138 times.
✓ Branch 5 taken 392743 times.
✓ Branch 6 taken 83395 times.
476138 if(it->getName() == attrName){
257
1/1
✓ Branch 2 taken 392743 times.
392743 attr = *it;
258 392743 isSearched = false;
259 }
260 476138 ++it;
261 }
262 555111 return !isSearched;
263 }
264
265 ///Set a value to an attribute
266 /** @param[out] xml : xml to be modified
267 * @param nameAttr : name of the attribute
268 * @param valueAttr : value of the attribute
269 */
270 65 void pxml_setAttr(PXml & xml, const PString & nameAttr, const PString & valueAttr){
271 65 bool isSearched(true);
272
1/1
✓ Branch 1 taken 65 times.
65 PVecXmlAttr & vecAttr = xml.getVecAttr();
273 65 PVecXmlAttr::iterator it(vecAttr.begin());
274
6/6
✓ Branch 2 taken 290 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 241 times.
✓ Branch 5 taken 49 times.
✓ Branch 6 taken 241 times.
✓ Branch 7 taken 65 times.
306 while(it != vecAttr.end() && isSearched){
275
3/3
✓ Branch 2 taken 241 times.
✓ Branch 5 taken 61 times.
✓ Branch 6 taken 180 times.
241 if(it->getName() == nameAttr){
276
1/1
✓ Branch 2 taken 61 times.
61 it->setValue(valueAttr);
277 61 isSearched = false;
278 }
279 241 ++it;
280 }
281 65 }
282
283 ///Erase the childs of the current xml if it has childName as name
284 /** @param xml : current input
285 * @param childName : name of the childs to be erased
286 * @return output xml without childs named childName
287 */
288 2 PXml pxml_eraseVecChild(const PXml & xml, const PString & childName){
289 2 PXml out;
290
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 out.setName(xml.getName());
291
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 out.setValue(xml.getValue());
292
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 out.setVecAttr(xml.getVecAttr());
293
1/1
✓ Branch 1 taken 2 times.
2 const PVecXml & vecXml = xml.getVecChild();
294
2/2
✓ Branch 4 taken 37 times.
✓ Branch 5 taken 2 times.
39 for(PVecXml::const_iterator it(vecXml.begin()); it != vecXml.end(); ++it){
295
3/3
✓ Branch 2 taken 37 times.
✓ Branch 5 taken 19 times.
✓ Branch 6 taken 18 times.
37 if(it->getName() != childName){
296
2/2
✓ Branch 1 taken 19 times.
✓ Branch 5 taken 19 times.
19 out.getVecChild().push_back(*it);
297 }
298 }
299 2 return out;
300 }
301
302 ///Save a xml in a file
303 /** @param fileName : name of the output file
304 * @param xml : xml to be saved
305 * @param isSvg : say if the output xml has to be SVG like (with no space between chevron and newline between attribute
306 * @return true on success, false otherwise
307 */
308 4 bool pxml_saveFile(const PPath & fileName, const PXml & xml, bool isSvg){
309
1/1
✓ Branch 1 taken 4 times.
4 PString body(pxml_baliseStr(xml, isSvg));
310
1/1
✓ Branch 1 taken 4 times.
8 return fileName.saveFileContent(body);
311 4 }
312
313 ///Convert xml in string
314 /** @param xml : xml to be converted into string
315 * @param isSvg : say if the output xml has to be SVG like (with no space between chevron and newline between attribute
316 * @return output string
317 */
318 89193 PString pxml_baliseStr(const PXml & xml, bool isSvg){
319
3/3
✓ Branch 1 taken 89193 times.
✓ Branch 4 taken 89193 times.
✓ Branch 7 taken 89193 times.
89193 PString body(""), name(xml.getName());
320
1/1
✓ Branch 1 taken 89193 times.
89193 PString baseXmlNewLine("\n");
321
2/2
✓ Branch 0 taken 89059 times.
✓ Branch 1 taken 134 times.
89193 if(isSvg){
322
1/1
✓ Branch 1 taken 89059 times.
89059 baseXmlNewLine = "";
323 }
324
3/3
✓ Branch 1 taken 89193 times.
✓ Branch 3 taken 45440 times.
✓ Branch 4 taken 43753 times.
89193 if(xml.getIsText()){
325
2/2
✓ Branch 1 taken 45440 times.
✓ Branch 4 taken 45440 times.
45440 body += xml.getValue();
326 }else{
327
2/2
✓ Branch 1 taken 43740 times.
✓ Branch 2 taken 13 times.
43753 if(name != ""){
328
1/1
✓ Branch 1 taken 43740 times.
43740 body += "<";
329
1/1
✓ Branch 1 taken 43740 times.
43740 body += name;
330
3/3
✓ Branch 1 taken 43740 times.
✓ Branch 4 taken 43740 times.
✓ Branch 7 taken 43740 times.
43740 body += pxml_vecAttrStr(xml.getVecAttr(), isSvg);
331
332
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 43740 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
43740 if(name == "?xml"){body += " ?>\n";}
333
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 43740 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
43740 else if(name == "!--"){body += " -->\n";}
334
3/3
✓ Branch 1 taken 43740 times.
✓ Branch 3 taken 41090 times.
✓ Branch 4 taken 2650 times.
43740 else if(xml.getIsCompact()){
335
2/2
✓ Branch 1 taken 41090 times.
✓ Branch 4 taken 41090 times.
41090 body += " />"+baseXmlNewLine;
336 }else{
337
2/2
✓ Branch 1 taken 2650 times.
✓ Branch 4 taken 2650 times.
2650 body += ">"+baseXmlNewLine;
338
3/3
✓ Branch 1 taken 2650 times.
✓ Branch 4 taken 2650 times.
✓ Branch 7 taken 2650 times.
2650 body += pxml_vecXmlStr(xml.getVecChild(), isSvg);
339
2/2
✓ Branch 1 taken 2650 times.
✓ Branch 4 taken 2650 times.
2650 body += xml.getValue();
340
4/4
✓ Branch 1 taken 2650 times.
✓ Branch 4 taken 2650 times.
✓ Branch 7 taken 2650 times.
✓ Branch 10 taken 2650 times.
2650 body += "</"+ name + ">" + baseXmlNewLine;
341 }
342 }else{
343
344
3/3
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 13 times.
13 body += pxml_vecXmlStr(xml.getVecChild(), isSvg);
345 }
346 }
347 178386 return body;
348 89193 }
349
350 ///Convert a vecto of xml in string
351 /** @param vecXml : vecor of xml to be converted into string
352 * @param isSvg : say if the output xml has to be SVG like (with no space between chevron and newline between attribute
353 * @return output string
354 */
355 2670 PString pxml_vecXmlStr(const PVecXml & vecXml, bool isSvg){
356 2670 PString body("");
357
2/2
✓ Branch 3 taken 89167 times.
✓ Branch 4 taken 2670 times.
91837 for(PVecXml::const_iterator it(vecXml.begin()); it != vecXml.end(); ++it){
358
2/2
✓ Branch 2 taken 89167 times.
✓ Branch 5 taken 89167 times.
89167 body += pxml_baliseStr(*it, isSvg);
359 }
360 2670 return body;
361 }
362
363 ///Convert attribute in string
364 /** @param xmlAttr : xml attribute to be converted into string
365 * @param isSvg : say if the output xml has to be SVG like (with no space between chevron and newline between attribute
366 * @return output string
367 */
368 194165 PString pxml_attrStr(const PXmlAttr & xmlAttr, bool isSvg){
369 194165 PString body(" ");
370
6/6
✓ Branch 1 taken 194165 times.
✓ Branch 4 taken 194165 times.
✓ Branch 7 taken 194165 times.
✓ Branch 10 taken 194165 times.
✓ Branch 13 taken 194165 times.
✓ Branch 16 taken 194165 times.
194165 body += xmlAttr.getName() + "=\"" + xmlAttr.getValue() + "\"";
371
2/2
✓ Branch 0 taken 194158 times.
✓ Branch 1 taken 7 times.
194165 if(isSvg){
372
1/1
✓ Branch 1 taken 194158 times.
194158 body += "\n\t";
373 }
374 194165 return body;
375 }
376
377 ///Convert attributes in string
378 /** @param vecXmlAttr : xml attributes to be converted into string
379 * @param isSvg : say if the output xml has to be SVG like (with no space between chevron and newline between attribute
380 * @return output string
381 */
382 43740 PString pxml_vecAttrStr(const PVecXmlAttr & vecXmlAttr, bool isSvg){
383
3/3
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 43639 times.
✓ Branch 4 taken 101 times.
43740 if(vecXmlAttr.size() == 0lu){return "";}
384
1/1
✓ Branch 1 taken 43639 times.
43639 PString body("");
385
2/2
✓ Branch 3 taken 194165 times.
✓ Branch 4 taken 43639 times.
237804 for(PVecXmlAttr::const_iterator it(vecXmlAttr.begin()); it != vecXmlAttr.end(); ++it){
386
2/2
✓ Branch 2 taken 194165 times.
✓ Branch 5 taken 194165 times.
194165 body += pxml_attrStr(*it, isSvg);
387 }
388
1/1
✓ Branch 1 taken 43639 times.
43639 return body;
389 43639 }
390
391 ///Get the content of the PXml (children or value)
392 /** @param xml : PXml to be used
393 * @return content of the PXml (children or value)
394 */
395 2621888 PString pxml_getFullContent(const PXml & xml){
396 2621888 const PVecXml & vecXml = xml.getVecChild();
397
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2621881 times.
2621888 if(vecXml.size() != 0lu){
398 7 return pxml_vecXmlStr(vecXml);
399 }else{
400 2621881 return xml.getValue();
401 }
402 }
403
404
405