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.

106 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1991-2000, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. utf.h
  5. Abstract:
  6. This file contains the header information for the UTF module of NLS.
  7. Revision History:
  8. 02-06-96 JulieB Created.
  9. --*/
  10. //
  11. // Constant Declarations.
  12. //
  13. #define ASCII 0x007f
  14. #define SHIFT_IN '+' // beginning of a shift sequence
  15. #define SHIFT_OUT '-' // end of a shift sequence
  16. #define UTF8_2_MAX 0x07ff // max UTF8 2-byte sequence (32 * 64 = 2048)
  17. #define UTF8_1ST_OF_2 0xc0 // 110x xxxx
  18. #define UTF8_1ST_OF_3 0xe0 // 1110 xxxx
  19. #define UTF8_1ST_OF_4 0xf0 // 1111 xxxx
  20. #define UTF8_TRAIL 0x80 // 10xx xxxx
  21. #define HIGHER_6_BIT(u) ((u) >> 12)
  22. #define MIDDLE_6_BIT(u) (((u) & 0x0fc0) >> 6)
  23. #define LOWER_6_BIT(u) ((u) & 0x003f)
  24. #define BIT7(a) ((a) & 0x80)
  25. #define BIT6(a) ((a) & 0x40)
  26. #define HIGH_SURROGATE_START 0xd800
  27. #define HIGH_SURROGATE_END 0xdbff
  28. #define LOW_SURROGATE_START 0xdc00
  29. #define LOW_SURROGATE_END 0xdfff
  30. /////////////////////////
  31. // //
  32. // Unicode -> UTF-7 //
  33. // //
  34. /////////////////////////
  35. //
  36. // Convert one Unicode to 2 2/3 Base64 chars in a shifted sequence.
  37. // Each char represents a 6-bit portion of the 16-bit Unicode char.
  38. //
  39. CONST char cBase64[] =
  40. "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // A : 000000 .... 011001 ( 0 - 25)
  41. "abcdefghijklmnopqrstuvwxyz" // a : 011010 .... 110011 (26 - 51)
  42. "0123456789" // 0 : 110100 .... 111101 (52 - 61)
  43. "+/"; // + : 111110, / : 111111 (62 - 63)
  44. //
  45. // To determine if an ASCII char needs to be shifted.
  46. // 1 : to be shifted
  47. // 0 : not to be shifted
  48. //
  49. CONST BOOLEAN fShiftChar[] =
  50. {
  51. 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // Null, Tab, LF, CR
  52. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  53. 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, // Space '() +,-./
  54. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, // 0123456789: ?
  55. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ABCDEFGHIJKLMNO
  56. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, // PQRSTUVWXYZ
  57. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // abcdefghijklmno
  58. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 // pqrstuvwxyz
  59. };
  60. /////////////////////////
  61. // //
  62. // UTF-7 -> Unicode //
  63. // //
  64. /////////////////////////
  65. //
  66. // Convert a Base64 char in a shifted sequence to a 6-bit portion of a
  67. // Unicode char.
  68. // -1 means it is not a Base64
  69. //
  70. CONST char nBitBase64[] =
  71. {
  72. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  73. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  74. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, // + /
  75. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 0123456789
  76. -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // ABCDEFGHIJKLMNO
  77. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, // PQRSTUVWXYZ
  78. -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // abcdefghijklmno
  79. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 // pqrstuvwxyz
  80. };