home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 September / CHIPCD_9_99.iso / software / uaktualnienia / OptionPackPL / iis4_07.cab / token.h < prev    next >
C/C++ Source or Header  |  1998-04-27  |  2KB  |  111 lines

  1. #ifndef __TOKEN_H__
  2. #define __TOKEN_H__
  3.  
  4. #include <string>
  5. #include <tchar.h>
  6.  
  7. #include "state.h"
  8. #include "trie.h"
  9.  
  10.  
  11. //+---------------------------------------------------------------------
  12. // CToken:
  13.  
  14. class CToken
  15. {
  16. public:
  17.     enum BOUNDARY {
  18.         IRRELEVANT = 1,
  19.         WHITESPACE,
  20.         ALPHA,
  21.         NUMERIC,
  22.         ALPHANUMERIC,
  23.         NEWLINE,
  24.     };
  25.  
  26.     CToken(
  27.         const string&  rstr,
  28.         const BOUNDARY bndPrefix = IRRELEVANT,
  29.         const BOUNDARY bndSuffix = IRRELEVANT);
  30.  
  31.     static BOOL
  32.     MatchesBoundaryClass(
  33.         const TCHAR    tch,
  34.         const BOUNDARY bnd);
  35.  
  36.     BOOL
  37.     MatchesPrefixBoundary(
  38.         const TCHAR tch) const
  39.     {return MatchesBoundaryClass(tch, m_bndPrefix);}
  40.  
  41.     BOOL
  42.     MatchesSuffixBoundary(
  43.         const TCHAR tch) const
  44.     {return MatchesBoundaryClass(tch, m_bndSuffix);}
  45.  
  46.     virtual UINT
  47.     CountBytes(
  48.         CStateStack& rss,
  49.         LPCTSTR      ptszData,
  50.         UINT         cchData) const = 0;
  51.  
  52.     virtual UINT
  53.     DoFilter(
  54.         CStateStack& rss,
  55.         LPCTSTR&     rptszData,
  56.         UINT         cchData,
  57.         LPTSTR&      rptszOutBuf) const;
  58.  
  59.     const string    m_str;
  60.     const BOUNDARY  m_bndPrefix;
  61.     const BOUNDARY  m_bndSuffix;
  62.     
  63. // Implementation
  64. public:
  65. #ifdef _DEBUG
  66.     virtual void
  67.     AssertValid() const;
  68.  
  69.     virtual void
  70.     Dump() const;
  71. #endif
  72.  
  73.     virtual
  74.     ~CToken();
  75. };
  76.  
  77.  
  78.  
  79. //+---------------------------------------------------------------------
  80. // CTokenTrie:
  81.  
  82. class CTokenTrie : public CTrie<CToken, true, true>
  83. {
  84. public:
  85.     CTokenTrie();
  86.     
  87.     bool
  88.     AddToken(
  89.         const CToken* ptok);
  90.     
  91.     int
  92.     EndOfBuffer(
  93.         PHTTP_FILTER_RAW_DATA pRawData,
  94.         int iStart);
  95.     
  96. private:
  97.     // bit array for last letter of all tokens
  98.     BYTE  m_afLastChar[(CHAR_MAX - CHAR_MIN + 1 + 7) / 8];
  99.  
  100.     bool
  101.     _LastCharPresent(
  102.         CHAR ch) const;
  103.  
  104.     void
  105.     _SetLastCharPresent(
  106.         CHAR ch,
  107.         bool f);
  108. };
  109.  
  110. #endif // __TOKEN_H__
  111.