Leaked source code of windows server 2003
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.

88 lines
2.7 KiB

  1. #ifndef C_GB18030_H
  2. #define C_GB18030_H
  3. #define CODEPAGE_GBK 936
  4. #define GB18030_CODEPAGE 54936
  5. #define GB18030_MAX_CHAR_SIZE 4
  6. #define GB18030_DEFAULT_UNICODE_CHAR L'\x003f'
  7. #define GB18030_DEFAULT_CHAR '\x3f'
  8. //
  9. // Lead byte = 0x81 ~ 0xfe
  10. //
  11. #define IS_GB_LEAD_BYTE(ch) ((ch) >= 0x81 && (ch) <= 0xfe)
  12. //
  13. // Trailing byte for two-byte GB18030: 0x40 ~ 0x7e, 0x80 ~ 0xfe
  14. //
  15. #define IS_GB_TWO_BYTES_TRAILING(ch) \
  16. (((ch) >= 0x40 && (ch) <= 0x7e) || \
  17. ((ch) >= 0x80 && (ch) <= 0xfe))
  18. #define GBK2K_BYTE1_MIN 0x81
  19. #define GBK2K_BYTE1_MAX 0xfe
  20. #define GBK2K_BYTE2_MIN 0x30
  21. #define GBK2K_BYTE2_MAX 0x39
  22. #define GBK2K_BYTE3_MIN 0x81
  23. #define GBK2K_BYTE3_MAX 0xfe
  24. #define GBK2K_BYTE4_MIN 0x30
  25. #define GBK2K_BYTE4_MAX 0x39
  26. #define GBK2K_BYTE1_RANGE (GBK2K_BYTE1_MAX - GBK2K_BYTE1_MIN + 1)
  27. #define GBK2K_BYTE2_RANGE (GBK2K_BYTE2_MAX - GBK2K_BYTE2_MIN + 1)
  28. #define GBK2K_BYTE3_RANGE (GBK2K_BYTE3_MAX - GBK2K_BYTE3_MIN + 1)
  29. #define GBK2K_BYTE4_RANGE (GBK2K_BYTE4_MAX - GBK2K_BYTE4_MIN + 1)
  30. //
  31. // Trailing byte for four-byte GB18030: 0x30 ~ 0x39
  32. //
  33. #define IS_GB_FOUR_BYTES_TRAILING(ch) ((ch) >= 0x30 && (ch) <= 0x39)
  34. #define GET_FOUR_BYTES_OFFSET(offset1, offset2, offset3, offset4) \
  35. ((offset1) * GBK2K_BYTE2_RANGE * GBK2K_BYTE3_RANGE * GBK2K_BYTE4_RANGE + \
  36. (offset2) * GBK2K_BYTE3_RANGE * GBK2K_BYTE4_RANGE + \
  37. (offset3) * GBK2K_BYTE4_RANGE + offset4)
  38. #define GET_FOUR_BYTES_OFFSET_FROM_BYTES(byte1, byte2, byte3, byte4) \
  39. (((byte1) - GBK2K_BYTE1_MIN) * GBK2K_BYTE2_RANGE * GBK2K_BYTE3_RANGE * GBK2K_BYTE4_RANGE + \
  40. ((byte2) - GBK2K_BYTE2_MIN) * GBK2K_BYTE3_RANGE * GBK2K_BYTE4_RANGE + \
  41. ((byte3) - GBK2K_BYTE3_MIN) * GBK2K_BYTE4_RANGE + \
  42. ((byte4) - GBK2K_BYTE4_MIN))
  43. #define IS_HIGH_SURROGATE(wch) (((wch) >= 0xd800) && ((wch) <= 0xdbff))
  44. #define IS_LOW_SURROGATE(wch) (((wch) >= 0xdc00) && ((wch) <= 0xdfff))
  45. extern const BYTE g_wUnicodeToGBTwoBytes[];
  46. extern const WORD g_wUnicodeToGB[];
  47. extern const WORD g_wMax4BytesOffset;
  48. extern const DWORD g_dwSurrogateOffset;
  49. extern const WORD g_wGBFourBytesToUnicode[];
  50. extern const WORD g_wGBLeadByteOffset[];
  51. extern const WORD g_wUnicodeFromGBTwoBytes[];
  52. DWORD GetBytesToUnicodeCount(
  53. BYTE* lpMultiByteStr,
  54. int cchMultiByte,
  55. BOOL bSupportDecoder);
  56. STDAPI_(DWORD) BytesToUnicode(
  57. BYTE* lpMultiByteStr,
  58. UINT cchMultiByte,
  59. UINT* pcchLeftOverBytes,
  60. LPWSTR lpWideCharStr,
  61. UINT cchWideChar);
  62. DWORD GetUnicodeToBytesCount(
  63. LPWSTR lpWideCharStr,
  64. int cchWideChar);
  65. STDAPI_(DWORD) UnicodeToBytes(
  66. LPWSTR lpWideCharStr,
  67. UINT cchWideChar,
  68. LPSTR lpMultiByteStr,
  69. UINT cchMultiByte);
  70. #endif