WXDLLEXPORT added to wxStringTokenizer (and also several "const"s here and

there...)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2752 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-06-10 21:16:58 +00:00
parent b23198ab9e
commit 85833f5c6c
4 changed files with 126 additions and 116 deletions

View File

@@ -20,38 +20,38 @@
#include "wx/string.h" #include "wx/string.h"
#include "wx/filefn.h" #include "wx/filefn.h"
class wxStringTokenizer : public wxObject { class WXDLLEXPORT wxStringTokenizer : public wxObject
{
public: public:
wxStringTokenizer(const wxString& to_tokenize, wxStringTokenizer(const wxString& to_tokenize,
const wxString& delims = " \t\r\n", const wxString& delims = " \t\r\n",
bool ret_delim = FALSE); bool ret_delim = FALSE);
wxStringTokenizer() { m_string = ""; m_delims = ""; m_retdelims = FALSE;} wxStringTokenizer() { m_retdelims = FALSE;}
~wxStringTokenizer(); virtual ~wxStringTokenizer();
int CountTokens(); int CountTokens() count;
bool HasMoreToken(); bool HasMoreTokens();
inline bool HasMoreTokens() { return HasMoreToken(); };
wxString NextToken();
// A better name!
inline wxString GetNextToken() { return NextToken(); };
wxString GetString() { return m_string; }
void SetString(const wxString& to_tokenize, wxString NextToken();
const wxString& delims = " \t\r\n", wxString GetNextToken() { return NextToken(); };
bool ret_delim = FALSE)
{ wxString GetString() const { return m_string; }
m_string = to_tokenize;
m_delims = delims; void SetString(const wxString& to_tokenize,
m_retdelims = ret_delim; const wxString& delims = " \t\r\n",
} bool ret_delim = FALSE)
{
m_string = to_tokenize;
m_delims = delims;
m_retdelims = ret_delim;
}
protected: protected:
off_t FindDelims(const wxString& str, const wxString& delims); off_t FindDelims(const wxString& str, const wxString& delims);
void EatLeadingDelims(); // AVS - added to fix leading whitespace / void EatLeadingDelims();
// mult. delims bugs
protected: wxString m_string, m_delims;
wxString m_string, m_delims; bool m_retdelims;
bool m_retdelims;
}; };
#endif #endif // _WX_TOKENZRH

View File

