Source code of Windows XP (NT5)
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.

117 lines
2.5 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SIMTOK.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/12/1998
  12. *
  13. * DESCRIPTION: String tokenizer template class
  14. *
  15. *******************************************************************************/
  16. #ifndef _SIMTOK_H_INCLUDED
  17. #define _SIMTOK_H_INCLUDED
  18. #include "simstr.h"
  19. template <class T>
  20. class CSimpleStringToken
  21. {
  22. private:
  23. T m_strStr;
  24. int m_nIndex;
  25. public:
  26. CSimpleStringToken(void);
  27. CSimpleStringToken( const T &str );
  28. CSimpleStringToken( const CSimpleStringToken &other );
  29. CSimpleStringToken &operator=( const CSimpleStringToken &other );
  30. virtual ~CSimpleStringToken(void);
  31. void Reset(void);
  32. T Tokenize( const T &strDelim );
  33. T String(void) const;
  34. int Index(void) const;
  35. };
  36. template <class T>
  37. CSimpleStringToken<T>::CSimpleStringToken(void)
  38. :m_nIndex(0)
  39. {
  40. }
  41. template <class T>
  42. CSimpleStringToken<T>::CSimpleStringToken( const T &str )
  43. : m_strStr(str), m_nIndex(0)
  44. {
  45. }
  46. template <class T>
  47. CSimpleStringToken<T>::CSimpleStringToken( const CSimpleStringToken &other )
  48. : m_strStr(other.String()), m_nIndex(other.Index())
  49. {
  50. }
  51. template <class T>
  52. CSimpleStringToken<T> &CSimpleStringToken<T>::operator=( const CSimpleStringToken &other )
  53. {
  54. m_strStr = other.String();
  55. m_nIndex = other.Index();
  56. return *this;
  57. }
  58. template <class T>
  59. CSimpleStringToken<T>::~CSimpleStringToken(void)
  60. {
  61. }
  62. template <class T>
  63. void CSimpleStringToken<T>::Reset(void)
  64. {
  65. m_nIndex = 0;
  66. }
  67. template <class T>
  68. T CSimpleStringToken<T>::Tokenize( const T &strDelim )
  69. {
  70. T strToken(TEXT(""));
  71. // Throw away the leading delimiters
  72. while (m_nIndex < (int)m_strStr.Length())
  73. {
  74. if (strDelim.Find(m_strStr[m_nIndex]) < 0)
  75. break;
  76. ++m_nIndex;
  77. }
  78. // Copy the string until we reach a delimiter
  79. while (m_nIndex < (int)m_strStr.Length())
  80. {
  81. if (strDelim.Find(m_strStr[m_nIndex]) >= 0)
  82. break;
  83. strToken += m_strStr[m_nIndex];
  84. ++m_nIndex;
  85. }
  86. // Throw away the trailing delimiters
  87. while (m_nIndex < (int)m_strStr.Length())
  88. {
  89. if (strDelim.Find(m_strStr[m_nIndex]) < 0)
  90. break;
  91. ++m_nIndex;
  92. }
  93. return strToken;
  94. }
  95. template <class T>
  96. T CSimpleStringToken<T>::String(void) const
  97. {
  98. return m_strStr;
  99. }
  100. template <class T>
  101. int CSimpleStringToken<T>::Index(void) const
  102. {
  103. return m_nIndex;
  104. }
  105. #endif