* xmlLookupCharEncodingHandler: * @enc: an xmlCharEncoding value. * @out: pointer to result * * Find or create a handler matching the encoding. If no default or * registered handler could be found, try to create a handler using * iconv or ICU if supported. * * The handler must be closed with xmlCharEncCloseFunc. * * Available since 2.13.0. * * Returns an xmlParserErrors error code.
| 1778 | * Returns an xmlParserErrors error code. |
| 1779 | */ |
| 1780 | int |
| 1781 | xmlLookupCharEncodingHandler(xmlCharEncoding enc, |
| 1782 | xmlCharEncodingHandler **out) { |
| 1783 | const char *name = NULL; |
| 1784 | static const char *const ebcdicNames[] = { |
| 1785 | "EBCDIC", "ebcdic", "EBCDIC-US", "IBM-037" |
| 1786 | }; |
| 1787 | static const char *const ucs4Names[] = { |
| 1788 | "ISO-10646-UCS-4", "UCS-4", "UCS4" |
| 1789 | }; |
| 1790 | static const char *const ucs2Names[] = { |
| 1791 | "ISO-10646-UCS-2", "UCS-2", "UCS2" |
| 1792 | }; |
| 1793 | static const char *const shiftJisNames[] = { |
| 1794 | "SHIFT-JIS", "SHIFT_JIS", "Shift_JIS", |
| 1795 | }; |
| 1796 | const char *const *names = NULL; |
| 1797 | int numNames = 0; |
| 1798 | int ret; |
| 1799 | int i; |
| 1800 | |
| 1801 | if (out == NULL) |
| 1802 | return(XML_ERR_ARGUMENT); |
| 1803 | *out = NULL; |
| 1804 | |
| 1805 | switch (enc) { |
| 1806 | case XML_CHAR_ENCODING_ERROR: |
| 1807 | return(XML_ERR_UNSUPPORTED_ENCODING); |
| 1808 | case XML_CHAR_ENCODING_NONE: |
| 1809 | return(0); |
| 1810 | case XML_CHAR_ENCODING_UTF8: |
| 1811 | return(0); |
| 1812 | case XML_CHAR_ENCODING_UTF16LE: |
| 1813 | *out = (xmlCharEncodingHandler *) xmlUTF16LEHandler; |
| 1814 | return(0); |
| 1815 | case XML_CHAR_ENCODING_UTF16BE: |
| 1816 | *out = (xmlCharEncodingHandler *) xmlUTF16BEHandler; |
| 1817 | return(0); |
| 1818 | case XML_CHAR_ENCODING_EBCDIC: |
| 1819 | names = ebcdicNames; |
| 1820 | numNames = sizeof(ebcdicNames) / sizeof(ebcdicNames[0]); |
| 1821 | break; |
| 1822 | case XML_CHAR_ENCODING_UCS4BE: |
| 1823 | case XML_CHAR_ENCODING_UCS4LE: |
| 1824 | names = ucs4Names; |
| 1825 | numNames = sizeof(ucs4Names) / sizeof(ucs4Names[0]); |
| 1826 | break; |
| 1827 | case XML_CHAR_ENCODING_UCS4_2143: |
| 1828 | break; |
| 1829 | case XML_CHAR_ENCODING_UCS4_3412: |
| 1830 | break; |
| 1831 | case XML_CHAR_ENCODING_UCS2: |
| 1832 | names = ucs2Names; |
| 1833 | numNames = sizeof(ucs2Names) / sizeof(ucs2Names[0]); |
| 1834 | break; |
| 1835 | |
| 1836 | case XML_CHAR_ENCODING_ASCII: |
| 1837 | *out = (xmlCharEncodingHandler *) xmlAsciiHandler; |
no test coverage detected