@@ -10,31 +10,25 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "tokenzr.h" #pragma implementation "tokenzr.h"
#endif #endif
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
#ifndef WX_PRECOMP
#endif
#include "wx/object.h"
#include "wx/string.h"
#include "wx/tokenzr.h" #include "wx/tokenzr.h"
wxStringTokenizer::wxStringTokenizer(const wxString& to_tokenize, wxStringTokenizer::wxStringTokenizer(const wxString& to_tokenize,
const wxString& delims, const wxString& delims,
bool ret_delims) bool ret_delims)
: wxObject()
{ {
m_string = to_tokenize; m_string = to_tokenize;
m_delims = delims; m_delims = delims;
m_retdelims = ret_delims; m_retdelims = ret_delims;
} }
wxStringTokenizer::~wxStringTokenizer() wxStringTokenizer::~wxStringTokenizer()
@@ -43,86 +37,102 @@ wxStringTokenizer::~wxStringTokenizer()
off_t wxStringTokenizer::FindDelims(const wxString& str, const wxString& delims) off_t wxStringTokenizer::FindDelims(const wxString& str, const wxString& delims)
{ {
int i, j; for ( int i = 0; i < str.Length(); i++ )
register int s_len = str.Length(), {
len = delims.Length(); char c = str[i];
for (i=0;i<s_len;i++) { for ( int j = 0; j < delims.Length() ; j++ )
register char c = str[i]; {
if ( delims[j] == c )
return i;
}
}
for (j=0;j<len;j++) return -1;
if (delims[j] == c)
return i;
}
return -1;
} }
int wxStringTokenizer::CountTokens() int wxStringTokenizer::CountTokens() const
{ {
wxString p_string = m_string; wxString p_string = m_string;
bool found = TRUE; bool found = TRUE;
int pos, count = 1; int pos, count = 1;
if (p_string.Length() == 0) if (p_string.Length() == 0)
return 0; return 0;
while (found) { while (found)
pos = FindDelims(p_string, m_delims); {
if (pos != -1) { pos = FindDelims(p_string, m_delims);
count++; if (pos != -1)
p_string = p_string(0, pos); {
} else count++;
found = FALSE; p_string = p_string(0, pos);
} }
return count; else
{
found = FALSE;
}
}
return count;
} }
bool wxStringTokenizer::HasMoreToken() bool wxStringTokenizer::HasMoreToken()
{ {
return (m_string.Length() != 0); return !m_string.IsEmpty();
} }
// AVS - added to fix leading whitespace / mult. delims bugs // needed to fix leading whitespace / mult. delims bugs
void wxStringTokenizer::EatLeadingDelims() void wxStringTokenizer::EatLeadingDelims()
{ {
int pos; int pos;
while ((pos=FindDelims(m_string, m_delims))==0) { // while leading delims // while leading delims trim 'em from the left
m_string = m_string.Mid((size_t)1); // trim 'em from the left while ( ( pos = FindDelims(m_string, m_delims)) == 0 )
} {
m_string = m_string.Mid((size_t)1);
}
} }
wxString wxStringTokenizer::NextToken() wxString wxStringTokenizer::NextToken()
{ {
register off_t pos, pos2; off_t pos, pos2;
wxString r_string; wxString r_string;
if (m_string.IsNull()) if ( m_string.IsEmpty() )
return m_string; return m_string;
if (!m_retdelims) if ( !m_retdelims )
EatLeadingDelims(); // AVS - added to fix leading whitespace / EatLeadingDelims();
// mult. delims bugs
pos = FindDelims(m_string, m_delims);
if (pos == -1)
{
r_string = m_string;
m_string = wxEmptyString;
return r_string;
}
if (m_retdelims)
{
if (!pos)
{
pos++;
pos2 = 1;
}
else
{
pos2 = pos;
}
}
else
{
pos2 = pos + 1;
}
r_string = m_string.Left((size_t)pos);
m_string = m_string.Mid((size_t)pos2);
pos = FindDelims(m_string, m_delims);
if (pos == -1) {
r_string = m_string;
m_string = wxEmptyString;
return r_string; return r_string;
}
if (m_retdelims) {
if (!pos) {
pos++;
pos2 = 1;
} else
pos2 = pos;
} else
pos2 = pos + 1;
r_string = m_string.Left((size_t)pos);
m_string = m_string.Mid((size_t)pos2);
return r_string;
} }

View File

