#ifndef __03aef7a5_f6eb_4234_9ffc_05627e330871__ #define __03aef7a5_f6eb_4234_9ffc_05627e330871__ #include "simstr.h" template class CSimpleStringToken { private: T m_strStr; int m_nIndex; public: CSimpleStringToken(void); CSimpleStringToken( const T &str ); CSimpleStringToken( const CSimpleStringToken &other ); CSimpleStringToken &operator=( const CSimpleStringToken &other ); virtual ~CSimpleStringToken(void); void Reset(void); T Tokenize( const T &strDelim ); T String(void) const; int Index(void) const; }; template CSimpleStringToken::CSimpleStringToken(void) :m_nIndex(0) { } template CSimpleStringToken::CSimpleStringToken( const T &str ) : m_strStr(str), m_nIndex(0) { } template CSimpleStringToken::CSimpleStringToken( const CSimpleStringToken &other ) : m_strStr(other.String()), m_nIndex(other.Index()) { } template CSimpleStringToken &CSimpleStringToken::operator=( const CSimpleStringToken &other ) { m_strStr = other.String(); m_nIndex = other.Index(); return *this; } template CSimpleStringToken::~CSimpleStringToken(void) { } template void CSimpleStringToken::Reset(void) { m_nIndex = 0; } template T CSimpleStringToken::Tokenize( const T &strDelim ) { T strToken(TEXT("")); // Throw away the leading delimiters while (m_nIndex < (int)m_strStr.Length()) { if (strDelim.Find(m_strStr[m_nIndex]) < 0) break; ++m_nIndex; } // Copy the string until we reach a delimiter while (m_nIndex < (int)m_strStr.Length()) { if (strDelim.Find(m_strStr[m_nIndex]) >= 0) break; strToken += m_strStr[m_nIndex]; ++m_nIndex; } // Throw away the trailing delimiters while (m_nIndex < (int)m_strStr.Length()) { if (strDelim.Find(m_strStr[m_nIndex]) < 0) break; ++m_nIndex; } return strToken; } template T CSimpleStringToken::String(void) const { return m_strStr; } template int CSimpleStringToken::Index(void) const { return m_nIndex; } #endif