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.

149 lines
3.7 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // DelimitedIterator.h
  7. //
  8. // Description:
  9. // This file contains the declaration of the CDelimitedIterator class.
  10. //
  11. // Documentation:
  12. //
  13. // Implementation Files:
  14. // DelimitedIterator.cpp
  15. //
  16. // Maintained By:
  17. // John Franco (jfranco) 26-Oct-2001
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. // Make sure that this file is included only once per compile path.
  21. #pragma once
  22. //////////////////////////////////////////////////////////////////////////////
  23. // Include Files
  24. //////////////////////////////////////////////////////////////////////////////
  25. //////////////////////////////////////////////////////////////////////////////
  26. // Constant Declarations
  27. //////////////////////////////////////////////////////////////////////////////
  28. //////////////////////////////////////////////////////////////////////////////
  29. //++
  30. //
  31. // class CDelimitedIterator
  32. //
  33. // Description:
  34. //
  35. // This class iterates through delimited items in a string.
  36. // Multiple delimiters are possible, and any number of them can precede,
  37. // follow, or be interspersed among the items in the string.
  38. //
  39. // The class does not make private copies of the item string or of the
  40. // string that specifies the delimiters, so the client must ensure that
  41. // the strings are valid throughout the iterator's lifetime.
  42. //
  43. // The class modifies the string of delimited items as it iterates.
  44. //
  45. //--
  46. //////////////////////////////////////////////////////////////////////////////
  47. class CDelimitedIterator
  48. {
  49. public:
  50. CDelimitedIterator(
  51. LPCWSTR pwszDelimitersIn
  52. , LPWSTR pwszDelimitedListIn
  53. , size_t cchListIn
  54. );
  55. LPCWSTR Current( void ) const;
  56. void Next( void );
  57. private:
  58. // Hide copy constructor and assignment operator.
  59. CDelimitedIterator( const CDelimitedIterator & );
  60. CDelimitedIterator & operator=( const CDelimitedIterator & );
  61. void IsolateCurrent( void );
  62. LPCWSTR m_pwszDelimiters;
  63. LPWSTR m_pwszList;
  64. size_t m_cchList;
  65. size_t m_idxCurrent;
  66. size_t m_idxNext;
  67. }; //*** CDelimitedIterator
  68. //////////////////////////////////////////////////////////////////////////////
  69. //++
  70. //
  71. // CDelimitedIterator::Current
  72. //
  73. // Description:
  74. //
  75. // Arguments:
  76. // None.
  77. //
  78. // Return Value:
  79. // A pointer to the current item in the list, or NULL if the iterator
  80. // has reached the list's end.
  81. //
  82. // Remarks:
  83. // The pointer refers to part of the original string, so the caller must
  84. // NOT delete the pointer.
  85. //
  86. //--
  87. //////////////////////////////////////////////////////////////////////////////
  88. inline
  89. LPCWSTR
  90. CDelimitedIterator::Current( void ) const
  91. {
  92. LPCWSTR pwszCurrent = NULL;
  93. if ( m_idxCurrent < m_cchList )
  94. {
  95. pwszCurrent = m_pwszList + m_idxCurrent;
  96. }
  97. return pwszCurrent;
  98. } //*** CDelimitedIterator::Current
  99. //////////////////////////////////////////////////////////////////////////////
  100. //++
  101. //
  102. // CDelimitedIterator::Next
  103. //
  104. // Description:
  105. // Advance to the next item in the string, if one exists and
  106. // the iterator has not already passed the last one.
  107. //
  108. // Arguments:
  109. // None.
  110. //
  111. // Return Value:
  112. // None.
  113. //
  114. // Remarks:
  115. //
  116. //--
  117. //////////////////////////////////////////////////////////////////////////////
  118. inline
  119. void
  120. CDelimitedIterator::Next( void )
  121. {
  122. m_idxCurrent = m_idxNext;
  123. IsolateCurrent();
  124. } //*** CDelimitedIterator::Next