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.

112 lines
2.3 KiB

  1. /*
  2. * H D R I T E R . H
  3. *
  4. * Comma-separated header iterator
  5. *
  6. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  7. */
  8. #ifndef _HDRITER_H_
  9. #define _HDRITER_H_
  10. // Check if the given character is whitespace
  11. //
  12. template<class X>
  13. inline BOOL WINAPI FIsWhiteSpace( const X ch )
  14. {
  15. BOOL f;
  16. if (sizeof(X) == sizeof(WCHAR))
  17. {
  18. f = !!wcschr(gc_wszLWS, static_cast<const WCHAR>(ch));
  19. }
  20. else
  21. {
  22. f = !!strchr(gc_szLWS, static_cast<const CHAR>(ch));;
  23. }
  24. return f;
  25. }
  26. // Comma-separated header iterator -------------------------------------------
  27. //
  28. template<class T>
  29. class HDRITER_TEMPLATE
  30. {
  31. private:
  32. const T * m_pszHdr;
  33. const T * m_pch;
  34. StringBuffer<T> m_buf;
  35. // NOT IMPLEMENTED
  36. //
  37. HDRITER_TEMPLATE& operator=( const HDRITER_TEMPLATE& );
  38. HDRITER_TEMPLATE( const HDRITER_TEMPLATE& );
  39. public:
  40. HDRITER_TEMPLATE (const T * psz=0) : m_pszHdr(psz), m_pch(psz) {}
  41. ~HDRITER_TEMPLATE() {}
  42. // Accessors -------------------------------------------------------------
  43. //
  44. void Restart() { m_pch = m_pszHdr; }
  45. void NewHeader(const T * psz) { m_pch = m_pszHdr = psz; }
  46. const T * PszRaw(VOID) const { return m_pch; }
  47. const T * PszNext(VOID)
  48. {
  49. const T * psz;
  50. const T * pszEnd;
  51. // If no header existed, then there is nothing to do
  52. //
  53. if (m_pch == NULL)
  54. return NULL;
  55. // Eat all the white space
  56. //
  57. while (*m_pch && FIsWhiteSpace<T>(*m_pch))
  58. m_pch++;
  59. // There is nothing left to process
  60. //
  61. if (*m_pch == 0)
  62. return NULL;
  63. // Record the start of the current segment and zip
  64. // along until you find the end of the new segment
  65. //
  66. psz = m_pch;
  67. while (*m_pch && (*m_pch != ','))
  68. m_pch++;
  69. // Need to eat all the trailing white spaces
  70. //
  71. pszEnd = m_pch - 1;
  72. while ((pszEnd >= psz) && FIsWhiteSpace<T>(*pszEnd))
  73. pszEnd--;
  74. // The difference between, the two pointers gives us
  75. // the size of the current entry.
  76. //
  77. m_buf.AppendAt (0, static_cast<UINT>(pszEnd - psz + 1) * sizeof(T), psz);
  78. m_buf.FTerminate ();
  79. // Skip the trailing comma, if any.
  80. //
  81. if (*m_pch == ',')
  82. m_pch++;
  83. // Return the string
  84. //
  85. return m_buf.PContents();
  86. }
  87. };
  88. typedef HDRITER_TEMPLATE<CHAR> HDRITER;
  89. typedef HDRITER_TEMPLATE<CHAR> HDRITER_A;
  90. typedef HDRITER_TEMPLATE<WCHAR> HDRITER_W;
  91. #endif // _HDRITER_H_