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.

139 lines
3.4 KiB

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