head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.41; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.59; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.06; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.22.03; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# xmltok.h

    00001 /*
    00002 The contents of this file are subject to the Mozilla Public License
    00003 Version 1.1 (the "License"); you may not use this file except in
    00004 compliance with the License. You may obtain a copy of the License at
    00005 http://www.mozilla.org/MPL/
    00006
    00007 Software distributed under the License is distributed on an "AS IS"
    00008 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    00009 License for the specific language governing rights and limitations
    00010 under the License.
    00011
    00012 The Original Code is expat.
    00013
    00014 The Initial Developer of the Original Code is James Clark.
    00015 Portions created by James Clark are Copyright (C) 1998, 1999
    00016 James Clark. All Rights Reserved.
    00017
    00018 Contributor(s):
    00019
    00020 Alternatively, the contents of this file may be used under the terms
    00021 of the GNU General Public License (the "GPL"), in which case the
    00022 provisions of the GPL are applicable instead of those above.  If you
    00023 wish to allow use of your version of this file only under the terms of
    00024 the GPL and not to allow others to use your version of this file under
    00025 the MPL, indicate your decision by deleting the provisions above and
    00026 replace them with the notice and other provisions required by the
    00027 GPL. If you do not delete the provisions above, a recipient may use
    00028 your version of this file under either the MPL or the GPL.
    00029 */
    00030
    00031 #ifndef XmlTok_INCLUDED
    00032 #define XmlTok_INCLUDED 1
    00033
    00034 #ifdef __cplusplus
    00035 extern "C" {
    00036 #endif
    00037
    00038 #ifndef XMLTOKAPI
    00039 #define XMLTOKAPI /* as nothing */
    00040 #endif
    00041
    00042 /* The following token may be returned by XmlContentTok */
    00043 #define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be start of
    00044                                     illegal ]]> sequence */
    00045 /* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
    00046 #define XML_TOK_NONE -4    /* The string to be scanned is empty */
    00047 #define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan;
    00048                                   might be part of CRLF sequence */
    00049 #define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */
    00050 #define XML_TOK_PARTIAL -1 /* only part of a token */
    00051 #define XML_TOK_INVALID 0
    00052
    00053 /* The following tokens are returned by XmlContentTok; some are also
    00054   returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok */
    00055
    00056 #define XML_TOK_START_TAG_WITH_ATTS 1
    00057 #define XML_TOK_START_TAG_NO_ATTS 2
    00058 #define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */
    00059 #define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4
    00060 #define XML_TOK_END_TAG 5
    00061 #define XML_TOK_DATA_CHARS 6
    00062 #define XML_TOK_DATA_NEWLINE 7
    00063 #define XML_TOK_CDATA_SECT_OPEN 8
    00064 #define XML_TOK_ENTITY_REF 9
    00065 #define XML_TOK_CHAR_REF 10     /* numeric character reference */
    00066
    00067 /* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
    00068 #define XML_TOK_PI 11      /* processing instruction */
    00069 #define XML_TOK_XML_DECL 12 /* XML decl or text decl */
    00070 #define XML_TOK_COMMENT 13
    00071 #define XML_TOK_BOM 14     /* Byte order mark */
    00072
    00073 /* The following tokens are returned only by XmlPrologTok */
    00074 #define XML_TOK_PROLOG_S 15
    00075 #define XML_TOK_DECL_OPEN 16 /* <!foo */
    00076 #define XML_TOK_DECL_CLOSE 17 /* > */
    00077 #define XML_TOK_NAME 18
    00078 #define XML_TOK_NMTOKEN 19
    00079 #define XML_TOK_POUND_NAME 20 /* #name */
    00080 #define XML_TOK_OR 21 /* | */
    00081 #define XML_TOK_PERCENT 22
    00082 #define XML_TOK_OPEN_PAREN 23
    00083 #define XML_TOK_CLOSE_PAREN 24
    00084 #define XML_TOK_OPEN_BRACKET 25
    00085 #define XML_TOK_CLOSE_BRACKET 26
    00086 #define XML_TOK_LITERAL 27
    00087 #define XML_TOK_PARAM_ENTITY_REF 28
    00088 #define XML_TOK_INSTANCE_START 29
    00089
    00090 /* The following occur only in element type declarations */
    00091 #define XML_TOK_NAME_QUESTION 30 /* name? */
    00092 #define XML_TOK_NAME_ASTERISK 31 /* name* */
    00093 #define XML_TOK_NAME_PLUS 32 /* name+ */
    00094 #define XML_TOK_COND_SECT_OPEN 33 /* <![ */
    00095 #define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */
    00096 #define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */
    00097 #define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */
    00098 #define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */
    00099 #define XML_TOK_COMMA 38
    00100
    00101 /* The following token is returned only by XmlAttributeValueTok */
    00102 #define XML_TOK_ATTRIBUTE_VALUE_S 39
    00103
    00104 /* The following token is returned only by XmlCdataSectionTok */
    00105 #define XML_TOK_CDATA_SECT_CLOSE 40
    00106
    00107 /* With namespace processing this is returned by XmlPrologTok
    00108    for a name with a colon. */
    00109 #define XML_TOK_PREFIXED_NAME 41
    00110
    00111 #define XML_N_STATES 3
    00112 #define XML_PROLOG_STATE 0
    00113 #define XML_CONTENT_STATE 1
    00114 #define XML_CDATA_SECTION_STATE 2
    00115
    00116 #define XML_N_LITERAL_TYPES 2
    00117 #define XML_ATTRIBUTE_VALUE_LITERAL 0
    00118 #define XML_ENTITY_VALUE_LITERAL 1
    00119
    00120 /* The size of the buffer passed to XmlUtf8Encode must be at least this. */
    00121 #define XML_UTF8_ENCODE_MAX 4
    00122 /* The size of the buffer passed to XmlUtf16Encode must be at least this. */
    00123 #define XML_UTF16_ENCODE_MAX 2
    00124
    00125 typedef struct position {
    00126   /* first line and first column are 0 not 1 */
    00127   unsigned long lineNumber;
    00128   unsigned long columnNumber;
    00129 } POSITION;
    00130
    00131 typedef struct {
    00132   const char *name;
    00133   const char *valuePtr;
    00134   const char *valueEnd;
    00135   char normalized;
    00136 } ATTRIBUTE;
    00137
    00138 struct encoding;
    00139 typedef struct encoding ENCODING;
    00140
    00141 struct encoding {
    00142   int (*scanners[XML_N_STATES])(const ENCODING *,
    00143                                 const char *,
    00144                                 const char *,
    00145                                 const char **);
    00146   int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
    00147                                               const char *,
    00148                                               const char *,
    00149                                               const char **);
    00150   int (*sameName)(const ENCODING *,
    00151                   const char *, const char *);
    00152   int (*nameMatchesAscii)(const ENCODING *,
    00153                           const char *, const char *);
    00154   int (*nameLength)(const ENCODING *, const char *);
    00155   const char *(*skipS)(const ENCODING *, const char *);
    00156   int (*getAtts)(const ENCODING *enc, const char *ptr,
    00157                  int attsMax, ATTRIBUTE *atts);
    00158   int (*charRefNumber)(const ENCODING *enc, const char *ptr);
    00159   int (*predefinedEntityName)(const ENCODING *, const char *, const char *);
    00160   void (*updatePosition)(const ENCODING *,
    00161                          const char *ptr,
    00162                          const char *end,
    00163                          POSITION *);
    00164   int (*isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
    00165                     const char **badPtr);
    00166   void (*utf8Convert)(const ENCODING *enc,
    00167                       const char **fromP,
    00168                       const char *fromLim,
    00169                       char **toP,
    00170                       const char *toLim);
    00171   void (*utf16Convert)(const ENCODING *enc,
    00172                        const char **fromP,
    00173                        const char *fromLim,
    00174                        unsigned short **toP,
    00175                        const unsigned short *toLim);
    00176   int minBytesPerChar;
    00177   char isUtf8;
    00178   char isUtf16;
    00179 };
    00180
    00181 /*
    00182 Scan the string starting at ptr until the end of the next complete token,
    00183 but do not scan past eptr.  Return an integer giving the type of token.
    00184
    00185 Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
    00186
    00187 Return XML_TOK_PARTIAL when the string does not contain a complete token;
    00188 nextTokPtr will not be set.
    00189
    00190 Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr
    00191 will be set to point to the character which made the token invalid.
    00192
    00193 Otherwise the string starts with a valid token; nextTokPtr will be set to point
    00194 to the character following the end of that token.
    00195
    00196 Each data character counts as a single token, but adjacent data characters
    00197 may be returned together.  Similarly for characters in the prolog outside
    00198 literals, comments and processing instructions.
    00199 */
    00200
    00201
    00202 #define XmlTok(enc, state, ptr, end, nextTokPtr) \
    00203   (((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
    00204
    00205 #define XmlPrologTok(enc, ptr, end, nextTokPtr) \
    00206    XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
    00207
    00208 #define XmlContentTok(enc, ptr, end, nextTokPtr) \
    00209    XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
    00210
    00211 #define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
    00212    XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
    00213
    00214 /* This is used for performing a 2nd-level tokenization on
    00215 the content of a literal that has already been returned by XmlTok. */
    00216
    00217 #define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
    00218   (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
    00219
    00220 #define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
    00221    XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
    00222
    00223 #define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
    00224    XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
    00225
    00226 #define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
    00227
    00228 #define XmlNameMatchesAscii(enc, ptr1, ptr2) \
    00229   (((enc)->nameMatchesAscii)(enc, ptr1, ptr2))
    00230
    00231 #define XmlNameLength(enc, ptr) \
    00232   (((enc)->nameLength)(enc, ptr))
    00233
    00234 #define XmlSkipS(enc, ptr) \
    00235   (((enc)->skipS)(enc, ptr))
    00236
    00237 #define XmlGetAttributes(enc, ptr, attsMax, atts) \
    00238   (((enc)->getAtts)(enc, ptr, attsMax, atts))
    00239
    00240 #define XmlCharRefNumber(enc, ptr) \
    00241   (((enc)->charRefNumber)(enc, ptr))
    00242
    00243 #define XmlPredefinedEntityName(enc, ptr, end) \
    00244   (((enc)->predefinedEntityName)(enc, ptr, end))
    00245
    00246 #define XmlUpdatePosition(enc, ptr, end, pos) \
    00247   (((enc)->updatePosition)(enc, ptr, end, pos))
    00248
    00249 #define XmlIsPublicId(enc, ptr, end, badPtr) \
    00250   (((enc)->isPublicId)(enc, ptr, end, badPtr))
    00251
    00252 #define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
    00253   (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
    00254
    00255 #define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
    00256   (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
    00257
    00258 typedef struct {
    00259   ENCODING initEnc;
    00260   const ENCODING **encPtr;
    00261 } INIT_ENCODING;
    00262
    00263 int XMLTOKAPI XmlParseXmlDecl(int isGeneralTextEntity,
    00264                               const ENCODING *enc,
    00265                               const char *ptr,
    00266                               const char *end,
    00267                               const char **badPtr,
    00268                               const char **versionPtr,
    00269                               const char **encodingNamePtr,
    00270                               const ENCODING **namedEncodingPtr,
    00271                               int *standalonePtr);
    00272
    00273 int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
    00274 const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding();
    00275 const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding();
    00276 int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf);
    00277 int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf);
    00278
    00279 int XMLTOKAPI XmlSizeOfUnknownEncoding();
    00280 ENCODING XMLTOKAPI *
    00281 XmlInitUnknownEncoding(void *mem,
    00282                        int *table,
    00283                        int (*conv)(void *userData, const char *p),
    00284                        void *userData);
    00285
    00286 int XMLTOKAPI XmlParseXmlDeclNS(int isGeneralTextEntity,
    00287                                 const ENCODING *enc,
    00288                                 const char *ptr,
    00289                                 const char *end,
    00290                                 const char **badPtr,
    00291                                 const char **versionPtr,
    00292                                 const char **encodingNamePtr,
    00293                                 const ENCODING **namedEncodingPtr,
    00294                                 int *standalonePtr);
    00295 int XMLTOKAPI XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
    00296 const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncodingNS();
    00297 const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncodingNS();
    00298 ENCODING XMLTOKAPI *
    00299 XmlInitUnknownEncodingNS(void *mem,
    00300                          int *table,
    00301                          int (*conv)(void *userData, const char *p),
    00302                          void *userData);
    00303 #ifdef __cplusplus
    00304 }
    00305 #endif
    00306
    00307 #endif /* not XmlTok_INCLUDED */

@ 1.3 log @Oops, try again. @ text @d316 1 a316 1