Patch level : 12.0 no-patch
Files correlati : Commento : Aggiunta compare per le token string
This commit is contained in:
parent
d4cfef4d30
commit
154dda5842
src/include
@ -2038,6 +2038,75 @@ TToken_string& TToken_string::pack()
|
||||
return *this;
|
||||
}
|
||||
|
||||
int TToken_string::compare(const char* s, int max, bool ignorecase) const
|
||||
{
|
||||
if (items() > 1)
|
||||
{
|
||||
TToken_string stok(s, separator());
|
||||
int res = 0;
|
||||
int i = 0;
|
||||
|
||||
FOR_EACH_STR_TOKEN(*this, tok)
|
||||
{
|
||||
if (!tok.blank())
|
||||
{
|
||||
TFieldtypes type = _alfafld;
|
||||
|
||||
if (real::is_natural(tok))
|
||||
type = _longfld;
|
||||
else
|
||||
if (real::is_real(tok))
|
||||
type = _realfld;
|
||||
else
|
||||
if (TDate::isdate(tok))
|
||||
type = _datefld;
|
||||
switch (type)
|
||||
{
|
||||
case _longfld: // @emem Campo di tipo intero lungo
|
||||
// @emem Campo di tipo intero
|
||||
// @emem Campo di tipo intero senza segno
|
||||
// @emem Campo di tipo intero zero filled
|
||||
// @emem Campo di tipo intero lungo zero filled
|
||||
{
|
||||
long l = atol(tok);
|
||||
|
||||
res = l - stok.get_long(i++);
|
||||
}
|
||||
break;
|
||||
case _realfld: // @emem Campo di tipo reale (vedi <c real>)
|
||||
{
|
||||
real r(tok);
|
||||
|
||||
r -= stok.get_real(i++);
|
||||
res = r > ZERO ? 1 : (r < ZERO ? -1 : 0);
|
||||
}
|
||||
break;
|
||||
case _datefld: // @emem Campo di tipo data (vedi <c TDate>)
|
||||
{
|
||||
TDate d(tok);
|
||||
|
||||
res = d - stok.get_date(i++);
|
||||
}
|
||||
break;
|
||||
case _alfafld: // @emem Campo di tipo alfanumerico
|
||||
// @emem Campo di tipo carattere
|
||||
// @emem Campo di tipo booleano
|
||||
// @emem Campo di tipo memo
|
||||
default:
|
||||
res = tok.compare(stok.get(i++), -1, ignorecase);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
res = TString::compare(s, max, ignorecase);
|
||||
if ((max >= 0 && i >= max) || res != 0)
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return TString::compare(s, max, ignorecase);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TAuto_token_string
|
||||
///////////////////////////////////////////////////////////
|
||||
|
@ -294,7 +294,7 @@ public:
|
||||
// @cmember Confronta usando le regular expression
|
||||
bool match(const char* pat, bool ignorecase = false) const;
|
||||
// @cmember Compara due stringhe (o i primi max caratteri)
|
||||
int compare(const char* s, int max = -1, bool ignorecase = false) const;
|
||||
virtual int compare(const char* s, int max = -1, bool ignorecase = false) const;
|
||||
// @cmember Controlla se la stringa comincia per s
|
||||
bool starts_with(const char* s, bool ignorecase = false) const;
|
||||
// @cmember Controlla se la stringa finisce per s
|
||||
@ -738,6 +738,8 @@ public:
|
||||
bool empty_items() const;
|
||||
// @cmember Compatta tutti i campi " " in ""
|
||||
TToken_string& pack();
|
||||
// @cmenmber compara 2 Token_string elemento per elemento come stringhe
|
||||
virtual int compare(const char* s, int max = -1, bool ignorecase = false) const;
|
||||
};
|
||||
|
||||
#define FOR_EACH_TOKEN(__tok, __str) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user