diff options
Diffstat (limited to 'src/xine-utils/xmllexer.c')
-rw-r--r-- | src/xine-utils/xmllexer.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index 754a006f9..8879f7d0c 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -15,11 +15,8 @@ * * You should have received a copy of the GNU Library General Public * License along with the Gnome Library; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * $Id: xmllexer.c,v 1.13 2007/03/04 16:19:12 hadess Exp $ - * + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110, USA */ #define LOG_MODULE "xmllexer" @@ -39,6 +36,9 @@ #include <ctype.h> #include <string.h> #include <stdlib.h> +#ifdef HAVE_ICONV +#include <iconv.h> +#endif /* private constants*/ #define NORMAL 0 /* normal lex mode */ @@ -463,7 +463,7 @@ char *lexer_decode_entities (const char *tok) { /* parse the character entity (on failure, treat it as literal text) */ const char *tp = tok; - long i; + signed long i; for (i = 0; lexer_entities[i].code; ++i) if (!strncmp (lexer_entities[i].name, tok, lexer_entities[i].namelen) @@ -491,7 +491,7 @@ char *lexer_decode_entities (const char *tok) else i = strtol (tp, (char **)&tp, 10); - if (i < 1 || i > 255 || *tp != ';') + if (*tp != ';' || i < 1) { /* out of range, or format error */ *bp++ = '&'; @@ -499,7 +499,23 @@ char *lexer_decode_entities (const char *tok) } tok = tp + 1; - *bp++ = i; + + if (i < 128) + /* ASCII - store as-is */ + *bp++ = i; + else + { + /* Non-ASCII, so convert to UTF-8 */ + int count = (i >= 0x04000000) ? 5 : + (i >= 0x00200000) ? 4 : + (i >= 0x00010000) ? 3 : + (i >= 0x00000800) ? 2 : 1; + *bp = (char)(0x1F80 >> count); + count *= 6; + *bp++ |= i >> count; + while ((count -= 6) >= 0) + *bp++ = 128 | ((i >> count) & 0x3F); + } } } *bp = 0; |