@@ -27,7 +27,7 @@ @implementation FBXPath
2727
2828+ (void )throwException : (NSString *)name forQuery : (NSString *)xpathQuery __attribute__((noreturn))
2929{
30- NSString * reason = [NSString stringWithFormat: @" Cannot evaluate results for XPath expression \" %@ \" " , xpathQuery];
30+ NSString *reason = [NSString stringWithFormat: @" Cannot evaluate results for XPath expression \" %@ \" " , xpathQuery];
3131 @throw [NSException exceptionWithName: name reason: reason userInfo: @{}];
3232}
3333
@@ -46,13 +46,13 @@ + (nullable NSString *)xmlStringWithSnapshot:(XCElementSnapshot *)root
4646 xmlDocDumpFormatMemory (doc, &xmlbuff, &buffersize, 1 );
4747 xmlFreeTextWriter (writer);
4848 xmlFreeDoc (doc);
49- return [NSString stringWithCString: (const char *)xmlbuff encoding: NSUTF8StringEncoding];
49+ return [NSString stringWithCString: (const char *)xmlbuff encoding: NSUTF8StringEncoding];
5050}
5151
5252+ (NSArray <XCElementSnapshot *> *)findMatchesIn : (XCElementSnapshot *)root xpathQuery : (NSString *)xpathQuery
5353{
5454 xmlDocPtr doc;
55-
55+
5656 xmlTextWriterPtr writer = xmlNewTextWriterDoc (&doc, 0 );
5757 if (NULL == writer) {
5858 [FBLogger logFmt: @" Failed to invoke libxml2>xmlNewTextWriterDoc for XPath query \" %@ \" " , xpathQuery];
@@ -67,15 +67,15 @@ + (nullable NSString *)xmlStringWithSnapshot:(XCElementSnapshot *)root
6767 [FBXPath throwException: XCElementSnapshotXPathQueryEvaluationException forQuery: xpathQuery];
6868 return nil ;
6969 }
70-
70+
7171 xmlXPathObjectPtr queryResult = [FBXPath evaluate: xpathQuery document: doc];
7272 if (NULL == queryResult) {
7373 xmlFreeTextWriter (writer);
7474 xmlFreeDoc (doc);
7575 [FBXPath throwException: XCElementSnapshotInvalidXPathException forQuery: xpathQuery];
7676 return nil ;
7777 }
78-
78+
7979 NSArray *matchingSnapshots = [FBXPath collectMatchingSnapshots: queryResult->nodesetval elementStore: elementStore];
8080 xmlXPathFreeObject (queryResult);
8181 xmlFreeTextWriter (writer);
@@ -101,7 +101,7 @@ + (NSArray *)collectMatchingSnapshots:(xmlNodeSetPtr)nodeSet elementStore:(NSMut
101101 [FBLogger log: @" Failed to invoke libxml2>xmlGetProp" ];
102102 return nil ;
103103 }
104- XCElementSnapshot *element = [elementStore objectForKey: (id )[NSString stringWithCString: (const char *)attrValue encoding: NSUTF8StringEncoding]];
104+ XCElementSnapshot *element = [elementStore objectForKey: (id )[NSString stringWithCString: (const char *)attrValue encoding: NSUTF8StringEncoding]];
105105 if (element) {
106106 [matchingSnapshots addObject: element];
107107 }
@@ -133,22 +133,22 @@ + (int)getSnapshotAsXML:(XCElementSnapshot *)root writer:(xmlTextWriterPtr)write
133133 return 0 ;
134134}
135135
136- + (xmlChar *) xmlCharPtrForInput : (const char *)input
136+ + (xmlChar *)xmlCharPtrForInput : (const char *)input
137137{
138138 if (0 == input) {
139139 return NULL ;
140140 }
141-
141+
142142 xmlCharEncodingHandlerPtr handler = xmlFindCharEncodingHandler (_UTF8Encoding);
143143 if (!handler) {
144144 [FBLogger log: @" Failed to invoke libxml2>xmlFindCharEncodingHandler" ];
145145 return NULL ;
146146 }
147-
147+
148148 int size = (int ) strlen (input) + 1 ;
149149 int outputSize = size * 2 - 1 ;
150150 xmlChar *output = (unsigned char *) xmlMalloc ((size_t ) outputSize);
151-
151+
152152 if (0 != output) {
153153 int temp = size - 1 ;
154154 int ret = handler->input (output, &outputSize, (const xmlChar *) input, &temp);
@@ -160,7 +160,7 @@ + (xmlChar *) xmlCharPtrForInput:(const char *)input
160160 output[outputSize] = 0 ;
161161 }
162162 }
163-
163+
164164 return output;
165165}
166166
@@ -171,7 +171,7 @@ + (xmlXPathObjectPtr)evaluate:(NSString *)xpathQuery document:(xmlDocPtr)doc
171171 [FBLogger logFmt: @" Failed to invoke libxml2>xmlXPathNewContext for XPath query \" %@ \" " , xpathQuery];
172172 return NULL ;
173173 }
174-
174+
175175 xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression ([FBXPath xmlCharPtrForInput: [xpathQuery cStringUsingEncoding: NSUTF8StringEncoding]], xpathCtx);
176176 if (NULL == xpathObj) {
177177 xmlXPathFreeContext (xpathCtx);
@@ -223,11 +223,6 @@ + (int)recordElementAttributes:(xmlTextWriterPtr)writer forElement:(XCElementSna
223223 return rc;
224224 }
225225 }
226- rc = xmlTextWriterWriteAttribute (writer, BAD_CAST " visible" , element.wdVisible ? BAD_CAST " true" : BAD_CAST " false" );
227- if (rc < 0 ) {
228- [FBLogger logFmt: @" Failed to invoke libxml2>xmlTextWriterWriteAttribute. Error code: %d " , rc];
229- return rc;
230- }
231226 rc = xmlTextWriterWriteAttribute (writer, BAD_CAST " enabled" , element.wdEnabled ? BAD_CAST " true" : BAD_CAST " false" );
232227 if (rc < 0 ) {
233228 [FBLogger logFmt: @" Failed to invoke libxml2>xmlTextWriterWriteAttribute. Error code: %d " , rc];
@@ -241,7 +236,7 @@ + (int)recordElementAttributes:(xmlTextWriterPtr)writer forElement:(XCElementSna
241236 return rc;
242237 }
243238 }
244-
239+
245240 if (nil != indexPath) {
246241 rc = xmlTextWriterWriteAttribute (writer, [FBXPath xmlCharPtrForInput: [kXMLIndexPathKey cStringUsingEncoding: NSUTF8StringEncoding]],
247242 [FBXPath xmlCharPtrForInput: [indexPath cStringUsingEncoding: NSUTF8StringEncoding]]);
@@ -250,25 +245,25 @@ + (int)recordElementAttributes:(xmlTextWriterPtr)writer forElement:(XCElementSna
250245 return rc;
251246 }
252247 }
253-
248+
254249 return 0 ;
255250}
256251
257252+ (int )generateXMLPresentation : (XCElementSnapshot *)root indexPath : (nullable NSString *)indexPath elementStore : (nullable NSMutableDictionary *)elementStore writer : (xmlTextWriterPtr)writer
258253{
259254 NSAssert ((indexPath == nil && elementStore == nil ) || (indexPath != nil && elementStore != nil ), @"Either both or none of indexPath and elementStore arguments should be equal to nil");
260-
255+
261256 int rc = xmlTextWriterStartElement (writer, [FBXPath xmlCharPtrForInput: [root.wdType cStringUsingEncoding: NSUTF8StringEncoding]]);
262257 if (rc < 0 ) {
263258 [FBLogger logFmt: @" Failed to invoke libxml2>xmlTextWriterStartElement. Error code: %d " , rc];
264259 return rc;
265260 }
266-
261+
267262 rc = [FBXPath recordElementAttributes: writer forElement: root indexPath: indexPath];
268263 if (rc < 0 ) {
269264 return rc;
270265 }
271-
266+
272267 NSArray *children = root.children ;
273268 for (NSUInteger i = 0 ; i < [children count ]; i++) {
274269 XCElementSnapshot *childSnapshot = children[i];
@@ -281,7 +276,7 @@ + (int)generateXMLPresentation:(XCElementSnapshot *)root indexPath:(nullable NSS
281276 return rc;
282277 }
283278 }
284-
279+
285280 rc = xmlTextWriterEndElement (writer);
286281 if (rc < 0 ) {
287282 [FBLogger logFmt: @" Failed to invoke libxml2>xmlTextWriterEndElement. Error code: %d " , rc];
@@ -291,4 +286,3 @@ + (int)generateXMLPresentation:(XCElementSnapshot *)root indexPath:(nullable NSS
291286}
292287
293288@end
294-
0 commit comments