Patch level : 12.0 no-patch

Files correlati     :
Commento            :

Aggiunta merge e merge_token per le string_array

Aggiunta compare_token per le token string
This commit is contained in:
Alessandro Bonazzi 2020-10-15 21:27:49 +02:00
parent d436986337
commit 864436700f
4 changed files with 39 additions and 18 deletions

View File

@ -159,8 +159,9 @@ bool TArray::destroy(
if (index < 0)
{
for (int i = last(); i >= 0; i--) if (_data[i] != nullptr)
safe_delete(_data[i]);
for (int i = last(); i >= 0; i--)
if (_data[i] != NULL)
safe_delete(_data[i]);
_items = _next = 0;
}
else
@ -649,23 +650,20 @@ int TString_array::find(
}
return found;
}
HIDDEN int ascending_string(const TObject** o1, const TObject** o2)
{
if (((const TToken_string*)*o1)->items() > 1)
{
const TString* s1 = (const TString*)*o1;
const TString* s2 = (const TString*)*o2;
return strcmp(*s1, *s2);
}
HIDDEN int ascending_token(const TObject** o1, const TObject** o2)
{
const TToken_string* s1 = (const TToken_string*)*o1;
const TToken_string* s2 = (const TToken_string*)*o2;
return s1->compare(*s2);
}
else
{
const TString* s1 = (const TString*)*o1;
const TString* s2 = (const TString*)*o2;
return strcmp(*s1, *s2);
}
}
HIDDEN int descending_string(const TObject** o1, const TObject** o2)
@ -673,11 +671,21 @@ HIDDEN int descending_string(const TObject** o1, const TObject** o2)
return -ascending_string(o1, o2);
}
HIDDEN int descending_token(const TObject** o1, const TObject** o2)
{
return -ascending_token(o1, o2);
}
void TString_array::sort(bool ascending)
{
TArray::sort(ascending ? ascending_string : descending_string);
}
void TString_array::sort_token(bool ascending)
{
TArray::sort(ascending ? ascending_token : descending_token);
}
const TString_array & TString_array::merge(const TString_array & a)
{
FOR_EACH_ARRAY_ROW(a, i, row)
@ -687,6 +695,15 @@ const TString_array & TString_array::merge(const TString_array & a)
return *this;
}
const TString_array & TString_array::merge_token(const TString_array & a)
{
FOR_EACH_ARRAY_ROW(a, i, row)
if (find(*row) == -1)
add(*row);
sort_token(true);
return *this;
}
const TString_array & TString_array::tok2arr(TToken_string & tok, bool clear)
{
if (clear)

View File

@ -202,7 +202,7 @@ public:
};
inline TObject* TArray::objptr(int index) const
{ return (index < _size && index >= 0) ? _data[index] : NULL; }
{ return (index < _size && index >= 0) ? _data[index] : nullptr; }
#ifndef DBG
inline TObject& TArray::operator[] (int index) const
@ -264,8 +264,12 @@ public:
int find(const char* s, int from = 0) const;
// @cmember Ordina alfabeticamente l'array
void sort(bool ascending = true);
// @cmember Ordina alfabeticamente l'array come token_string
void sort_token(bool ascending = true);
// @cmember fonde con l'array a
const TString_array & merge(const TString_array & a);
// @cmember fonde con l'array a
const TString_array & merge_token(const TString_array & a);
// @cmember Ritorna l'ultima riga (deve esistere!)
TToken_string& last_row()
{ return (TToken_string&)operator[](last()); }

View File

@ -2038,7 +2038,7 @@ TToken_string& TToken_string::pack()
return *this;
}
int TToken_string::compare(const char* s, int max, bool ignorecase) const
int TToken_string::compare_token(const char* s, int max, bool ignorecase) const
{
if (items() > 1)
{
@ -2200,7 +2200,7 @@ TToken_string& get_tmp_string(int len)
TToken_string* str = (TToken_string*)ararar.objptr(next);
if (str == NULL)
if (str == nullptr)
{
str = new TToken_string(max(len,50));
ararar.add(str, next);

View File

@ -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)
virtual int compare(const char* s, int max = -1, bool ignorecase = false) const;
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
@ -739,7 +739,7 @@ public:
// @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;
int compare_token(const char* s, int max = -1, bool ignorecase = false) const;
};
#define FOR_EACH_TOKEN(__tok, __str) \