EgtGeneral 1.5a6 : migliorata Tokenize per Atom nestati su più livelli.
This commit is contained in:
+40
-24
@@ -1,13 +1,14 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2013-2013
|
||||
// EgalTech 2013-2014
|
||||
//----------------------------------------------------------------------------
|
||||
// File : StringUtils.cpp Data : 02.12.13 Versione : 1.4a1
|
||||
// File : StringUtils.cpp Data : 19.01.14 Versione : 1.5a6
|
||||
// Contenuto : Implementazione delle funzioni di utilità per le stringhe.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 20.01.13 DS Creazione modulo.
|
||||
// 02.12.13 DS Agg. FromString per Vector3d, Point3d e Point3d+W.
|
||||
// 19.01.14 DS Tokenize con Atom ora funziona su più livelli.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
@@ -275,35 +276,50 @@ bool
|
||||
Tokenize( const string& sString, const string& sSeparators,
|
||||
const string& sAtomStarts, const string& sAtomEnds, STRVECTOR& vsTokens)
|
||||
{
|
||||
string::size_type iPosStart ;
|
||||
string::size_type iPosEnd ;
|
||||
string::size_type iAtomStart ;
|
||||
string::size_type iAtomEnd ;
|
||||
|
||||
|
||||
// i separatori devono essere diversi da inizio e fine di atomi
|
||||
if ( sAtomStarts.find_first_of( sSeparators) != string::npos ||
|
||||
sAtomEnds.find_first_of( sSeparators) != string::npos)
|
||||
return false ;
|
||||
|
||||
// pulisco il risultato
|
||||
vsTokens.clear() ;
|
||||
// se la stringa è vuota non c'è niente da cercare
|
||||
if ( sString.empty())
|
||||
return true ;
|
||||
// parto dall'inizio
|
||||
iPosStart = ( sString.empty() ? string::npos : 0) ;
|
||||
// mentre esiste un nuovo inizio di token
|
||||
while ( iPosStart != string::npos) {
|
||||
// eventuale inizio e fine di parte atomica
|
||||
iAtomStart = sString.find_first_of( sAtomStarts, iPosStart) ;
|
||||
iAtomEnd = sString.find_first_of( sAtomEnds, iAtomStart) ;
|
||||
// cerco il primo separatore
|
||||
iPosEnd = sString.find_first_of( sSeparators, iPosStart) ;
|
||||
// se separatore è nella parte atomica, lo ricerco dopo la sua fine
|
||||
if ( iAtomStart != string::npos && iPosEnd != string::npos &&
|
||||
iPosEnd > iAtomStart && iPosEnd < iAtomEnd)
|
||||
iPosEnd = sString.find_first_of( sSeparators, iAtomEnd) ;
|
||||
// aggiungo il token al vettore
|
||||
vsTokens.push_back( sString.substr( iPosStart, iPosEnd - iPosStart)) ;
|
||||
// cerco l'inizio di un nuovo token
|
||||
iPosStart = sString.find_first_not_of( sSeparators, iPosEnd) ;
|
||||
int nOpenAtom = 0 ;
|
||||
string::size_type iPosStart = 0 ;
|
||||
string::size_type iPosEnd = iPosStart ;
|
||||
// mentre esiste un nuovo carattere
|
||||
while ( iPosEnd < sString.size()) {
|
||||
// trovo separatore non all'interno di un atomo
|
||||
if ( sSeparators.find( sString[iPosEnd]) != string::npos && nOpenAtom <= 0) {
|
||||
// aggiungo il token al vettore
|
||||
vsTokens.push_back( sString.substr( iPosStart, iPosEnd - iPosStart)) ;
|
||||
// passo al carattere successivo
|
||||
++ iPosEnd ;
|
||||
// imposto nuovo inizio di token
|
||||
iPosStart = ( iPosEnd < sString.size() ? iPosEnd : string::npos) ;
|
||||
}
|
||||
// trovo inizio di atomo
|
||||
else if ( sAtomStarts.find( sString[iPosEnd]) != string::npos) {
|
||||
++ nOpenAtom ;
|
||||
// passo al carattere successivo
|
||||
++ iPosEnd ;
|
||||
}
|
||||
// trovo fine di atomo
|
||||
else if ( sAtomEnds.find( sString[iPosEnd]) != string::npos) {
|
||||
-- nOpenAtom ;
|
||||
// passo al carattere successivo
|
||||
++ iPosEnd ;
|
||||
}
|
||||
// carattere normale, vado oltre
|
||||
else
|
||||
++ iPosEnd ;
|
||||
}
|
||||
// se è rimasto un ultimo token
|
||||
if ( iPosStart != string::npos)
|
||||
vsTokens.push_back( sString.substr( iPosStart)) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user