Back to index

lightning-sunbird  0.9+nobinonly
xmltok_ns.c
Go to the documentation of this file.
00001 const ENCODING *
00002 NS(XmlGetUtf8InternalEncoding)(void)
00003 {
00004   return &ns(internal_utf8_encoding).enc;
00005 }
00006 
00007 const ENCODING *
00008 NS(XmlGetUtf16InternalEncoding)(void)
00009 {
00010 #if BYTEORDER == 1234
00011   return &ns(internal_little2_encoding).enc;
00012 #elif BYTEORDER == 4321
00013   return &ns(internal_big2_encoding).enc;
00014 #else
00015   const short n = 1;
00016   return (*(const char *)&n
00017           ? &ns(internal_little2_encoding).enc
00018           : &ns(internal_big2_encoding).enc);
00019 #endif
00020 }
00021 
00022 static const ENCODING *NS(encodings)[] = {
00023   &ns(latin1_encoding).enc,
00024   &ns(ascii_encoding).enc,
00025   &ns(utf8_encoding).enc,
00026   &ns(big2_encoding).enc,
00027   &ns(big2_encoding).enc,
00028   &ns(little2_encoding).enc,
00029   &ns(utf8_encoding).enc /* NO_ENC */
00030 };
00031 
00032 static int PTRCALL
00033 NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
00034                    const char **nextTokPtr)
00035 {
00036   return initScan(NS(encodings), (const INIT_ENCODING *)enc,
00037                   XML_PROLOG_STATE, ptr, end, nextTokPtr);
00038 }
00039 
00040 static int PTRCALL
00041 NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
00042                     const char **nextTokPtr)
00043 {
00044   return initScan(NS(encodings), (const INIT_ENCODING *)enc,
00045                   XML_CONTENT_STATE, ptr, end, nextTokPtr);
00046 }
00047 
00048 int
00049 NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
00050                     const char *name)
00051 {
00052   int i = getEncodingIndex(name);
00053   if (i == UNKNOWN_ENC)
00054     return 0;
00055   SET_INIT_ENC_INDEX(p, i);
00056   p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
00057   p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
00058   p->initEnc.updatePosition = initUpdatePosition;
00059   p->encPtr = encPtr;
00060   *encPtr = &(p->initEnc);
00061   return 1;
00062 }
00063 
00064 static const ENCODING *
00065 NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
00066 {
00067 #define ENCODING_MAX 128
00068   char buf[ENCODING_MAX];
00069   char *p = buf;
00070   int i;
00071   XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
00072   if (ptr != end)
00073     return 0;
00074   *p = 0;
00075   if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
00076     return enc;
00077   i = getEncodingIndex(buf);
00078   if (i == UNKNOWN_ENC)
00079     return 0;
00080   return NS(encodings)[i];
00081 }
00082 
00083 int
00084 NS(XmlParseXmlDecl)(int isGeneralTextEntity,
00085                     const ENCODING *enc,
00086                     const char *ptr,
00087                     const char *end,
00088                     const char **badPtr,
00089                     const char **versionPtr,
00090                     const char **versionEndPtr,
00091                     const char **encodingName,
00092                     const ENCODING **encoding,
00093                     int *standalone)
00094 {
00095   return doParseXmlDecl(NS(findEncoding),
00096                         isGeneralTextEntity,
00097                         enc,
00098                         ptr,
00099                         end,
00100                         badPtr,
00101                         versionPtr,
00102                         versionEndPtr,
00103                         encodingName,
00104                         encoding,
00105                         standalone);
00106 }