Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
212 dhylands 1
/****************************************************************************
2
*
3
*     Copyright (c) 2003 Dave Hylands
4
*           All Rights Reserved
5
*
6
*   Permission is granted to any individual or institution to use, copy, or
7
*   redistribute this software so long as it is not sold for profit, and that
8
*   this copyright notice is retained.
9
*
10
****************************************************************************/
11
/**
12
*
13
*   @file   StrToken.h
14
*
15
*   @brief  String Tokenizer.
16
*
17
****************************************************************************/
18
 
19
#if !defined( STRTOKEN_H )
20
#define STRTOKEN_H           ///< Include Guard
21
 
22
// ---- Include Files -------------------------------------------------------
23
 
24
/**
25
 * @addtogroup Str
26
 * @{
27
 */
28
 
29
//---------------------------------------------------------------------------
30
/**
31
*   The StrTokenizer class basically wraps up a reentrant version of strtok.
32
*/
33
 
34
class StrTokenizer
35
{
36
public:
37
 
38
    //------------------------------------------------------------------------
39
    // Default constructor
40
 
41
    StrTokenizer();
42
 
43
    //------------------------------------------------------------------------
44
    // Constructor which specifies string to be tokenized, along with location
45
    // to store tokens as they're parsed.
46
 
47
    StrTokenizer( const char *str, char *outToken, size_t maxLen );
48
 
49
    //------------------------------------------------------------------------
50
    // Destructor
51
 
52
    ~StrTokenizer();
53
 
54
    //------------------------------------------------------------------------
55
 
56
    void Init( const char *str, char *outToken, size_t maxLen );
57
 
58
    //------------------------------------------------------------------------
59
 
60
    char *NextToken( const char *delim );
61
 
62
    //------------------------------------------------------------------------
63
 
64
    const char *Remainder() const;
65
 
66
private:
67
 
68
    //------------------------------------------------------------------------
69
    // The copy constructor and assignment operator are not need for this
70
    // class so we declare them private and don't provide an implementation.
71
 
72
    StrTokenizer( const StrTokenizer & copy );
73
    StrTokenizer &operator =( const StrTokenizer &rhs );
74
 
75
    //------------------------------------------------------------------------
76
 
77
    const char *m_str;      ///< Where we are in the string
78
    char       *m_outToken; ///< Place to store the parsed token.
79
    size_t      m_maxLen;   ///< Max size of m_outToken.
80
};
81
 
82
// ---- Inline Functions ----------------------------------------------------
83
 
84
/***************************************************************************/
85
/**
86
*   Returns the remainder of the untokenized string.
87
*/
88
 
89
inline const char *StrTokenizer::Remainder() const
90
{
91
    return m_str;
92
}
93
 
94
/** @} */
95
 
96
#endif // STRTOKEN_H
97