]>
git.saurik.com Git - wxWidgets.git/blob - src/common/tokenzr.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: String tokenizer
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "tokenzr.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/tokenzr.h"
25 wxStringTokenizer::wxStringTokenizer(const wxString
& to_tokenize
,
26 const wxString
& delims
,
29 m_string
= to_tokenize
;
31 m_retdelims
= ret_delims
;
34 wxStringTokenizer::~wxStringTokenizer()
38 off_t
wxStringTokenizer::FindDelims(const wxString
& str
, const wxString
& delims
) const
40 for ( size_t i
= 0; i
< str
.Length(); i
++ )
44 for ( size_t j
= 0; j
< delims
.Length() ; j
++ )
54 int wxStringTokenizer::CountTokens() const
56 wxString p_string
= m_string
;
60 if (p_string
.Length() == 0)
65 pos
= FindDelims(p_string
, m_delims
);
69 p_string
= p_string(0, pos
);
80 bool wxStringTokenizer::HasMoreTokens()
82 return !m_string
.IsEmpty();
85 // needed to fix leading whitespace / mult. delims bugs
86 void wxStringTokenizer::EatLeadingDelims()
90 // while leading delims trim 'em from the left
91 while ( ( pos
= FindDelims(m_string
, m_delims
)) == 0 )
93 m_string
= m_string
.Mid((size_t)1);
97 wxString
wxStringTokenizer::NextToken()
102 if ( m_string
.IsEmpty() )
108 pos
= FindDelims(m_string
, m_delims
);
112 m_string
= wxEmptyString
;
134 r_string
= m_string
.Left((size_t)pos
);
135 m_string
= m_string
.Mid((size_t)pos2
);