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.

135 lines
3.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1991, Microsoft Corporation.
  4. //
  5. // File: XlatChar.hxx
  6. //
  7. // Contents: Character translation class.
  8. //
  9. // Classes: CXlatChar
  10. //
  11. // History: 01-20-92 KyleP Created
  12. // 03-11-97 arunk Modified for regex lib
  13. //
  14. //--------------------------------------------------------------------------
  15. #ifndef __XLATCHAR_HXX__
  16. #define __XLATCHAR_HXX__
  17. #include <windows.h>
  18. //
  19. // Special character equivalence classes. I suppose in theory these
  20. // could doubly map to character classes in the regex but nearly
  21. // every unicode symbol must be treated uniquely somewhere in the
  22. // regex for that to happen.
  23. //
  24. UINT const symAny = 1; // Any single character (except BEG/END LINE)
  25. UINT const symBeginLine = 2; // Special character indicating beginning
  26. // of line.
  27. UINT const symEndLine = 3; // Special character indicating end of line.
  28. UINT const symInvalid = 4; // Guaranteed invalid
  29. UINT const symEpsilon = 5; // Epsilon move.
  30. UINT const symDot = 6; // '.' Don't ask. It's for DOS compliance
  31. UINT const cSpecialCharClasses = symDot; // 'normal' character classes
  32. // start here.
  33. //
  34. // Wide character values less than or equal to symLastValidCharacter have
  35. // no special signifigance.
  36. //
  37. UINT const symLastValidChar = 0xffffffff;
  38. //+-------------------------------------------------------------------------
  39. //
  40. // Class: CXlatChar
  41. //
  42. // Purpose: Maps UniCode characters to equivalence class(es).
  43. //
  44. // History: 20-Jan-92 KyleP Created
  45. //
  46. // Notes: Equivalence classes must consist of sequential characters.
  47. // The implementation for this class is a sorted array of
  48. // characters. Each character marks the end of a range. The
  49. // class for a given character is found by binary searching
  50. // the array until you end up in the appropriate range.
  51. //
  52. //--------------------------------------------------------------------------
  53. class CXlatChar
  54. {
  55. public:
  56. CXlatChar( bool fCaseSens );
  57. CXlatChar( CXlatChar const & src );
  58. inline ~CXlatChar();
  59. void AddRange( WCHAR wcStart, WCHAR wcEnd );
  60. UINT Translate( WCHAR wc );
  61. UINT TranslateRange( WCHAR wcStart, WCHAR wcEnd );
  62. inline UINT NumClasses() const;
  63. void Prepare();
  64. private:
  65. UINT _Search( WCHAR wc );
  66. void _Realloc();
  67. WCHAR * _pwcRangeEnd; // Character in position i is the end
  68. // of the ith range.
  69. UINT _cRange;
  70. UINT _cAllocation;
  71. UINT _iPrevRange;
  72. bool _fCaseSens; // true if case sensitive mapping.
  73. };
  74. //+-------------------------------------------------------------------------
  75. //
  76. // Member: CXlatChar::NumClasses, public
  77. //
  78. // Returns: The number of different equivalence classes.
  79. //
  80. // History: 20-Jan-92 KyleP Created
  81. //
  82. //--------------------------------------------------------------------------
  83. inline UINT CXlatChar::NumClasses() const
  84. {
  85. return( _cRange + cSpecialCharClasses );
  86. }
  87. //+-------------------------------------------------------------------------
  88. //
  89. // Member: CXlatChar::~CXlatChar, public
  90. //
  91. // Synopsis: Destroys class.
  92. //
  93. // History: 20-Jan-92 KyleP Created
  94. //
  95. //--------------------------------------------------------------------------
  96. inline CXlatChar::~CXlatChar()
  97. {
  98. delete _pwcRangeEnd;
  99. }
  100. #endif //__XLATCHAR_HXX__