Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.8 KiB

  1. /*
  2. * @(#)CharEncoder.hxx 1.0 6/10/97
  3. *
  4. * Copyright (c) 1997 - 1999 Microsoft Corporation. All rights reserved. *
  5. */
  6. #ifndef _FUSION_XMLPARSER__CHARENCODER_HXX
  7. #define _FUSION_XMLPARSER__CHARENCODER_HXX
  8. #pragma once
  9. #include "codepage.h"
  10. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  11. #include "mlang.h"
  12. #endif
  13. typedef HRESULT WideCharFromMultiByteFunc(DWORD* pdwMode, CODEPAGE codepage, BYTE * bytebuffer,
  14. UINT * cb, WCHAR * buffer, UINT * cch);
  15. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  16. typedef HRESULT WideCharToMultiByteFunc(DWORD* pdwMode, CODEPAGE codepage, WCHAR * buffer,
  17. UINT *cch, BYTE * bytebuffer, UINT * cb);
  18. #endif
  19. struct EncodingEntry
  20. {
  21. UINT codepage;
  22. WCHAR * charset;
  23. UINT maxCharSize;
  24. WideCharFromMultiByteFunc * pfnWideCharFromMultiByte;
  25. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  26. WideCharToMultiByteFunc * pfnWideCharToMultiByte;
  27. #endif
  28. };
  29. class Encoding
  30. {
  31. protected:
  32. Encoding() {};
  33. public:
  34. // default encoding is UTF-8.
  35. static Encoding* newEncoding(const WCHAR * s = L"UTF-8", ULONG len = 5, bool endian = false, bool mark = false);
  36. virtual ~Encoding();
  37. WCHAR * charset; // charset
  38. bool littleendian; // endian flag for UCS-2/UTF-16 encoding, true: little endian, false: big endian
  39. bool byteOrderMark; // byte order mark (BOM) flag, BOM appears when true
  40. };
  41. /**
  42. *
  43. * An Encoder specifically for dealing with different encoding formats
  44. * @version 1.0, 6/10/97
  45. */
  46. class NOVTABLE CharEncoder
  47. {
  48. //
  49. // class CharEncoder is a utility class, makes sure no instance can be defined
  50. //
  51. private: virtual charEncoder() = 0;
  52. public:
  53. static HRESULT getWideCharFromMultiByteInfo(Encoding * encoding, CODEPAGE * pcodepage, WideCharFromMultiByteFunc ** pfnWideCharFromMultiByte, UINT * mCharSize);
  54. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  55. static HRESULT getWideCharToMultiByteInfo(Encoding * encoding, CODEPAGE * pcodepage, WideCharToMultiByteFunc ** pfnWideCharToMultiByte, UINT * mCharSize);
  56. #endif
  57. /**
  58. * Encoding functions: get Unicode from other encodings
  59. */
  60. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  61. static WideCharFromMultiByteFunc wideCharFromUcs4Bigendian;
  62. static WideCharFromMultiByteFunc wideCharFromUcs4Littleendian;
  63. static WideCharFromMultiByteFunc wideCharFromUtf7;
  64. static WideCharFromMultiByteFunc wideCharFromAnsiLatin1;
  65. static WideCharFromMultiByteFunc wideCharFromMultiByteWin32;
  66. static WideCharFromMultiByteFunc wideCharFromMultiByteMlang;
  67. #endif
  68. // actually, we only use these three functions for UCS-2 and UTF-8
  69. static WideCharFromMultiByteFunc wideCharFromUtf8;
  70. static WideCharFromMultiByteFunc wideCharFromUcs2Bigendian;
  71. static WideCharFromMultiByteFunc wideCharFromUcs2Littleendian;
  72. /**
  73. * Encoding functions: from Unicode to other encodings
  74. */
  75. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  76. static WideCharToMultiByteFunc wideCharToUcs2Bigendian;
  77. static WideCharToMultiByteFunc wideCharToUcs2Littleendian;
  78. static WideCharToMultiByteFunc wideCharToUcs4Bigendian;
  79. static WideCharToMultiByteFunc wideCharToUcs4Littleendian;
  80. static WideCharToMultiByteFunc wideCharToUtf8;
  81. static WideCharToMultiByteFunc wideCharToUtf7;
  82. static WideCharToMultiByteFunc wideCharToAnsiLatin1;
  83. static WideCharToMultiByteFunc wideCharToMultiByteWin32;
  84. static WideCharToMultiByteFunc wideCharToMultiByteMlang;
  85. #endif
  86. static int getCharsetInfo(const WCHAR * charset, CODEPAGE * pcodepage, UINT * mCharSize);
  87. private:
  88. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  89. static HRESULT _EnsureMultiLanguage();
  90. #endif
  91. private:
  92. #ifdef FUSION_USE_OLD_XML_PARSER_SOURCE
  93. static IMultiLanguage * pMultiLanguage;
  94. #endif
  95. static const EncodingEntry charsetInfo [];
  96. };
  97. #endif _FUSION_XMLPARSER__CHARENCODER_HXX