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.

102 lines
2.1 KiB

  1. #ifndef __03aef7a5_f6eb_4234_9ffc_05627e330871__
  2. #define __03aef7a5_f6eb_4234_9ffc_05627e330871__
  3. #include "simstr.h"
  4. template <class T>
  5. class CSimpleStringToken
  6. {
  7. private:
  8. T m_strStr;
  9. int m_nIndex;
  10. public:
  11. CSimpleStringToken(void);
  12. CSimpleStringToken( const T &str );
  13. CSimpleStringToken( const CSimpleStringToken &other );
  14. CSimpleStringToken &operator=( const CSimpleStringToken &other );
  15. virtual ~CSimpleStringToken(void);
  16. void Reset(void);
  17. T Tokenize( const T &strDelim );
  18. T String(void) const;
  19. int Index(void) const;
  20. };
  21. template <class T>
  22. CSimpleStringToken<T>::CSimpleStringToken(void)
  23. :m_nIndex(0)
  24. {
  25. }
  26. template <class T>
  27. CSimpleStringToken<T>::CSimpleStringToken( const T &str )
  28. : m_strStr(str), m_nIndex(0)
  29. {
  30. }
  31. template <class T>
  32. CSimpleStringToken<T>::CSimpleStringToken( const CSimpleStringToken &other )
  33. : m_strStr(other.String()), m_nIndex(other.Index())
  34. {
  35. }
  36. template <class T>
  37. CSimpleStringToken<T> &CSimpleStringToken<T>::operator=( const CSimpleStringToken &other )
  38. {
  39. m_strStr = other.String();
  40. m_nIndex = other.Index();
  41. return *this;
  42. }
  43. template <class T>
  44. CSimpleStringToken<T>::~CSimpleStringToken(void)
  45. {
  46. }
  47. template <class T>
  48. void CSimpleStringToken<T>::Reset(void)
  49. {
  50. m_nIndex = 0;
  51. }
  52. template <class T>
  53. T CSimpleStringToken<T>::Tokenize( const T &strDelim )
  54. {
  55. T strToken(TEXT(""));
  56. // Throw away the leading delimiters
  57. while (m_nIndex < (int)m_strStr.Length())
  58. {
  59. if (strDelim.Find(m_strStr[m_nIndex]) < 0)
  60. break;
  61. ++m_nIndex;
  62. }
  63. // Copy the string until we reach a delimiter
  64. while (m_nIndex < (int)m_strStr.Length())
  65. {
  66. if (strDelim.Find(m_strStr[m_nIndex]) >= 0)
  67. break;
  68. strToken += m_strStr[m_nIndex];
  69. ++m_nIndex;
  70. }
  71. // Throw away the trailing 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. return strToken;
  79. }
  80. template <class T>
  81. T CSimpleStringToken<T>::String(void) const
  82. {
  83. return m_strStr;
  84. }
  85. template <class T>
  86. int CSimpleStringToken<T>::Index(void) const
  87. {
  88. return m_nIndex;
  89. }
  90. #endif