summaryrefslogtreecommitdiff
path: root/src/xine-utils/xmllexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xine-utils/xmllexer.c')
-rw-r--r--src/xine-utils/xmllexer.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c
index c0f314699..a9fcd9e31 100644
--- a/src/xine-utils/xmllexer.c
+++ b/src/xine-utils/xmllexer.c
@@ -15,8 +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.
+ * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110, USA
*
* $Id: xmllexer.c,v 1.13 2007/03/04 16:19:12 hadess Exp $
*
@@ -39,6 +39,9 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
+#ifdef HAVE_ICONV
+#include <iconv.h>
+#endif
/* private constants*/
@@ -521,7 +524,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)
@@ -549,7 +552,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++ = '&';
@@ -557,7 +560,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;