UTF32 support from 4suite.org for libexpat
Raphael Bossek <[email protected]>
| Newsgroups | gmane.text.xml.expat.general |
|---|---|
| Message-ID | <[email protected]> |
Hi folks, as mentioned before you will find a patch created by me from the 4suite.org sources against latest CVS. -- Raphael Bossek _______________________________________________ Expat-discuss mailing list [email protected] http://mail.libexpat.org/mailman/listinfo/expat-discuss
utf32cvs.diff
(text/plain, 26.6 KB)
Index: configure.in
===================================================================
RCS file: /cvsroot/expat/expat/configure.in,v
retrieving revision 1.40
diff -u -r1.40 configure.in
--- configure.in 28 Jan 2005 06:32:30 -0000 1.40
+++ configure.in 5 Oct 2005 05:41:13 -0000
@@ -44,9 +44,9 @@
dnl If the API changes incompatibly set LIBAGE back to 0
dnl
-LIBCURRENT=5
+LIBCURRENT=6
LIBREVISION=0
-LIBAGE=5
+LIBAGE=0
AC_CONFIG_HEADER(expat_config.h)
Index: lib/expat.h
===================================================================
RCS file: /cvsroot/expat/expat/lib/expat.h,v
retrieving revision 1.76
diff -u -r1.76 expat.h
--- lib/expat.h 29 Jan 2005 04:48:43 -0000 1.76
+++ lib/expat.h 5 Oct 2005 05:41:16 -0000
@@ -14,9 +14,10 @@
#define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg
#endif
-#include <stdlib.h>
#include "expat_external.h"
+#include <stdlib.h>
+
#ifdef __cplusplus
extern "C" {
#endif
Index: lib/expat_external.h
===================================================================
RCS file: /cvsroot/expat/expat/lib/expat_external.h,v
retrieving revision 1.3
diff -u -r1.3 expat_external.h
--- lib/expat_external.h 26 Nov 2004 00:20:21 -0000 1.3
+++ lib/expat_external.h 5 Oct 2005 05:41:16 -0000
@@ -5,6 +5,16 @@
#ifndef Expat_External_INCLUDED
#define Expat_External_INCLUDED 1
+#ifdef COMPILED_FROM_DSP
+#include "winconfig.h"
+#elif defined(MACOS_CLASSIC)
+#include "macconfig.h"
+#elif defined(__amigaos4__)
+#include "amigaconfig.h"
+#elif defined(HAVE_EXPAT_CONFIG_H)
+#include <expat_config.h>
+#endif /* ndef COMPILED_FROM_DSP */
+
/* External API definitions */
#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__)
@@ -77,18 +87,43 @@
extern "C" {
#endif
+/* Setting XML_UNICODE_WIDE enables UCS-4 storage. Otherwise, Unicode
+ strings are stored as UCS-2 (with limited support for UTF-16) */
+
+#if XML_UNICODE_SIZE >= 4
+#define XML_UNICODE_WIDE
+#endif
+
#ifdef XML_UNICODE_WCHAR_T
+#define HAVE_USABLE_WCHAR_T
#define XML_UNICODE
#endif
+#ifdef HAVE_USABLE_WCHAR_T
+# ifndef HAVE_WCHAR_H
+# define HAVE_WCHAR_H
+# endif
+#endif
+
+#ifdef HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+
#ifdef XML_UNICODE /* Information is UTF-16 encoded. */
-#ifdef XML_UNICODE_WCHAR_T
-typedef wchar_t XML_Char;
+# if defined(HAVE_USABLE_WCHAR_T)
+# define XML_UNICODE_TYPE wchar_t
+# elif defined(XML_UNICODE_WIDE)
+# define XML_UNICODE_TYPE unsigned long
+# else
+# define XML_UNICODE_TYPE unsigned short
+# endif
+typedef XML_UNICODE_TYPE XML_Char;
+# ifdef XML_UNICODE_WCHAR_T
typedef wchar_t XML_LChar;
-#else
-typedef unsigned short XML_Char;
+# else
typedef char XML_LChar;
-#endif /* XML_UNICODE_WCHAR_T */
+# endif /* XML_UNICODE_WCHAR_T */
+
#else /* Information is UTF-8 encoded. */
typedef char XML_Char;
typedef char XML_LChar;
Index: lib/xmlparse.c
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmlparse.c,v
retrieving revision 1.148
diff -u -r1.148 xmlparse.c
--- lib/xmlparse.c 15 Jun 2005 14:24:26 -0000 1.148
+++ lib/xmlparse.c 5 Oct 2005 05:41:27 -0000
@@ -2,25 +2,23 @@
See the file COPYING for copying permission.
*/
-#include <stddef.h>
-#include <string.h> /* memset(), memcpy() */
-#include <assert.h>
-
#define XML_BUILDING_EXPAT 1
-#ifdef COMPILED_FROM_DSP
-#include "winconfig.h"
-#elif defined(MACOS_CLASSIC)
-#include "macconfig.h"
-#elif defined(__amigaos4__)
-#include "amigaconfig.h"
-#elif defined(HAVE_EXPAT_CONFIG_H)
-#include <expat_config.h>
-#endif /* ndef COMPILED_FROM_DSP */
-
#include "expat.h"
-#ifdef XML_UNICODE
+#include <stddef.h>
+#include <string.h> /* memset(), memcpy() */
+#include <assert.h>
+
+#if defined(XML_UNICODE_WIDE)
+#define XML_ENCODE_MAX XML_UTF32_ENCODE_MAX
+#define XmlConvert XmlUtf32Convert
+#define XmlGetInternalEncoding XmlGetUtf32InternalEncoding
+#define XmlGetInternalEncodingNS XmlGetUtf32InternalEncodingNS
+#define XmlEncode XmlUtf32Encode
+#define MUST_CONVERT(enc, s) (!(enc)->isUtf32 || (((unsigned long)s) & 1))
+typedef unsigned long ICHAR;
+#elif defined(XML_UNICODE)
#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX
#define XmlConvert XmlUtf16Convert
#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding
@@ -51,11 +49,10 @@
#ifdef XML_UNICODE
-#ifdef XML_UNICODE_WCHAR_T
-#define XML_T(x) (const wchar_t)x
+#define XML_T(x) (const XML_UNICODE_TYPE)x
+#if defined(XML_UNICODE_WCHAR_T)
#define XML_L(x) L ## x
#else
-#define XML_T(x) (const unsigned short)x
#define XML_L(x) x
#endif
@@ -102,7 +99,7 @@
*/
#ifdef XML_UNICODE
#define CHAR_HASH(h, c) \
- (((h) * 0xF4243) ^ (unsigned short)(c))
+ (((h) * 0xF4243) ^ (unsigned long)(c))
#else
#define CHAR_HASH(h, c) \
(((h) * 0xF4243) ^ (unsigned char)(c))
Index: lib/xmlrole.c
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmlrole.c,v
retrieving revision 1.21
diff -u -r1.21 xmlrole.c
--- lib/xmlrole.c 26 Feb 2005 01:38:13 -0000 1.21
+++ lib/xmlrole.c 5 Oct 2005 05:41:29 -0000
@@ -4,18 +4,6 @@
#include <stddef.h>
-#ifdef COMPILED_FROM_DSP
-#include "winconfig.h"
-#elif defined(MACOS_CLASSIC)
-#include "macconfig.h"
-#elif defined(__amigaos4__)
-#include "amigaconfig.h"
-#else
-#ifdef HAVE_EXPAT_CONFIG_H
-#include <expat_config.h>
-#endif
-#endif /* ndef COMPILED_FROM_DSP */
-
#include "expat_external.h"
#include "internal.h"
#include "xmlrole.h"
Index: lib/xmltok.c
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmltok.c,v
retrieving revision 1.34
diff -u -r1.34 xmltok.c
--- lib/xmltok.c 26 Feb 2005 01:38:13 -0000 1.34
+++ lib/xmltok.c 5 Oct 2005 05:41:32 -0000
@@ -4,18 +4,6 @@
#include <stddef.h>
-#ifdef COMPILED_FROM_DSP
-#include "winconfig.h"
-#elif defined(MACOS_CLASSIC)
-#include "macconfig.h"
-#elif defined(__amigaos4__)
-#include "amigaconfig.h"
-#else
-#ifdef HAVE_EXPAT_CONFIG_H
-#include <expat_config.h>
-#endif
-#endif /* ndef COMPILED_FROM_DSP */
-
#include "expat_external.h"
#include "internal.h"
#include "xmltok.h"
@@ -38,10 +26,10 @@
PREFIX(getAtts), \
PREFIX(charRefNumber), \
PREFIX(predefinedEntityName), \
- PREFIX(updatePosition), \
PREFIX(isPublicId)
-#define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16)
+#define VTABLE VTABLE1, PREFIX(updatePosition), \
+ PREFIX(toUtf8), PREFIX(toUtf16), PREFIX(toUtf32)
#define UCS2_GET_NAMING(pages, hi, lo) \
(namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F)))
@@ -314,6 +302,57 @@
UTF8_cval4 = 0xf0
};
+static char utf8_code_length[256] = {
+ /* Map UTF-8 encoded prefix byte to sequence length. zero means
+ illegal prefix. see RFC 2279 for details */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0
+};
+
+static void PTRCALL
+utf8_updatePosition(const ENCODING *enc,
+ const char *ptr,
+ const char *end,
+ POSITION *pos)
+{
+ while (ptr != end) {
+ unsigned char ch = (unsigned char)*ptr;
+ if (ch >= 32) {
+ if (ch < 128)
+ ptr++;
+ else
+ ptr += utf8_code_length[ch];
+ pos->columnNumber++;
+ } else if (ch == 10) {
+ pos->columnNumber = 0;
+ pos->lineNumber++;
+ ptr++;
+ } else if (ch == 13) {
+ pos->columnNumber = 0;
+ pos->lineNumber++;
+ ptr++;
+ if (ptr != end && *ptr == 10) ptr++;
+ } else {
+ ptr++;
+ pos->columnNumber++;
+ }
+ }
+}
+
static void PTRCALL
utf8_toUtf8(const ENCODING *enc,
const char **fromP, const char *fromLim,
@@ -341,33 +380,34 @@
unsigned short *to = *toP;
const char *from = *fromP;
while (from != fromLim && to != toLim) {
- switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) {
- case BT_LEAD2:
- *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f));
- from += 2;
- break;
- case BT_LEAD3:
- *to++ = (unsigned short)(((from[0] & 0xf) << 12)
- | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f));
- from += 3;
- break;
- case BT_LEAD4:
- {
- unsigned long n;
- if (to + 1 == toLim)
+ unsigned short ch = (unsigned char) *from;
+ if (ch < 0x80) {
+ *to++ = ch;
+ from++;
+ } else {
+ switch (utf8_code_length[ch]) {
+ case 2:
+ *to++ = (((from[0] & 0x1f) << 6) | (from[1] & 0x3f));
+ from += 2;
+ break;
+ case 3:
+ *to++ = (((from[0] & 0xf) << 12)
+ | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f));
+ from += 3;
+ break;
+ case 4:
+ if (to + 1 == toLim)
goto after;
- n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12)
- | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f);
- n -= 0x10000;
- to[0] = (unsigned short)((n >> 10) | 0xD800);
- to[1] = (unsigned short)((n & 0x3FF) | 0xDC00);
+ ch = ((((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12)
+ | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f)) - 0x10000);
+ to[0] = (unsigned short)((ch >> 10) | 0xD800);
+ to[1] = (unsigned short)((ch & 0x3FF) | 0xDC00);
to += 2;
from += 4;
+ break;
+ default:
+ break;
}
- break;
- default:
- *to++ = *from++;
- break;
}
}
after:
@@ -375,9 +415,48 @@
*toP = to;
}
+static void PTRCALL
+utf8_toUtf32(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ unsigned long **toP, const unsigned long *toLim)
+{
+ unsigned long *to = *toP;
+ const char *from = *fromP;
+ while (from != fromLim && to != toLim) {
+ unsigned long ch = (unsigned char) *from;
+ if (ch < 0x80) {
+ *to++ = ch;
+ from++;
+ } else {
+ switch (utf8_code_length[ch]) {
+ case 2:
+ *to++ = (((from[0] & 0x1f) << 6) | (from[1] & 0x3f));
+ from += 2;
+ break;
+ case 3:
+ *to++ = (((from[0] & 0xf) << 12)
+ | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f));
+ from += 3;
+ break;
+ case 4:
+ *to++ = (((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12)
+ | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f));
+ from += 4;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ *fromP = from;
+ *toP = to;
+}
+
#ifdef XML_NS
static const struct normal_encoding utf8_encoding_ns = {
- { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
+ { VTABLE1, utf8_updatePosition,
+ utf8_toUtf8, utf8_toUtf16, utf8_toUtf32,
+ 1, 1, 0, 0},
{
#include "asciitab.h"
#include "utf8tab.h"
@@ -387,7 +466,9 @@
#endif
static const struct normal_encoding utf8_encoding = {
- { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
+ { VTABLE1, utf8_updatePosition,
+ utf8_toUtf8, utf8_toUtf16, utf8_toUtf32,
+ 1, 1, 0, 0 },
{
#define BT_COLON BT_NMSTRT
#include "asciitab.h"
@@ -400,7 +481,9 @@
#ifdef XML_NS
static const struct normal_encoding internal_utf8_encoding_ns = {
- { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
+ { VTABLE1, utf8_updatePosition,
+ utf8_toUtf8, utf8_toUtf16, utf8_toUtf32,
+ 1, 1, 0, 0 },
{
#include "iasciitab.h"
#include "utf8tab.h"
@@ -411,7 +494,9 @@
#endif
static const struct normal_encoding internal_utf8_encoding = {
- { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
+ { VTABLE1, utf8_updatePosition,
+ utf8_toUtf8, utf8_toUtf16, utf8_toUtf32,
+ 1, 1, 0, 0 },
{
#define BT_COLON BT_NMSTRT
#include "iasciitab.h"
@@ -422,6 +507,33 @@
};
static void PTRCALL
+latin1_updatePosition(const ENCODING *enc,
+ const char *ptr,
+ const char *end,
+ POSITION *pos)
+{
+ while (ptr != end) {
+ unsigned char ch = (unsigned char)*ptr;
+ if (ch >= 32) {
+ ptr++;
+ pos->columnNumber++;
+ } else if (ch == 10) {
+ pos->columnNumber = 0;
+ pos->lineNumber++;
+ ptr++;
+ } else if (ch == 13) {
+ pos->columnNumber = 0;
+ pos->lineNumber++;
+ ptr++;
+ if (ptr != end && *ptr == 10) ptr++;
+ } else {
+ ptr++;
+ pos->columnNumber++;
+ }
+ }
+}
+
+static void PTRCALL
latin1_toUtf8(const ENCODING *enc,
const char **fromP, const char *fromLim,
char **toP, const char *toLim)
@@ -455,10 +567,21 @@
*(*toP)++ = (unsigned char)*(*fromP)++;
}
+static void PTRCALL
+latin1_toUtf32(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ unsigned long **toP, const unsigned long *toLim)
+{
+ while (*fromP != fromLim && *toP != toLim)
+ *(*toP)++ = (unsigned char)*(*fromP)++;
+}
+
#ifdef XML_NS
static const struct normal_encoding latin1_encoding_ns = {
- { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 },
+ { VTABLE1, latin1_updatePosition,
+ latin1_toUtf8, latin1_toUtf16, latin1_toUtf32,
+ 1, 0, 0, 0 },
{
#include "asciitab.h"
#include "latin1tab.h"
@@ -469,7 +592,9 @@
#endif
static const struct normal_encoding latin1_encoding = {
- { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 },
+ { VTABLE1, latin1_updatePosition,
+ latin1_toUtf8, latin1_toUtf16, latin1_toUtf32,
+ 1, 0, 0, 0 },
{
#define BT_COLON BT_NMSTRT
#include "asciitab.h"
@@ -491,7 +616,8 @@
#ifdef XML_NS
static const struct normal_encoding ascii_encoding_ns = {
- { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 },
+ { VTABLE1, latin1_updatePosition,
+ ascii_toUtf8, latin1_toUtf16, latin1_toUtf32, 1, 1, 0, 0 },
{
#include "asciitab.h"
/* BT_NONXML == 0 */
@@ -502,7 +628,8 @@
#endif
static const struct normal_encoding ascii_encoding = {
- { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 },
+ { VTABLE1, latin1_updatePosition,
+ ascii_toUtf8, latin1_toUtf16, latin1_toUtf32, 1, 1, 0, 0 },
{
#define BT_COLON BT_NMSTRT
#include "asciitab.h"
@@ -608,6 +735,30 @@
*(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \
}
+#define DEFINE_UTF16_TO_UTF32(E) \
+static void PTRCALL \
+E ## toUtf32(const ENCODING *enc, \
+ const char **fromP, const char *fromLim, \
+ unsigned long **toP, const unsigned long *toLim) \
+{ \
+ /* Avoid copying first half only of surrogate */ \
+ if (fromLim - *fromP > ((toLim - *toP) << 1) \
+ && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \
+ fromLim -= 2; \
+ while (*fromP != fromLim && *toP != toLim) { \
+ unsigned long n = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \
+ *fromP += 2; \
+ if (n < 0xD800 || n > 0xDFFF) { \
+ *(*toP)++ = n; \
+ } else { \
+ /* UTF-16 surrogate pair */ \
+ unsigned long n2 = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \
+ *fromP += 2; \
+ *(*toP)++ = (((n & 0x3FF)<<10) | (n2 & 0x3FF)) + 0x10000; \
+ } \
+ } \
+}
+
#define SET2(ptr, ch) \
(((ptr)[0] = ((ch) & 0xff)), ((ptr)[1] = ((ch) >> 8)))
#define GET_LO(ptr) ((unsigned char)(ptr)[0])
@@ -615,6 +766,7 @@
DEFINE_UTF16_TO_UTF8(little2_)
DEFINE_UTF16_TO_UTF16(little2_)
+DEFINE_UTF16_TO_UTF32(little2_)
#undef SET2
#undef GET_LO
@@ -627,6 +779,7 @@
DEFINE_UTF16_TO_UTF8(big2_)
DEFINE_UTF16_TO_UTF16(big2_)
+DEFINE_UTF16_TO_UTF32(big2_)
#undef SET2
#undef GET_LO
@@ -676,7 +829,8 @@
}
#undef VTABLE
-#define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16
+#define VTABLE VTABLE1, little2_updatePosition, \
+ little2_toUtf8, little2_toUtf16, little2_toUtf32
#else /* not XML_MIN_SIZE */
@@ -711,11 +865,11 @@
static const struct normal_encoding little2_encoding_ns = {
{ VTABLE, 2, 0,
#if BYTEORDER == 1234
- 1
+ 1,
#else
- 0
+ 0,
#endif
- },
+ 0 },
{
#include "asciitab.h"
#include "latin1tab.h"
@@ -728,11 +882,11 @@
static const struct normal_encoding little2_encoding = {
{ VTABLE, 2, 0,
#if BYTEORDER == 1234
- 1
+ 1,
#else
- 0
+ 0,
#endif
- },
+ 0 },
{
#define BT_COLON BT_NMSTRT
#include "asciitab.h"
@@ -747,7 +901,7 @@
#ifdef XML_NS
static const struct normal_encoding internal_little2_encoding_ns = {
- { VTABLE, 2, 0, 1 },
+ { VTABLE, 2, 0, 1, 0 },
{
#include "iasciitab.h"
#include "latin1tab.h"
@@ -758,7 +912,7 @@
#endif
static const struct normal_encoding internal_little2_encoding = {
- { VTABLE, 2, 0, 1 },
+ { VTABLE, 2, 0, 1, 0 },
{
#define BT_COLON BT_NMSTRT
#include "iasciitab.h"
@@ -815,7 +969,8 @@
}
#undef VTABLE
-#define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16
+#define VTABLE VTABLE1, big2_updatePosition, \
+ big2_toUtf8, big2_toUtf16, big2_toUtf32
#else /* not XML_MIN_SIZE */
@@ -850,11 +1005,11 @@
static const struct normal_encoding big2_encoding_ns = {
{ VTABLE, 2, 0,
#if BYTEORDER == 4321
- 1
+ 1,
#else
- 0
+ 0,
#endif
- },
+ 0 },
{
#include "asciitab.h"
#include "latin1tab.h"
@@ -867,11 +1022,11 @@
static const struct normal_encoding big2_encoding = {
{ VTABLE, 2, 0,
#if BYTEORDER == 4321
- 1
+ 1,
#else
- 0
+ 0,
#endif
- },
+ 0 },
{
#define BT_COLON BT_NMSTRT
#include "asciitab.h"
@@ -886,7 +1041,7 @@
#ifdef XML_NS
static const struct normal_encoding internal_big2_encoding_ns = {
- { VTABLE, 2, 0, 1 },
+ { VTABLE, 2, 0, 1, 0 },
{
#include "iasciitab.h"
#include "latin1tab.h"
@@ -897,7 +1052,7 @@
#endif
static const struct normal_encoding internal_big2_encoding = {
- { VTABLE, 2, 0, 1 },
+ { VTABLE, 2, 0, 1, 0 },
{
#define BT_COLON BT_NMSTRT
#include "iasciitab.h"
@@ -909,6 +1064,115 @@
#endif
+
+#define UTF32_BYTE_TYPE(enc, p) \
+ ((p)[1] == 0 \
+ ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \
+ : BT_NONASCII)
+#define UTF32_BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1)
+#define UTF32_CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c)
+#define UTF32_IS_NAME_CHAR_MINBPC(enc, p) \
+ UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0])
+#define UTF32_IS_NMSTRT_CHAR_MINBPC(enc, p) \
+ UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0])
+
+#ifdef XML_MIN_SIZE
+
+static int PTRFASTCALL
+utf32_byteType(const ENCODING *enc, const char *p)
+{
+ return UTF32_BYTE_TYPE(enc, p);
+}
+
+static int PTRFASTCALL
+utf32_byteToAscii(const ENCODING *enc, const char *p)
+{
+ return UTF32_BYTE_TO_ASCII(enc, p);
+}
+
+static int PTRCALL
+utf32_charMatches(const ENCODING *enc, const char *p, int c)
+{
+ return UTF32_CHAR_MATCHES(enc, p, c);
+}
+
+static int PTRFASTCALL
+utf32_isNameMin(const ENCODING *enc, const char *p)
+{
+ return UTF32_IS_NAME_CHAR_MINBPC(enc, p);
+}
+
+static int PTRFASTCALL
+utf32_isNmstrtMin(const ENCODING *enc, const char *p)
+{
+ return UTF32_IS_NMSTRT_CHAR_MINBPC(enc, p);
+}
+
+#undef VTABLE
+#define VTABLE VTABLE1, utf32_updatePosition, \
+ utf32_toUtf8, utf32_toUtf16, utf32_toUtf32
+
+#else /* not XML_MIN_SIZE */
+
+#undef PREFIX
+#define PREFIX(ident) utf32_ ## ident
+#define MINBPC(enc) 4
+/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */
+#define BYTE_TYPE(enc, p) UTF32_BYTE_TYPE(enc, p)
+#define BYTE_TO_ASCII(enc, p) UTF32_BYTE_TO_ASCII(enc, p)
+#define CHAR_MATCHES(enc, p, c) UTF32_CHAR_MATCHES(enc, p, c)
+#define IS_NAME_CHAR(enc, p, n) 0
+#define IS_NAME_CHAR_MINBPC(enc, p) UTF32_IS_NAME_CHAR_MINBPC(enc, p)
+#define IS_NMSTRT_CHAR(enc, p, n) (0)
+#define IS_NMSTRT_CHAR_MINBPC(enc, p) UTF32_IS_NMSTRT_CHAR_MINBPC(enc, p)
+
+#include "xmltok_impl.c"
+
+#undef MINBPC
+#undef BYTE_TYPE
+#undef BYTE_TO_ASCII
+#undef CHAR_MATCHES
+#undef IS_NAME_CHAR
+#undef IS_NAME_CHAR_MINBPC
+#undef IS_NMSTRT_CHAR
+#undef IS_NMSTRT_CHAR_MINBPC
+#undef IS_INVALID_CHAR
+
+#endif /* not XML_MIN_SIZE */
+
+static void PTRCALL
+internalUtf32_toUtf32(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ unsigned long **toP, const unsigned long *toLim)
+{
+ for (; *fromP != fromLim && *toP != toLim; *fromP += 4) {
+ *(*toP)++ = *(*fromP);
+ }
+}
+
+#undef VTABLE
+#define VTABLE VTABLE1, utf32_updatePosition
+
+static const struct normal_encoding internal_utf32_encoding_ns = {
+ { VTABLE, NULL, NULL, internalUtf32_toUtf32, 4, 0, 0, 1 },
+ {
+#include "iasciitab.h"
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(sb_)
+};
+
+static const struct normal_encoding internal_utf32_encoding = {
+ { VTABLE, NULL, NULL, internalUtf32_toUtf32, 4, 0, 0, 1 },
+ {
+#define BT_COLON BT_NMSTRT
+#include "iasciitab.h"
+#undef BT_COLON
+#include "latin1tab.h"
+ },
+ STANDARD_VTABLE(sb_)
+};
+
#undef PREFIX
static int FASTCALL
@@ -1236,6 +1500,15 @@
return 0;
}
+int FASTCALL
+XmlUtf32Encode(int ch, unsigned long *buf)
+{
+ if (ch < 0)
+ return 0;
+ buf[0] = (unsigned long) ch;
+ return 1;
+}
+
struct unknown_encoding {
struct normal_encoding normal;
CONVERTER convert;
@@ -1334,6 +1607,26 @@
}
}
+static void PTRCALL
+unknown_toUtf32(const ENCODING *enc,
+ const char **fromP, const char *fromLim,
+ unsigned long **toP, const unsigned long *toLim)
+{
+ const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc);
+ while (*fromP != fromLim && *toP != toLim) {
+ unsigned short c = uenc->utf16[(unsigned char)**fromP];
+ if (c == 0) {
+ c = (unsigned short)
+ uenc->convert(uenc->userData, *fromP);
+ *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP]
+ - (BT_LEAD2 - 2));
+ }
+ else
+ (*fromP)++;
+ *(*toP)++ = c;
+ }
+}
+
ENCODING *
XmlInitUnknownEncoding(void *mem,
int *table,
@@ -1410,6 +1703,7 @@
}
e->normal.enc.utf8Convert = unknown_toUtf8;
e->normal.enc.utf16Convert = unknown_toUtf16;
+ e->normal.enc.utf32Convert = unknown_toUtf32;
return &(e->normal.enc);
}
Index: lib/xmltok.h
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmltok.h,v
retrieving revision 1.10
diff -u -r1.10 xmltok.h
--- lib/xmltok.h 26 Mar 2004 14:24:11 -0000 1.10
+++ lib/xmltok.h 5 Oct 2005 05:41:33 -0000
@@ -108,6 +108,8 @@
#define XML_UTF8_ENCODE_MAX 4
/* The size of the buffer passed to XmlUtf16Encode must be at least this. */
#define XML_UTF16_ENCODE_MAX 2
+/* The size of the buffer passed to XmlUtf32Encode must be at least this. */
+#define XML_UTF32_ENCODE_MAX 1
typedef struct position {
/* first line and first column are 0 not 1 */
@@ -150,14 +152,14 @@
int (PTRCALL *predefinedEntityName)(const ENCODING *,
const char *,
const char *);
- void (PTRCALL *updatePosition)(const ENCODING *,
- const char *ptr,
- const char *end,
- POSITION *);
int (PTRCALL *isPublicId)(const ENCODING *enc,
const char *ptr,
const char *end,
const char **badPtr);
+ void (PTRCALL *updatePosition)(const ENCODING *,
+ const char *ptr,
+ const char *end,
+ POSITION *);
void (PTRCALL *utf8Convert)(const ENCODING *enc,
const char **fromP,
const char *fromLim,
@@ -168,9 +170,18 @@
const char *fromLim,
unsigned short **toP,
const unsigned short *toLim);
+ /* Added in 1.95.9 */
+ void (PTRCALL *utf32Convert)(const ENCODING *enc,
+ const char **fromP,
+ const char *fromLim,
+ unsigned long **toP,
+ const unsigned long *toLim);
int minBytesPerChar;
char isUtf8;
char isUtf16;
+ /* Added in 1.95.9 */
+ char isUtf32;
+ char _reserved[128];
};
/* Scan the string starting at ptr until the end of the next complete
@@ -257,6 +268,9 @@
#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
(((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
+/* Added in 1.95.9 */
+#define XmlUtf32Convert(enc, fromP, fromLim, toP, toLim) \
+ (((enc)->utf32Convert)(enc, fromP, fromLim, toP, toLim))
typedef struct {
ENCODING initEnc;
@@ -277,8 +291,12 @@
int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
const ENCODING *XmlGetUtf8InternalEncoding(void);
const ENCODING *XmlGetUtf16InternalEncoding(void);
+/* Added in 1.95.9 */
+const ENCODING *XmlGetUtf32InternalEncoding(void);
int FASTCALL XmlUtf8Encode(int charNumber, char *buf);
int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf);
+/* Added in 1.95.9 */
+int FASTCALL XmlUtf32Encode(int charNumber, unsigned long *buf);
int XmlSizeOfUnknownEncoding(void);
@@ -304,6 +322,7 @@
int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
const ENCODING *XmlGetUtf8InternalEncodingNS(void);
const ENCODING *XmlGetUtf16InternalEncodingNS(void);
+const ENCODING *XmlGetUtf32InternalEncodingNS(void);
ENCODING *
XmlInitUnknownEncodingNS(void *mem,
int *table,
Index: lib/xmltok_ns.c
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmltok_ns.c,v
retrieving revision 1.7
diff -u -r1.7 xmltok_ns.c
--- lib/xmltok_ns.c 26 Nov 2004 14:58:24 -0000 1.7
+++ lib/xmltok_ns.c 5 Oct 2005 05:41:33 -0000
@@ -19,6 +19,13 @@
#endif
}
+/* Added in 1.95.9 */
+const ENCODING *
+NS(XmlGetUtf32InternalEncoding)(void)
+{
+ return &ns(internal_utf32_encoding).enc;
+}
+
static const ENCODING * const NS(encodings)[] = {
&ns(latin1_encoding).enc,
&ns(ascii_encoding).enc,
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDTCepN2lBq4Nesv8RAqZHAJwM7gldZ5T/0gsnjfWYRSd/Irgy4ACfb+nq sZIUt/NMoDAt9t8uMgurJ5w= =tugk -----END PGP SIGNATURE-----