]>
git.saurik.com Git - wxWidgets.git/blob - src/common/tokenzr.cpp
19ae5e0f29a44ab49cfe32d98f3adb5deef8048b
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"
26 #include "wx/object.h"
27 #include "wx/string.h"
28 #include "wx/tokenzr.h"
30 wxStringTokenizer::wxStringTokenizer(const wxString
& to_tokenize
,
31 const wxString
& delims
,
35 m_string
= to_tokenize
;
37 m_retdelims
= ret_delims
;
40 wxStringTokenizer::~wxStringTokenizer()
44 off_t
wxStringTokenizer::FindDelims(const wxString
& str
, const wxString
& delims
)
47 register int s_len
= str
.Length(),
48 len
= delims
.Length();
50 for (i
=0;i
<s_len
;i
++) {
51 register char c
= str
[i
];
60 int wxStringTokenizer::CountTokens()
62 wxString p_string
= m_string
;
66 if (p_string
.Length() == 0)
70 pos
= FindDelims(p_string
, m_delims
);
73 p_string
= p_string(0, pos
);
80 bool wxStringTokenizer::HasMoreToken()
82 return (m_string
.Length() != 0);
85 // AVS - added to fix leading whitespace / mult. delims bugs
86 void wxStringTokenizer::EatLeadingDelims()
90 while ((pos
=FindDelims(m_string
, m_delims
))==0) { // while leading delims
91 m_string
= m_string
.Mid((size_t)1); // trim 'em from the left
95 wxString
wxStringTokenizer::NextToken()
97 register off_t pos
, pos2
;
100 if (m_string
.IsNull())
104 EatLeadingDelims(); // AVS - added to fix leading whitespace /
107 pos
= FindDelims(m_string
, m_delims
);
110 m_string
= wxEmptyString
;
124 r_string
= m_string
.Left((size_t)pos
);
125 m_string
= m_string
.Mid((size_t)pos2
);