X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dab58492b2f5f7924755ba6b1064538a004632e0..0d1c8f39baaaeb7a7f757091209eab471ef5dbc4:/src/common/tokenzr.cpp diff --git a/src/common/tokenzr.cpp b/src/common/tokenzr.cpp index 19ae5e0f29..5bdae9d7fb 100644 --- a/src/common/tokenzr.cpp +++ b/src/common/tokenzr.cpp @@ -1,128 +1,229 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: tokenzr.cpp +// Name: src/common/tokenzr.cpp // Purpose: String tokenizer // Author: Guilhem Lavaux -// Modified by: +// Modified by: Vadim Zeitlin (almost full rewrite) // Created: 04/22/98 // RCS-ID: $Id$ // Copyright: (c) Guilhem Lavaux // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "tokenzr.h" -#endif +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif +#include "wx/tokenzr.h" + #ifndef WX_PRECOMP + #include "wx/arrstr.h" #endif -#include "wx/object.h" -#include "wx/string.h" -#include "wx/tokenzr.h" +// Required for wxIs... functions +#include + +// ============================================================================ +// implementation +// ============================================================================ -wxStringTokenizer::wxStringTokenizer(const wxString& to_tokenize, +// ---------------------------------------------------------------------------- +// wxStringTokenizer construction +// ---------------------------------------------------------------------------- + +wxStringTokenizer::wxStringTokenizer(const wxString& str, const wxString& delims, - bool ret_delims) - : wxObject() + wxStringTokenizerMode mode) { - m_string = to_tokenize; - m_delims = delims; - m_retdelims = ret_delims; + SetString(str, delims, mode); } -wxStringTokenizer::~wxStringTokenizer() +void wxStringTokenizer::SetString(const wxString& str, + const wxString& delims, + wxStringTokenizerMode mode) { + if ( mode == wxTOKEN_DEFAULT ) + { + // by default, we behave like strtok() if the delimiters are only + // whitespace characters and as wxTOKEN_RET_EMPTY otherwise (for + // whitespace delimiters, strtok() behaviour is better because we want + // to count consecutive spaces as one delimiter) + const wxChar *p; + for ( p = delims.c_str(); *p; p++ ) + { + if ( !wxIsspace(*p) ) + break; + } + + if ( *p ) + { + // not whitespace char in delims + mode = wxTOKEN_RET_EMPTY; + } + else + { + // only whitespaces + mode = wxTOKEN_STRTOK; + } + } + + m_delims = delims; + m_mode = mode; + + Reinit(str); } -off_t wxStringTokenizer::FindDelims(const wxString& str, const wxString& delims) +void wxStringTokenizer::Reinit(const wxString& str) { - int i, j; - register int s_len = str.Length(), - len = delims.Length(); - - for (i=0;i