| 1551 | |
| 1552 | #ifdef LIBXML_ICU_ENABLED |
| 1553 | static int |
| 1554 | openIcuConverter(const char* name, int toUnicode, uconv_t **out) |
| 1555 | { |
| 1556 | UErrorCode status; |
| 1557 | uconv_t *conv; |
| 1558 | |
| 1559 | *out = NULL; |
| 1560 | |
| 1561 | conv = (uconv_t *) xmlMalloc(sizeof(uconv_t)); |
| 1562 | if (conv == NULL) |
| 1563 | return(XML_ERR_NO_MEMORY); |
| 1564 | |
| 1565 | conv->pivot_source = conv->pivot_buf; |
| 1566 | conv->pivot_target = conv->pivot_buf; |
| 1567 | |
| 1568 | status = U_ZERO_ERROR; |
| 1569 | conv->uconv = ucnv_open(name, &status); |
| 1570 | if (U_FAILURE(status)) |
| 1571 | goto error; |
| 1572 | |
| 1573 | status = U_ZERO_ERROR; |
| 1574 | if (toUnicode) { |
| 1575 | ucnv_setToUCallBack(conv->uconv, UCNV_TO_U_CALLBACK_STOP, |
| 1576 | NULL, NULL, NULL, &status); |
| 1577 | } |
| 1578 | else { |
| 1579 | ucnv_setFromUCallBack(conv->uconv, UCNV_FROM_U_CALLBACK_STOP, |
| 1580 | NULL, NULL, NULL, &status); |
| 1581 | } |
| 1582 | if (U_FAILURE(status)) |
| 1583 | goto error; |
| 1584 | |
| 1585 | status = U_ZERO_ERROR; |
| 1586 | conv->utf8 = ucnv_open("UTF-8", &status); |
| 1587 | if (U_FAILURE(status)) |
| 1588 | goto error; |
| 1589 | |
| 1590 | *out = conv; |
| 1591 | return(0); |
| 1592 | |
| 1593 | error: |
| 1594 | if (conv->uconv) |
| 1595 | ucnv_close(conv->uconv); |
| 1596 | xmlFree(conv); |
| 1597 | |
| 1598 | if (status == U_FILE_ACCESS_ERROR) |
| 1599 | return(XML_ERR_UNSUPPORTED_ENCODING); |
| 1600 | if (status == U_MEMORY_ALLOCATION_ERROR) |
| 1601 | return(XML_ERR_NO_MEMORY); |
| 1602 | return(XML_ERR_SYSTEM); |
| 1603 | } |
| 1604 | |
| 1605 | static void |
| 1606 | closeIcuConverter(uconv_t *conv) |
no outgoing calls
no test coverage detected