@@ -34,21 +34,21 @@ public:
}; };
IMPLEMENT_ABSTRACT_CLASS(wxHTMLHelpControllerBase, wxHelpControllerBase) IMPLEMENT_ABSTRACT_CLASS(wxHTMLHelpControllerBase, wxHelpControllerBase)
/** /**
This class implements help via an external browser. This class implements help via an external browser.
It requires the name of a directory containing the documentation It requires the name of a directory containing the documentation
and a file mapping numerical Section numbers to relative URLS. and a file mapping numerical Section numbers to relative URLS.
*/ */
wxHTMLHelpControllerBase::wxHTMLHelpControllerBase(void) wxHTMLHelpControllerBase::wxHTMLHelpControllerBase()
{ {
m_MapList = (wxList*) NULL; m_MapList = (wxList*) NULL;
m_NumOfEntries = 0; m_NumOfEntries = 0;
} }
void void
wxHTMLHelpControllerBase::DeleteList(void) wxHTMLHelpControllerBase::DeleteList()
{ {
if(m_MapList) if(m_MapList)
{ {
@@ -64,7 +64,7 @@ wxHTMLHelpControllerBase::DeleteList(void)
} }
} }
wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase(void) wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase()
{ {
DeleteList(); DeleteList();
} }
@@ -88,7 +88,7 @@ wxHTMLHelpControllerBase::LoadFile(const wxString& ifile)
wxString mapFile, file, url, doc; wxString mapFile, file, url, doc;
int id,i,len; int id,i,len;
char buffer[WXEXTHELP_BUFLEN]; char buffer[WXEXTHELP_BUFLEN];
wxBusyCursor b; // display a busy cursor wxBusyCursor b; // display a busy cursor
if(! ifile.IsEmpty()) if(! ifile.IsEmpty())
@@ -125,10 +125,10 @@ wxHTMLHelpControllerBase::LoadFile(const wxString& ifile)
file = newfile; file = newfile;
} }
} }
if(! wxDirExists(file)) if(! wxDirExists(file))
return FALSE; return FALSE;
mapFile << file << WXEXTHELP_SEPARATOR << WXEXTHELP_MAPFILE; mapFile << file << WXEXTHELP_SEPARATOR << WXEXTHELP_MAPFILE;
} }
else // try to reload old file else // try to reload old file
@@ -140,7 +140,7 @@ wxHTMLHelpControllerBase::LoadFile(const wxString& ifile)
DeleteList(); DeleteList();
m_MapList = new wxList; m_MapList = new wxList;
m_NumOfEntries = 0; m_NumOfEntries = 0;
FILE *input = fopen(mapFile.fn_str(),"rt"); FILE *input = fopen(mapFile.fn_str(),"rt");
if(! input) if(! input)
return FALSE; return FALSE;
@@ -169,21 +169,21 @@ wxHTMLHelpControllerBase::LoadFile(const wxString& ifile)
} }
}while(! feof(input)); }while(! feof(input));
fclose(input); fclose(input);
m_MapFile = file; // now it's valid m_MapFile = file; // now it's valid
return TRUE; return TRUE;
} }
bool bool
wxHTMLHelpControllerBase::DisplayContents(void) wxHTMLHelpControllerBase::DisplayContents()
{ {
if(! m_NumOfEntries) if(! m_NumOfEntries)
return FALSE; return FALSE;
wxBusyCursor b; // display a busy cursor wxBusyCursor b; // display a busy cursor
return KeywordSearch(""); return KeywordSearch("");
} }
bool bool
wxHTMLHelpControllerBase::DisplaySection(int sectionNo) wxHTMLHelpControllerBase::DisplaySection(int sectionNo)
{ {
@@ -219,19 +219,19 @@ wxHTMLHelpControllerBase::KeywordSearch(const wxString& k)
wxString *choices = new wxString[m_NumOfEntries]; wxString *choices = new wxString[m_NumOfEntries];
wxString *urls = new wxString[m_NumOfEntries]; wxString *urls = new wxString[m_NumOfEntries];
wxString compA, compB; wxString compA, compB;
int idx = 0, j; int idx = 0, j;
bool rc; bool rc;
bool showAll = k.IsEmpty(); bool showAll = k.IsEmpty();
wxNode *node = m_MapList->First(); wxNode *node = m_MapList->First();
wxExtHelpMapEntry *entry; wxExtHelpMapEntry *entry;
compA = k; compA.LowerCase(); // we compare case insensitive compA = k; compA.LowerCase(); // we compare case insensitive
while(node) while(node)
{ {
entry = (wxExtHelpMapEntry *)node->Data(); entry = (wxExtHelpMapEntry *)node->Data();
compB = entry->doc; compB.LowerCase(); compB = entry->doc; compB.LowerCase();
if((showAll || compB.Contains(k)) && ! compB.IsEmpty()) if((showAll || compB.Contains(k)) && ! compB.IsEmpty())
{ {
urls[idx] = entry->url; urls[idx] = entry->url;
// doesn't work: // doesn't work:
@@ -266,19 +266,19 @@ wxHTMLHelpControllerBase::KeywordSearch(const wxString& k)
} }
delete[] urls; delete[] urls;
delete[] choices; delete[] choices;
return rc; return rc;
} }
bool bool
wxHTMLHelpControllerBase::Quit(void) wxHTMLHelpControllerBase::Quit()
{ {
return TRUE; return TRUE;
} }
void void
wxHTMLHelpControllerBase::OnQuit(void) wxHTMLHelpControllerBase::OnQuit()
{ {
} }

View File

@@ -161,7 +161,7 @@ wxClientDC::~wxClientDC()
// So we store a list of windows for which we already have the DC and not // So we store a list of windows for which we already have the DC and not
// just one single hDC. This seems to work, but I'm really not sure about // just one single hDC. This seems to work, but I'm really not sure about
// the usefullness of the whole idea - IMHO it's much better to not call // the usefullness of the whole idea - IMHO it's much better to not call
// base class OnPaint() at all, or, if we realyl want to allow it, add a // base class OnPaint() at all, or, if we really want to allow it, add a
// "wxPaintDC *" parameter to wxPaintEvent which should be used if it's // "wxPaintDC *" parameter to wxPaintEvent which should be used if it's
// !NULL instead of creating a new DC. // !NULL instead of creating a new DC.