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.

104 lines
5.4 KiB

  1. // --------------------------------------------------------------------------------
  2. // Strparse.h
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #ifndef __STRPARSE_H
  6. #define __STRPARSE_H
  7. typedef DWORD CODEPAGEID;
  8. // --------------------------------------------------------------------------------
  9. // Parse Flags, pass to CStringParser::Init
  10. // --------------------------------------------------------------------------------
  11. #define PSF_NOTRAILWS 0x00000001 // String trailing whitespace from pszValue
  12. #define PSF_NOFRONTWS 0x00000002 // Skip white space before searching for tokens
  13. #define PSF_ESCAPED 0x00000004 // Detect escaped characters such as '\\' or '\"'
  14. #define PSF_DBCS 0x00000008 // The String could contain DBCS characters
  15. #define PSF_NOCOMMENTS 0x00000010 // Skips comments (comment)
  16. #define PSF_NORESET 0x00000020 // Don't reset the destination buffer on ChParse
  17. // --------------------------------------------------------------------------------
  18. // LITERALINFO
  19. // --------------------------------------------------------------------------------
  20. typedef struct tagLITERALINFO {
  21. BYTE fInside; // Are we in a literal
  22. CHAR chStart; // Starting literal delimiter
  23. CHAR chEnd; // Ending literal delimiter if chEnd == chStart, no nesting
  24. DWORD cNested; // Number of nested delimiters
  25. } LITERALINFO, *LPLITERALINFO;
  26. // --------------------------------------------------------------------------------
  27. // CStringParser
  28. // --------------------------------------------------------------------------------
  29. class CStringParser
  30. {
  31. public:
  32. // ----------------------------------------------------------------------------
  33. // Construction
  34. // ----------------------------------------------------------------------------
  35. CStringParser(void);
  36. ~CStringParser(void);
  37. // ----------------------------------------------------------------------------
  38. // IUnknown methods
  39. // ----------------------------------------------------------------------------
  40. STDMETHODIMP_(ULONG) AddRef(void);
  41. STDMETHODIMP_(ULONG) Release(void);
  42. // ----------------------------------------------------------------------------
  43. // CStringParser Methods
  44. // ----------------------------------------------------------------------------
  45. void Init(LPCSTR pszParseMe, ULONG cchParseMe, DWORD dwFlags);
  46. void SetTokens(LPCSTR pszTokens);
  47. CHAR ChSkip(void);
  48. CHAR ChParse(void);
  49. CHAR ChSkipWhite(void);
  50. CHAR ChPeekNext(ULONG cchFromCurrent);
  51. HRESULT HrAppendValue(CHAR ch);
  52. // ----------------------------------------------------------------------------
  53. // Inline CStringParser Methods
  54. // ----------------------------------------------------------------------------
  55. UINT GetCP(void) { return m_codepage; }
  56. void SetCodePage(CODEPAGEID codepage) { m_codepage = codepage; }
  57. void SetIndex(ULONG iIndex) { m_iSource = iIndex; }
  58. CHAR ChSkip(LPCSTR pszTokens) { SetTokens(pszTokens); return ChSkip(); }
  59. CHAR ChParse(LPCSTR pszTokens, DWORD dwFlags);
  60. CHAR ChParse(LPCSTR pszTokens) { SetTokens(pszTokens); return ChParse(); }
  61. CHAR ChParse(CHAR chStart, CHAR chEnd, DWORD dwFlags);
  62. ULONG GetLength(void) { return m_cchSource; }
  63. ULONG GetIndex(void) { return m_iSource; }
  64. LPCSTR PszValue(void) { Assert(m_pszDest && '\0' == m_pszDest[m_cchDest]); return m_pszDest; }
  65. ULONG CchValue(void) { Assert(m_pszDest && '\0' == m_pszDest[m_cchDest]); return m_cchDest; }
  66. void FlagSet(DWORD dwFlags) { FLAGSET(m_dwFlags, dwFlags); }
  67. void FlagClear(DWORD dwFlags) { FLAGCLEAR(m_dwFlags, dwFlags); }
  68. BOOL FIsParseSpace(CHAR ch, BOOL *pfCommentChar);
  69. private:
  70. // ----------------------------------------------------------------------------
  71. // Private Methods
  72. // ----------------------------------------------------------------------------
  73. HRESULT _HrGrowDestination(ULONG cbWrite);
  74. HRESULT _HrDoubleByteIncrement(BOOL fEscape);
  75. private:
  76. // ----------------------------------------------------------------------------
  77. // Private Data
  78. // ----------------------------------------------------------------------------
  79. ULONG m_cRef; // Reference Count
  80. CODEPAGEID m_codepage; // Code page to use to parse the string
  81. LPCSTR m_pszSource; // String to parse
  82. ULONG m_cchSource; // Length of pszString
  83. ULONG m_iSource; // Index into m_pszString
  84. LPSTR m_pszDest; // Destination buffer
  85. ULONG m_cchDest; // Write Index/size of dest buffer
  86. ULONG m_cbDestMax; // Maximum size of m_pszDest
  87. DWORD m_dwFlags; // Parse String Flags
  88. CHAR m_szScratch[256]; // Scratch Buffer
  89. BYTE m_rgbTokTable[256]; // Token Table
  90. LPCSTR m_pszTokens; // Current Parse Tokens
  91. ULONG m_cCommentNest; // Nested comment parens
  92. LITERALINFO m_rLiteral; // Literal Information
  93. };
  94. #endif // __STRPARSE_H