xmltok_ns.c 2.4 KB

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