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.

129 lines
3.8 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // DelimitedIterator.cpp
  7. //
  8. // Header Files:
  9. // DelimitedIterator.h
  10. //
  11. // Description:
  12. // This file contains the implementation of the CDelimitedIterator class.
  13. //
  14. // Maintained By:
  15. // John Franco (jfranco) 26-Oct-2001
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19. // Include Files
  20. //////////////////////////////////////////////////////////////////////////////
  21. #include "Pch.h"
  22. #include "DelimitedIterator.h"
  23. //////////////////////////////////////////////////////////////////////////////
  24. // Constant Definitions
  25. //////////////////////////////////////////////////////////////////////////////
  26. DEFINE_THISCLASS( "CDelimitedIterator" );
  27. //*************************************************************************//
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CDelimitedIterator class
  30. /////////////////////////////////////////////////////////////////////////////
  31. //////////////////////////////////////////////////////////////////////////////
  32. //++
  33. //
  34. // CDelimitedIterator::CDelimitedIterator
  35. //
  36. // Description:
  37. //
  38. // Arguments:
  39. // pwszDelimitersIn
  40. // A null-terminated string consisting of those characters to treat
  41. // as delimiters.
  42. // pwszDelimitedListIn
  43. // The null-terminated string containing the delimited items.
  44. // cchListIn
  45. // The number of characters in pwszDelimitedListIn.
  46. //
  47. // Return Value:
  48. // None.
  49. //
  50. // Remarks:
  51. // None.
  52. //
  53. //--
  54. //////////////////////////////////////////////////////////////////////////////
  55. CDelimitedIterator::CDelimitedIterator(
  56. LPCWSTR pwszDelimitersIn
  57. , LPWSTR pwszDelimitedListIn
  58. , size_t cchListIn
  59. )
  60. : m_pwszDelimiters( pwszDelimitersIn )
  61. , m_pwszList( pwszDelimitedListIn )
  62. , m_cchList( cchListIn )
  63. , m_idxCurrent( 0 )
  64. , m_idxNext( 0 )
  65. {
  66. Assert( pwszDelimitersIn != NULL );
  67. Assert( pwszDelimitedListIn != NULL );
  68. IsolateCurrent();
  69. } //*** CDelimitedIterator::CDelimitedIterator
  70. //////////////////////////////////////////////////////////////////////////////
  71. //++
  72. //
  73. // CDelimitedIterator::IsolateCurrent
  74. //
  75. // Description:
  76. // Advance the current pointer to the next item (if any) in the list,
  77. // null out the first delimiter (if any) following the item, and advance
  78. // the next pointer to where the search for the next item should begin
  79. // after the iterator has advanced.
  80. //
  81. // Arguments:
  82. // None.
  83. //
  84. // Return Value:
  85. // None.
  86. //
  87. // Remarks:
  88. // None.
  89. //
  90. //--
  91. //////////////////////////////////////////////////////////////////////////////
  92. void
  93. CDelimitedIterator::IsolateCurrent( void )
  94. {
  95. // Skip any initial delimiters.
  96. while ( ( m_idxCurrent < m_cchList ) && ( wcschr( m_pwszDelimiters, m_pwszList[ m_idxCurrent ] ) != NULL ) )
  97. {
  98. m_idxCurrent += 1;
  99. }
  100. // Null next delimiter, if one exists, and remember its location (for finding next delimited item).
  101. if ( m_idxCurrent < m_cchList )
  102. {
  103. WCHAR * pwchNextDelimiter = wcspbrk( m_pwszList + m_idxCurrent, m_pwszDelimiters );
  104. if ( pwchNextDelimiter != NULL )
  105. {
  106. *pwchNextDelimiter = L'\0';
  107. m_idxNext = ( pwchNextDelimiter - m_pwszList ) + 1; // +1 means start after char that's null.
  108. }
  109. else // No more delimiters in string.
  110. {
  111. m_idxNext = m_cchList;
  112. }
  113. } // if not yet at end of string
  114. } //*** CDelimitedIterator::IsolateCurrent