* xmlNewSaveCtxt: * * Create a new saving context * * Returns the new structure or NULL in case of error */
| 327 | * Returns the new structure or NULL in case of error |
| 328 | */ |
| 329 | static xmlSaveCtxtPtr |
| 330 | xmlNewSaveCtxt(const char *encoding, int options) |
| 331 | { |
| 332 | xmlSaveCtxtPtr ret; |
| 333 | |
| 334 | ret = (xmlSaveCtxtPtr) xmlMalloc(sizeof(xmlSaveCtxt)); |
| 335 | if (ret == NULL) { |
| 336 | xmlSaveErrMemory(NULL); |
| 337 | return ( NULL ); |
| 338 | } |
| 339 | memset(ret, 0, sizeof(xmlSaveCtxt)); |
| 340 | |
| 341 | if (encoding != NULL) { |
| 342 | int res; |
| 343 | |
| 344 | res = xmlOpenCharEncodingHandler(encoding, /* output */ 1, |
| 345 | &ret->handler); |
| 346 | if (res != XML_ERR_OK) { |
| 347 | xmlSaveErr(NULL, res, NULL, encoding); |
| 348 | xmlFreeSaveCtxt(ret); |
| 349 | return(NULL); |
| 350 | } |
| 351 | ret->encoding = xmlStrdup((const xmlChar *)encoding); |
| 352 | ret->escape = NULL; |
| 353 | } |
| 354 | xmlSaveCtxtInit(ret); |
| 355 | |
| 356 | /* |
| 357 | * Use the options |
| 358 | */ |
| 359 | |
| 360 | /* Re-check this option as it may already have been set */ |
| 361 | if ((ret->options & XML_SAVE_NO_EMPTY) && ! (options & XML_SAVE_NO_EMPTY)) { |
| 362 | options |= XML_SAVE_NO_EMPTY; |
| 363 | } |
| 364 | |
| 365 | ret->options = options; |
| 366 | if (options & XML_SAVE_FORMAT) |
| 367 | ret->format = 1; |
| 368 | else if (options & XML_SAVE_WSNONSIG) |
| 369 | ret->format = 2; |
| 370 | |
| 371 | return(ret); |
| 372 | } |
| 373 | |
| 374 | /************************************************************************ |
| 375 | * * |
no test coverage detected