+
+#if wxUSE_UNICODE // FIXME-UTF8: only wc_str()
+    m_delims = delims.wc_str();
+#else
+    m_delims = delims.mb_str();
+#endif
+    m_delimsLen = delims.length();
+
+    m_mode = mode;
+
+    Reinit(str);
+}
+
+void wxStringTokenizer::Reinit(const wxString& str)
+{
+    wxASSERT_MSG( IsOk(), wxT("you should call SetString() first") );
+
+    m_string = str;
+    m_stringEnd = m_string.end();
+    m_pos = m_string.begin();
+    m_lastDelim = wxT('\0');
+    m_hasMoreTokens = MoreTokens_Unknown;
+}
+
+// ----------------------------------------------------------------------------
+// access to the tokens
+// ----------------------------------------------------------------------------
+
+// do we have more of them?
+bool wxStringTokenizer::HasMoreTokens() const
+{
+    // GetNextToken() calls HasMoreTokens() and so HasMoreTokens() is called
+    // twice in every interation in the following common usage patten:
+    //     while ( HasMoreTokens() )
+    //        GetNextToken();
+    // We optimize this case by caching HasMoreTokens() return value here:
+    if ( m_hasMoreTokens == MoreTokens_Unknown )
+    {
+        bool r = DoHasMoreTokens();
+        wxConstCast(this, wxStringTokenizer)->m_hasMoreTokens =
+            r ? MoreTokens_Yes : MoreTokens_No;
+        return r;
+    }
+    else
+        return m_hasMoreTokens == MoreTokens_Yes;
+}
+
+bool wxStringTokenizer::DoHasMoreTokens() const
+{
+    wxCHECK_MSG( IsOk(), false, wxT("you should call SetString() first") );
+
+    if ( find_first_not_of(m_delims, m_delimsLen, m_pos, m_stringEnd)
+         != m_stringEnd )
+    {
+        // there are non delimiter characters left, so we do have more tokens
+        return true;
+    }
+
+    switch ( m_mode )
+    {
+        case wxTOKEN_RET_EMPTY:
+        case wxTOKEN_RET_DELIMS:
+            // special hack for wxTOKEN_RET_EMPTY: we should return the initial
+            // empty token even if there are only delimiters after it
+            return !m_string.empty() && m_pos == m_string.begin();
+
+        case wxTOKEN_RET_EMPTY_ALL:
+            // special hack for wxTOKEN_RET_EMPTY_ALL: we can know if we had
+            // already returned the trailing empty token after the last
+            // delimiter by examining m_lastDelim: it is set to NUL if we run
+            // up to the end of the string in GetNextToken(), but if it is not
+            // NUL yet we still have this last token to return even if m_pos is
+            // already at m_string.length()
+            return m_pos < m_stringEnd || m_lastDelim != wxT('\0');
+
+        case wxTOKEN_INVALID:
+        case wxTOKEN_DEFAULT:
+            wxFAIL_MSG( wxT("unexpected tokenizer mode") );
+            // fall through
+
+        case wxTOKEN_STRTOK:
+            // never return empty delimiters
+            break;
+    }
+
+    return false;