* xmlTextWriterWriteString: * @writer: the xmlTextWriterPtr * @content: text string * * Write an xml text. * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */
| 1468 | * Returns the bytes written (may be 0 because of buffering) or -1 in case of error |
| 1469 | */ |
| 1470 | int |
| 1471 | xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content) |
| 1472 | { |
| 1473 | int count; |
| 1474 | int sum; |
| 1475 | xmlLinkPtr lk; |
| 1476 | xmlTextWriterStackEntry *p; |
| 1477 | xmlChar *buf; |
| 1478 | |
| 1479 | if ((writer == NULL) || (content == NULL)) |
| 1480 | return -1; |
| 1481 | |
| 1482 | sum = 0; |
| 1483 | buf = (xmlChar *) content; |
| 1484 | lk = xmlListFront(writer->nodes); |
| 1485 | if (lk != 0) { |
| 1486 | p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); |
| 1487 | if (p != 0) { |
| 1488 | switch (p->state) { |
| 1489 | case XML_TEXTWRITER_NAME: |
| 1490 | case XML_TEXTWRITER_TEXT: |
| 1491 | #if 0 |
| 1492 | buf = NULL; |
| 1493 | xmlOutputBufferWriteEscape(writer->out, content, NULL); |
| 1494 | #endif |
| 1495 | buf = xmlEncodeSpecialChars(NULL, content); |
| 1496 | break; |
| 1497 | case XML_TEXTWRITER_ATTRIBUTE: |
| 1498 | buf = NULL; |
| 1499 | xmlBufAttrSerializeTxtContent(writer->out, writer->doc, |
| 1500 | content); |
| 1501 | break; |
| 1502 | default: |
| 1503 | break; |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | if (buf != NULL) { |
| 1509 | count = xmlTextWriterWriteRaw(writer, buf); |
| 1510 | |
| 1511 | if (buf != content) /* buf was allocated by us, so free it */ |
| 1512 | xmlFree(buf); |
| 1513 | |
| 1514 | if (count < 0) |
| 1515 | return -1; |
| 1516 | sum += count; |
| 1517 | } |
| 1518 | |
| 1519 | return sum; |
| 1520 | } |
| 1521 | |
| 1522 | /** |
| 1523 | * xmlOutputBufferWriteBase64: |
no test coverage detected