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 | 21 | PFileParser pxml_setXmlParser(const PString & fileContent, bool isSvg){ | |
21 | 21 | PFileParser parser; | |
22 |
2/2✓ Branch 0 (3→4) taken 21 times.
✓ Branch 2 (4→5) taken 21 times.
|
21 | parser.setSeparator("<>\"="); |
23 |
2/2✓ Branch 0 (6→7) taken 8 times.
✓ Branch 1 (6→11) taken 13 times.
|
21 | if(isSvg){ |
24 |
2/2✓ Branch 0 (7→8) taken 8 times.
✓ Branch 2 (8→9) taken 8 times.
|
8 | parser.setWhiteSpace(""); |
25 | }else{ | ||
26 |
2/2✓ Branch 0 (11→12) taken 13 times.
✓ Branch 2 (12→13) taken 13 times.
|
13 | parser.setWhiteSpace("\t\n "); |
27 | } | ||
28 |
1/1✓ Branch 0 (15→16) taken 21 times.
|
21 | parser.setFileContent(fileContent); |
29 | 21 | 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 | 9 | bool pxml_parserFile(PXml & xml, const PPath & fileName, bool isSvg){ | |
39 |
2/2✓ Branch 0 (2→3) taken 9 times.
✓ Branch 2 (3→4) taken 9 times.
|
9 | 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 | 21 | bool pxml_parserContent(PXml & xml, const PString & fileContent, bool isSvg){ | |
49 |
1/1✓ Branch 0 (2→3) taken 21 times.
|
21 | PFileParser parser(pxml_setXmlParser(fileContent, isSvg)); |
50 |
2/2✓ Branch 0 (3→4) taken 21 times.
✓ Branch 2 (4→5) taken 21 times.
|
21 | xml.setName("root"); |
51 | |||
52 |
1/1✓ Branch 0 (6→7) taken 21 times.
|
42 | return pxml_parserXmlContent(xml, parser, true); |
53 | |||
54 | // return pxml_parserVecXml(xml.getVecChild(), parser, isSvg); | ||
55 | 21 | } | |
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 | 83 | bool pxml_isAttributeEnd(PXml & parent, PFileParser & parser){ | |
63 |
4/4✓ Branch 0 (2→3) taken 83 times.
✓ Branch 2 (3→4) taken 83 times.
✓ Branch 4 (5→6) taken 1 times.
✓ Branch 5 (5→8) taken 82 times.
|
83 | if(parser.isMatch("/>")){ |
64 | 1 | parent.setIsCompact(true); | |
65 | 1 | return true; | |
66 |
4/4✓ Branch 0 (8→9) taken 82 times.
✓ Branch 2 (9→10) taken 82 times.
✓ Branch 4 (11→12) taken 72 times.
✓ Branch 5 (11→14) taken 10 times.
|
82 | }else if(parser.isMatch(">")){ |
67 | 72 | parent.setIsCompact(false); | |
68 | 72 | return true; | |
69 | }else{ | ||
70 | 10 | 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 | 73 | bool pxml_parserXmlAttribute(PXml & parent, PFileParser & parser){ | |
80 |
2/2✓ Branch 0 (2→3) taken 73 times.
✓ Branch 2 (3→4) taken 73 times.
|
73 | parser.setWhiteSpace(" \t\n"); |
81 |
5/6✓ Branch 0 (68→69) taken 10 times.
✓ Branch 1 (68→72) taken 73 times.
✓ Branch 2 (70→71) taken 10 times.
✗ Branch 3 (70→72) not taken.
✓ Branch 4 (73→6) taken 10 times.
✓ Branch 5 (73→74) taken 73 times.
|
83 | while(!pxml_isAttributeEnd(parent, parser) && !parser.isEndOfFile()){ |
82 |
2/2✓ Branch 0 (6→7) taken 10 times.
✓ Branch 2 (7→8) taken 10 times.
|
10 | PString attributeName(parser.getStrComposedOf(ALLOWED_ATTRIBUTE_CHAR)); |
83 |
2/3✓ Branch 0 (9→10) taken 10 times.
✗ Branch 2 (10→11) not taken.
✓ Branch 3 (10→23) taken 10 times.
|
10 | 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 0 (23→24) taken 10 times.
✓ Branch 2 (24→25) taken 10 times.
✗ Branch 4 (26→27) not taken.
✓ Branch 5 (26→37) taken 10 times.
|
10 | 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 0 (37→38) taken 10 times.
✓ Branch 2 (38→39) taken 10 times.
✗ Branch 4 (40→41) not taken.
✓ Branch 5 (40→51) taken 10 times.
|
10 | 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 0 (51→52) taken 10 times.
✓ Branch 2 (52→53) taken 10 times.
|
10 | PString attributeValue(parser.getUntilKeyWithoutPatern("\"")); |
99 |
1/1✓ Branch 0 (54→55) taken 10 times.
|
10 | PXmlAttr tmpAttribute; |
100 |
1/1✓ Branch 0 (55→56) taken 10 times.
|
10 | tmpAttribute.setName(attributeName); |
101 |
1/1✓ Branch 0 (56→57) taken 10 times.
|
10 | tmpAttribute.setValue(attributeValue); |
102 |
2/2✓ Branch 0 (57→58) taken 10 times.
✓ Branch 2 (58→59) taken 10 times.
|
10 | parent.getVecAttr().push_back(tmpAttribute); |
103 |
1/2✓ Branch 0 (63→64) taken 10 times.
✗ Branch 1 (63→66) not taken.
|
10 | } |
104 |
2/2✓ Branch 0 (74→75) taken 73 times.
✓ Branch 2 (75→76) taken 73 times.
|
73 | parser.setWhiteSpace(""); |
105 | 73 | 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 | 93 | bool pxml_parserXmlContent(PXml & parent, PFileParser & parser, bool isMainBalise){ | |
116 |
2/2✓ Branch 0 (2→3) taken 93 times.
✓ Branch 2 (3→4) taken 93 times.
|
93 | parser.setSeparator("<>\"="); |
117 |
2/2✓ Branch 0 (5→6) taken 93 times.
✓ Branch 2 (6→7) taken 93 times.
|
93 | parser.setWhiteSpace(""); |
118 |
4/4✓ Branch 0 (8→9) taken 93 times.
✓ Branch 2 (9→10) taken 93 times.
✓ Branch 4 (10→11) taken 93 times.
✓ Branch 6 (11→12) taken 93 times.
|
93 | PString balisePartialEnd("/" + parent.getName() + ">"); |
119 |
2/2✓ Branch 0 (14→15) taken 93 times.
✓ Branch 2 (15→16) taken 93 times.
|
93 | PString baliseEnd("<" + balisePartialEnd); |
120 |
1/1✓ Branch 0 (17→18) taken 93 times.
|
93 | PXml text; |
121 |
1/1✓ Branch 0 (18→19) taken 93 times.
|
93 | text.setIsText(true); |
122 |
8/8✓ Branch 0 (142→143) taken 167 times.
✓ Branch 2 (143→144) taken 160 times.
✓ Branch 3 (143→147) taken 7 times.
✓ Branch 4 (144→145) taken 160 times.
✓ Branch 6 (145→146) taken 153 times.
✓ Branch 7 (145→147) taken 7 times.
✓ Branch 8 (148→20) taken 153 times.
✓ Branch 9 (148→149) taken 14 times.
|
167 | while(!parser.isMatch(baliseEnd) && !parser.isEndOfFile()){ |
123 |
2/2✓ Branch 0 (20→21) taken 153 times.
✓ Branch 2 (21→22) taken 153 times.
|
153 | PString textString(parser.getUntilKeyWithoutPatern("<")); |
124 |
3/3✓ Branch 0 (23→24) taken 153 times.
✓ Branch 2 (24→25) taken 117 times.
✓ Branch 3 (24→43) taken 36 times.
|
153 | if(textString != ""){ //If the next token is not a < it is a text |
125 |
2/2✓ Branch 0 (25→26) taken 117 times.
✓ Branch 2 (26→27) taken 117 times.
|
117 | text.getValue() += textString; |
126 |
3/3✓ Branch 0 (27→28) taken 117 times.
✓ Branch 2 (29→30) taken 71 times.
✓ Branch 3 (29→37) taken 46 times.
|
117 | if(parent.getVecChild().size() == 0lu){ |
127 |
3/3✓ Branch 0 (30→31) taken 71 times.
✓ Branch 2 (31→32) taken 40 times.
✓ Branch 3 (31→35) taken 31 times.
|
71 | if(parser.isMatch(balisePartialEnd)){ |
128 |
2/2✓ Branch 0 (32→33) taken 40 times.
✓ Branch 2 (33→34) taken 40 times.
|
40 | parent.setValue(text.getValue()); |
129 | 40 | return true; | |
130 | }else{ | ||
131 |
2/2✓ Branch 0 (35→36) taken 31 times.
✓ Branch 2 (36→39) taken 31 times.
|
31 | parent.getVecChild().push_back(text); |
132 | } | ||
133 | }else{ | ||
134 |
2/2✓ Branch 0 (37→38) taken 46 times.
✓ Branch 2 (38→39) taken 46 times.
|
46 | parent.getVecChild().push_back(text); |
135 | } | ||
136 |
2/2✓ Branch 0 (39→40) taken 77 times.
✓ Branch 2 (40→41) taken 77 times.
|
77 | text.setValue(""); //Reset value for next one |
137 | } | ||
138 |
3/3✓ Branch 0 (43→44) taken 113 times.
✓ Branch 2 (44→45) taken 14 times.
✓ Branch 3 (44→58) taken 99 times.
|
113 | if(parser.isEndOfFile()){ |
139 |
2/2✓ Branch 0 (45→46) taken 13 times.
✓ Branch 1 (45→47) taken 1 times.
|
14 | if(isMainBalise){ |
140 | 13 | return true; | |
141 | }else{ | ||
142 |
4/4✓ Branch 0 (47→48) taken 1 times.
✓ Branch 2 (48→49) taken 1 times.
✓ Branch 4 (49→50) taken 1 times.
✓ Branch 6 (50→51) taken 1 times.
|
1 | std::cerr << "pxml_parserXmlContent : error at : " << parser.getLocation() << std::endl; |
143 |
5/5✓ Branch 0 (52→53) taken 1 times.
✓ Branch 2 (53→54) taken 1 times.
✓ Branch 4 (54→55) taken 1 times.
✓ Branch 6 (55→56) taken 1 times.
✓ Branch 8 (56→57) 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 0 (58→59) taken 99 times.
✓ Branch 2 (59→60) taken 24 times.
✓ Branch 3 (59→61) taken 75 times.
|
99 | if(parser.isMatch(balisePartialEnd)){ //We find the end of the balise |
148 | 24 | return true; | |
149 | }else{ //Or it can be another balise | ||
150 |
2/2✓ Branch 0 (61→62) taken 75 times.
✓ Branch 2 (62→63) taken 75 times.
|
75 | PString childBaliseName(parser.getStrComposedOf(ALLOWED_BALISE_CHAR)); |
151 |
2/3✓ Branch 0 (64→65) taken 75 times.
✓ Branch 2 (65→66) taken 75 times.
✗ Branch 3 (65→116) not taken.
|
75 | if(childBaliseName != ""){ //We find a new balise |
152 |
1/1✓ Branch 0 (66→67) taken 75 times.
|
75 | PXml xml; |
153 |
1/1✓ Branch 0 (67→68) taken 75 times.
|
75 | xml.setName(childBaliseName); |
154 |
3/3✓ Branch 0 (68→69) taken 75 times.
✓ Branch 2 (69→70) taken 1 times.
✓ Branch 3 (69→75) taken 74 times.
|
75 | if(childBaliseName == "!--"){ |
155 |
2/2✓ Branch 0 (70→71) taken 1 times.
✓ Branch 2 (71→72) taken 1 times.
|
1 | parser.getUntilKeyWithoutPatern("-->"); //Skip the comment |
156 |
3/3✓ Branch 0 (75→76) taken 74 times.
✓ Branch 2 (76→77) taken 1 times.
✓ Branch 3 (76→82) taken 73 times.
|
74 | }else if(childBaliseName == "?xml"){ |
157 |
2/2✓ Branch 0 (77→78) taken 1 times.
✓ Branch 2 (78→79) taken 1 times.
|
1 | parser.getUntilKeyWithoutPatern("?>"); //Skip the svg balise |
158 | }else{ | ||
159 |
2/3✓ Branch 0 (82→83) taken 73 times.
✗ Branch 2 (83→84) not taken.
✓ Branch 3 (83→94) taken 73 times.
|
73 | 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 0 (94→95) taken 73 times.
✓ Branch 2 (95→96) taken 72 times.
✓ Branch 3 (95→108) taken 1 times.
|
73 | if(!xml.getIsCompact()){ |
165 | //Let's parse the content | ||
166 |
3/3✓ Branch 0 (96→97) taken 72 times.
✓ Branch 2 (97→98) taken 1 times.
✓ Branch 3 (97→108) taken 71 times.
|
72 | if(!pxml_parserXmlContent(xml, parser, false)){ |
167 |
4/4✓ Branch 0 (98→99) taken 1 times.
✓ Branch 2 (99→100) taken 1 times.
✓ Branch 4 (100→101) taken 1 times.
✓ Branch 6 (101→102) taken 1 times.
|
1 | std::cerr << "pxml_parserXmlContent : error at : " << parser.getLocation() << std::endl; |
168 |
4/4✓ Branch 0 (103→104) taken 1 times.
✓ Branch 2 (104→105) taken 1 times.
✓ Branch 4 (105→106) taken 1 times.
✓ Branch 6 (106→107) taken 1 times.
|
1 | std::cerr << "\tcannot parse balise '"<<childBaliseName<<"'" << std::endl; |
169 | 1 | return false; | |
170 | } | ||
171 | } | ||
172 |
2/2✓ Branch 0 (108→109) taken 72 times.
✓ Branch 2 (109→110) taken 72 times.
|
72 | parent.getVecChild().push_back(xml); |
173 | } | ||
174 |
2/6✓ Branch 0 (112→113) taken 74 times.
✓ Branch 1 (112→115) taken 1 times.
✗ Branch 2 (116→117) not taken.
✗ Branch 4 (117→118) not taken.
✗ Branch 6 (119→120) not taken.
✗ Branch 7 (119→129) not taken.
|
75 | }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 0 (133→134) taken 74 times.
✓ Branch 1 (133→136) taken 1 times.
|
75 | } |
181 |
2/2✓ Branch 0 (138→139) taken 74 times.
✓ Branch 1 (138→141) taken 79 times.
|
153 | } |
182 | 14 | return true; | |
183 | 93 | } | |
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 | 7 | bool pxml_getVecChildIfExist(PVecXml & vecMatch, const PXml & xml, const PString & childName){ | |
198 | 7 | bool isFound(false); | |
199 | 7 | const PVecXml & vecChild = xml.getVecChild(); | |
200 |
2/2✓ Branch 0 (23→4) taken 41 times.
✓ Branch 1 (23→24) taken 7 times.
|
96 | for(PVecXml::const_iterator it(vecChild.begin()); it != vecChild.end(); ++it){ |
201 |
3/3✓ Branch 0 (6→7) taken 41 times.
✓ Branch 2 (8→9) taken 17 times.
✓ Branch 3 (8→13) taken 24 times.
|
82 | if(it->getName() == childName){ |
202 |
1/1✓ Branch 0 (11→12) taken 17 times.
|
17 | vecMatch.push_back(*it); |
203 | 17 | isFound = true; | |
204 | } | ||
205 | } | ||
206 | 7 | 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 | 11 | bool pxml_getChildIfExist(PXml & match, const PXml & xml, const PString & childName){ | |
216 | 11 | bool isSearched(true); | |
217 |
1/1✓ Branch 0 (2→3) taken 11 times.
|
11 | const PVecXml & vecChild = xml.getVecChild(); |
218 | 11 | PVecXml::const_iterator it(vecChild.begin()); | |
219 |
5/6✓ Branch 0 (24→25) taken 18 times.
✓ Branch 1 (24→27) taken 11 times.
✓ Branch 2 (25→26) taken 18 times.
✗ Branch 3 (25→27) not taken.
✓ Branch 4 (28→5) taken 18 times.
✓ Branch 5 (28→29) taken 11 times.
|
58 | while(it != vecChild.end() && isSearched){ |
220 |
3/3✓ Branch 0 (7→8) taken 18 times.
✓ Branch 2 (9→10) taken 2 times.
✓ Branch 3 (9→14) taken 16 times.
|
36 | if(it->getName() == childName){ |
221 |
1/1✓ Branch 0 (12→13) taken 2 times.
|
2 | match = *it; |
222 | 2 | isSearched = false; | |
223 | } | ||
224 | ++it; | ||
225 | } | ||
226 | 11 | 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 | 7 | PXml * pxml_getChildPtr(PXml & xml, const PString & childName){ | |
235 | 7 | PXml * out = NULL; | |
236 | 7 | PVecXml & vecChild = xml.getVecChild(); | |
237 |
5/6✓ Branch 0 (22→23) taken 14 times.
✗ Branch 1 (22→25) not taken.
✓ Branch 2 (23→24) taken 7 times.
✓ Branch 3 (23→25) taken 7 times.
✓ Branch 4 (26→4) taken 7 times.
✓ Branch 5 (26→27) taken 7 times.
|
28 | for(PVecXml::iterator it(vecChild.begin()); it != vecChild.end() && out == NULL; ++it){ |
238 |
2/3✓ Branch 0 (6→7) taken 7 times.
✓ Branch 2 (8→9) taken 7 times.
✗ Branch 3 (8→12) not taken.
|
14 | if(it->getName() == childName){ |
239 | 7 | out = &(*it); | |
240 | } | ||
241 | } | ||
242 | 7 | 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 | 17 | bool pxml_getAttrIfExist(PXmlAttr & attr, const PXml & xml, const PString & attrName){ | |
252 | 17 | bool isSearched(true); | |
253 |
1/1✓ Branch 0 (2→3) taken 17 times.
|
17 | const PVecXmlAttr & vecAttr = xml.getVecAttr(); |
254 | 17 | PVecXmlAttr::const_iterator it(vecAttr.begin()); | |
255 |
5/6✓ Branch 0 (24→25) taken 5 times.
✓ Branch 1 (24→27) taken 17 times.
✓ Branch 2 (25→26) taken 5 times.
✗ Branch 3 (25→27) not taken.
✓ Branch 4 (28→5) taken 5 times.
✓ Branch 5 (28→29) taken 17 times.
|
44 | while(it != vecAttr.end() && isSearched){ |
256 |
2/3✓ Branch 0 (7→8) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✗ Branch 3 (9→14) not taken.
|
10 | if(it->getName() == attrName){ |
257 |
1/1✓ Branch 0 (12→13) taken 5 times.
|
5 | attr = *it; |
258 | 5 | isSearched = false; | |
259 | } | ||
260 | ++it; | ||
261 | } | ||
262 | 17 | 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 | 1 | void pxml_setAttr(PXml & xml, const PString & nameAttr, const PString & valueAttr){ | |
271 | 1 | bool isSearched(true); | |
272 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PVecXmlAttr & vecAttr = xml.getVecAttr(); |
273 | 1 | PVecXmlAttr::iterator it(vecAttr.begin()); | |
274 |
2/6✗ Branch 0 (24→25) not taken.
✓ Branch 1 (24→27) taken 1 times.
✗ Branch 2 (25→26) not taken.
✗ Branch 3 (25→27) not taken.
✗ Branch 4 (28→5) not taken.
✓ Branch 5 (28→29) taken 1 times.
|
2 | while(it != vecAttr.end() && isSearched){ |
275 | ✗ | if(it->getName() == nameAttr){ | |
276 | ✗ | it->setValue(valueAttr); | |
277 | ✗ | isSearched = false; | |
278 | } | ||
279 | ++it; | ||
280 | } | ||
281 | 1 | } | |
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 | 1 | PXml pxml_eraseVecChild(const PXml & xml, const PString & childName){ | |
289 | 1 | PXml out; | |
290 |
2/2✓ Branch 0 (3→4) taken 1 times.
✓ Branch 2 (4→5) taken 1 times.
|
1 | out.setName(xml.getName()); |
291 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
|
1 | out.setValue(xml.getValue()); |
292 |
2/2✓ Branch 0 (7→8) taken 1 times.
✓ Branch 2 (8→9) taken 1 times.
|
1 | out.setVecAttr(xml.getVecAttr()); |
293 |
1/1✓ Branch 0 (9→10) taken 1 times.
|
1 | const PVecXml & vecXml = xml.getVecChild(); |
294 |
2/2✓ Branch 0 (30→11) taken 6 times.
✓ Branch 1 (30→31) taken 1 times.
|
14 | for(PVecXml::const_iterator it(vecXml.begin()); it != vecXml.end(); ++it){ |
295 |
2/3✓ Branch 0 (13→14) taken 6 times.
✗ Branch 2 (15→16) not taken.
✓ Branch 3 (15→20) taken 6 times.
|
12 | if(it->getName() != childName){ |
296 | ✗ | out.getVecChild().push_back(*it); | |
297 | } | ||
298 | } | ||
299 | 1 | 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 0 (2→3) taken 4 times.
|
4 | PString body(pxml_baliseStr(xml, isSvg)); |
310 |
1/1✓ Branch 0 (3→4) 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 | 157 | PString pxml_baliseStr(const PXml & xml, bool isSvg){ | |
319 |
3/3✓ Branch 0 (2→3) taken 157 times.
✓ Branch 2 (3→4) taken 157 times.
✓ Branch 4 (4→5) taken 157 times.
|
157 | PString body(""), name(xml.getName()); |
320 |
1/1✓ Branch 0 (5→6) taken 157 times.
|
157 | PString baseXmlNewLine("\n"); |
321 |
2/2✓ Branch 0 (6→7) taken 23 times.
✓ Branch 1 (6→8) taken 134 times.
|
157 | if(isSvg){ |
322 |
1/1✓ Branch 0 (7→8) taken 23 times.
|
23 | baseXmlNewLine = ""; |
323 | } | ||
324 |
3/3✓ Branch 0 (8→9) taken 157 times.
✓ Branch 2 (9→10) taken 69 times.
✓ Branch 3 (9→12) taken 88 times.
|
157 | if(xml.getIsText()){ |
325 |
2/2✓ Branch 0 (10→11) taken 69 times.
✓ Branch 2 (11→54) taken 69 times.
|
69 | body += xml.getValue(); |
326 | }else{ | ||
327 |
3/3✓ Branch 0 (12→13) taken 88 times.
✓ Branch 2 (13→14) taken 84 times.
✓ Branch 3 (13→49) taken 4 times.
|
88 | if(name != ""){ |
328 |
1/1✓ Branch 0 (14→15) taken 84 times.
|
84 | body += "<"; |
329 |
1/1✓ Branch 0 (15→16) taken 84 times.
|
84 | body += name; |
330 |
3/3✓ Branch 0 (16→17) taken 84 times.
✓ Branch 2 (17→18) taken 84 times.
✓ Branch 4 (18→19) taken 84 times.
|
84 | body += pxml_vecAttrStr(xml.getVecAttr(), isSvg); |
331 | |||
332 |
2/4✓ Branch 0 (20→21) taken 84 times.
✗ Branch 2 (21→22) not taken.
✓ Branch 3 (21→23) taken 84 times.
✗ Branch 4 (22→54) not taken.
|
84 | if(name == "?xml"){body += " ?>\n";} |
333 |
2/4✓ Branch 0 (23→24) taken 84 times.
✗ Branch 2 (24→25) not taken.
✓ Branch 3 (24→26) taken 84 times.
✗ Branch 4 (25→54) not taken.
|
84 | else if(name == "!--"){body += " -->\n";} |
334 |
3/3✓ Branch 0 (26→27) taken 84 times.
✓ Branch 2 (27→28) taken 1 times.
✓ Branch 3 (27→32) taken 83 times.
|
84 | else if(xml.getIsCompact()){ |
335 |
2/2✓ Branch 0 (28→29) taken 1 times.
✓ Branch 2 (29→30) taken 1 times.
|
1 | body += " />"+baseXmlNewLine; |
336 | }else{ | ||
337 |
2/2✓ Branch 0 (32→33) taken 83 times.
✓ Branch 2 (33→34) taken 83 times.
|
83 | body += ">"+baseXmlNewLine; |
338 |
3/3✓ Branch 0 (35→36) taken 83 times.
✓ Branch 2 (36→37) taken 83 times.
✓ Branch 4 (37→38) taken 83 times.
|
83 | body += pxml_vecXmlStr(xml.getVecChild(), isSvg); |
339 |
2/2✓ Branch 0 (39→40) taken 83 times.
✓ Branch 2 (40→41) taken 83 times.
|
83 | body += xml.getValue(); |
340 |
4/4✓ Branch 0 (41→42) taken 83 times.
✓ Branch 2 (42→43) taken 83 times.
✓ Branch 4 (43→44) taken 83 times.
✓ Branch 6 (44→45) taken 83 times.
|
83 | body += "</"+ name + ">" + baseXmlNewLine; |
341 | } | ||
342 | }else{ | ||
343 | |||
344 |
3/3✓ Branch 0 (49→50) taken 4 times.
✓ Branch 2 (50→51) taken 4 times.
✓ Branch 4 (51→52) taken 4 times.
|
4 | body += pxml_vecXmlStr(xml.getVecChild(), isSvg); |
345 | } | ||
346 | } | ||
347 | 157 | return body; | |
348 | 157 | } | |
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 | 94 | PString pxml_vecXmlStr(const PVecXml & vecXml, bool isSvg){ | |
356 | 94 | PString body(""); | |
357 |
2/2✓ Branch 0 (19→4) taken 140 times.
✓ Branch 1 (19→20) taken 94 times.
|
468 | for(PVecXml::const_iterator it(vecXml.begin()); it != vecXml.end(); ++it){ |
358 |
2/2✓ Branch 0 (6→7) taken 140 times.
✓ Branch 2 (7→8) taken 140 times.
|
280 | body += pxml_baliseStr(*it, isSvg); |
359 | } | ||
360 | 94 | 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 | 10 | PString pxml_attrStr(const PXmlAttr & xmlAttr, bool isSvg){ | |
369 | 10 | PString body(" "); | |
370 |
6/6✓ Branch 0 (3→4) taken 10 times.
✓ Branch 2 (4→5) taken 10 times.
✓ Branch 4 (5→6) taken 10 times.
✓ Branch 6 (6→7) taken 10 times.
✓ Branch 8 (7→8) taken 10 times.
✓ Branch 10 (8→9) taken 10 times.
|
10 | body += xmlAttr.getName() + "=\"" + xmlAttr.getValue() + "\""; |
371 |
2/2✓ Branch 0 (12→13) taken 3 times.
✓ Branch 1 (12→14) taken 7 times.
|
10 | if(isSvg){ |
372 |
1/1✓ Branch 0 (13→14) taken 3 times.
|
3 | body += "\n\t"; |
373 | } | ||
374 | 10 | 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 | 84 | PString pxml_vecAttrStr(const PVecXmlAttr & vecXmlAttr, bool isSvg){ | |
383 |
3/3✓ Branch 0 (3→4) taken 74 times.
✓ Branch 1 (3→6) taken 10 times.
✓ Branch 2 (4→5) taken 74 times.
|
84 | if(vecXmlAttr.size() == 0lu){return "";} |
384 |
1/1✓ Branch 0 (6→7) taken 10 times.
|
10 | PString body(""); |
385 |
2/2✓ Branch 0 (23→8) taken 10 times.
✓ Branch 1 (23→24) taken 10 times.
|
40 | for(PVecXmlAttr::const_iterator it(vecXmlAttr.begin()); it != vecXmlAttr.end(); ++it){ |
386 |
2/2✓ Branch 0 (10→11) taken 10 times.
✓ Branch 2 (11→12) taken 10 times.
|
20 | body += pxml_attrStr(*it, isSvg); |
387 | } | ||
388 |
1/1✓ Branch 0 (24→25) taken 10 times.
|
10 | return body; |
389 | 10 | } | |
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 | 58 | PString pxml_getFullContent(const PXml & xml){ | |
396 | 58 | const PVecXml & vecXml = xml.getVecChild(); | |
397 |
2/2✓ Branch 0 (4→5) taken 7 times.
✓ Branch 1 (4→6) taken 51 times.
|
58 | if(vecXml.size() != 0lu){ |
398 | 7 | return pxml_vecXmlStr(vecXml); | |
399 | }else{ | ||
400 | 51 | return xml.getValue(); | |
401 | } | ||
402 | } | ||
403 | |||
404 | |||
405 |