add wstring split()

This commit is contained in:
Glenn Maynard
2003-01-05 03:59:07 +00:00
parent 965d7481ee
commit ee10c50216
2 changed files with 20 additions and 7 deletions
+19 -7
View File
@@ -152,22 +152,34 @@ CString join( const CString &Deliminator, const CStringArray& Source)
} }
void split( const CString &Source, const CString &Deliminator, CStringArray& AddIt, const bool bIgnoreEmpty ) template <class S>
void do_split( const S &Source, const S &Deliminator, vector<S> &AddIt, const bool bIgnoreEmpty )
{ {
int startpos = 0; unsigned startpos = 0;
do { do {
int pos = Source.Find(Deliminator, startpos); unsigned pos = Source.find_first_of(Deliminator, startpos);
if ( pos == -1 ) pos=Source.GetLength(); if ( pos == Source.npos ) pos=Source.size();
CString AddCString = Source.substr(startpos, pos-startpos); S AddCString = Source.substr(startpos, pos-startpos);
if( AddCString.empty() && bIgnoreEmpty ) if( AddCString.empty() && bIgnoreEmpty )
; // do nothing ; // do nothing
else else
AddIt.push_back(AddCString); AddIt.push_back(AddCString);
startpos=pos+Deliminator.GetLength(); startpos=pos+Deliminator.size();
} while ( startpos <= Source.GetLength() ); } while ( startpos <= Source.size() );
}
void split( const CString &Source, const CString &Deliminator, CStringArray &AddIt, const bool bIgnoreEmpty )
{
do_split(Source, Deliminator, AddIt, bIgnoreEmpty );
}
void split( const wstring &Source, const wstring &Deliminator, vector<wstring> &AddIt, const bool bIgnoreEmpty )
{
do_split(Source, Deliminator, AddIt, bIgnoreEmpty );
} }
+1
View File
@@ -155,6 +155,7 @@ void split(
CStringArray& AddIt, CStringArray& AddIt,
const bool bIgnoreEmpty = true const bool bIgnoreEmpty = true
); );
void split( const wstring &Source, const wstring &Deliminator, vector<wstring> &AddIt, const bool bIgnoreEmpty = true );
// Joins a CStringArray to create a CString according the Deliminator. // Joins a CStringArray to create a CString according the Deliminator.
CString join( CString join(