xmltok_ns.c
上传用户:hmc_gdtv
上传日期:2013-08-04
资源大小:798k
文件大小:3k
源码类别:

Windows Mobile

开发平台:

Visual C++

  1. const ENCODING *
  2. NS(XmlGetUtf8InternalEncoding)(void)
  3. {
  4.   return &ns(internal_utf8_encoding).enc;
  5. }
  6. const ENCODING *
  7. NS(XmlGetUtf16InternalEncoding)(void)
  8. {
  9. #if BYTEORDER == 1234
  10.   return &ns(internal_little2_encoding).enc;
  11. #elif BYTEORDER == 4321
  12.   return &ns(internal_big2_encoding).enc;
  13. #else
  14.   const short n = 1;
  15.   return (*(const char *)&n
  16.           ? &ns(internal_little2_encoding).enc
  17.           : &ns(internal_big2_encoding).enc);
  18. #endif
  19. }
  20. static const ENCODING *NS(encodings)[] = {
  21.   &ns(latin1_encoding).enc,
  22.   &ns(ascii_encoding).enc,
  23.   &ns(utf8_encoding).enc,
  24.   &ns(big2_encoding).enc,
  25.   &ns(big2_encoding).enc,
  26.   &ns(little2_encoding).enc,
  27.   &ns(utf8_encoding).enc /* NO_ENC */
  28. };
  29. static int PTRCALL
  30. NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
  31.                    const char **nextTokPtr)
  32. {
  33.   return initScan(NS(encodings), (const INIT_ENCODING *)enc,
  34.                   XML_PROLOG_STATE, ptr, end, nextTokPtr);
  35. }
  36. static int PTRCALL
  37. NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
  38.                     const char **nextTokPtr)
  39. {
  40.   return initScan(NS(encodings), (const INIT_ENCODING *)enc,
  41.                   XML_CONTENT_STATE, ptr, end, nextTokPtr);
  42. }
  43. int
  44. NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
  45.                     const char *name)
  46. {
  47.   int i = getEncodingIndex(name);
  48.   if (i == UNKNOWN_ENC)
  49.     return 0;
  50.   SET_INIT_ENC_INDEX(p, i);
  51.   p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
  52.   p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
  53.   p->initEnc.updatePosition = initUpdatePosition;
  54.   p->encPtr = encPtr;
  55.   *encPtr = &(p->initEnc);
  56.   return 1;
  57. }
  58. static const ENCODING *
  59. NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
  60. {
  61. #define ENCODING_MAX 128
  62.   char buf[ENCODING_MAX];
  63.   char *p = buf;
  64.   int i;
  65.   XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
  66.   if (ptr != end)
  67.     return 0;
  68.   *p = 0;
  69.   if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
  70.     return enc;
  71.   i = getEncodingIndex(buf);
  72.   if (i == UNKNOWN_ENC)
  73.     return 0;
  74.   return NS(encodings)[i];
  75. }
  76. int
  77. NS(XmlParseXmlDecl)(int isGeneralTextEntity,
  78.                     const ENCODING *enc,
  79.                     const char *ptr,
  80.                     const char *end,
  81.                     const char **badPtr,
  82.                     const char **versionPtr,
  83.                     const char **versionEndPtr,
  84.                     const char **encodingName,
  85.                     const ENCODING **encoding,
  86.                     int *standalone)
  87. {
  88.   return doParseXmlDecl(NS(findEncoding),
  89.                         isGeneralTextEntity,
  90.                         enc,
  91.                         ptr,
  92.                         end,
  93.                         badPtr,
  94.                         versionPtr,
  95.                         versionEndPtr,
  96.                         encodingName,
  97.                         encoding,
  98.                         standalone);
  99. }