Patch level : 12.0 no-patch

Files correlati     : include
Commento            :
- Aggiunti nuovi files a lffiles

Implementate funzioni in TString
- replace(const char*, const char*): sostituisce una stringa con quella passata (prima c'era solo la versione con char)
- contains(char, int): controlla se la stringa contiene il carattere passato
- contains(const char*, int): controlla se la stringa contiene la stringa passata

Implementata funzione in TToken_string:
- const char* remove(int): rimuove un token dalla stringa e lo ritorna

- Aggiunta funzione is_multi_table(int) in utility.h che ritorna se il file è un multitracciato
This commit is contained in:
Mattia Tollari 2019-06-11 11:07:47 +02:00
parent 579caa00ef
commit 2aab5ea277
4 changed files with 53 additions and 8 deletions

View File

@ -193,6 +193,10 @@
#define LF_TRASFATT 173
#define LF_IVALIQ 174
#define LF_CFPRI 175
#define LF_FPCUST 176
#define LF_FPCCAUS 177
#define LF_FPCART 178
#define LF_FPCADG 179
#define LF_EXTERNAL 1000 // Files with id >= are considered to be externals

View File

@ -411,6 +411,21 @@ int TString::replace(char find_char, char replace_char)
return n;
}
int TString::replace(const char* find_string, const char* replace_string)
{
int n = 0;
const int old_str_lenght = strlen(find_string);
const int new_str_lenght = strlen(replace_string);
for(int pos = find(find_string); pos >= 0; pos = find(find_string, pos + new_str_lenght))
{
static TString app; app.cut(0);
app << this->left(pos) << replace_string << this->mid(pos + old_str_lenght);
*this = app;
n++;
}
return n;
}
// Certified 99%
// @doc EXTERNAL
@ -1013,14 +1028,14 @@ TString& TString::insert(
strcpy_s(&_str[pos+l], _size-(pos+l)+1, spark); // Aggiungi spark
}
return *this;
}
TString & TString::add_front(const char * s)
{
const int l = strlen(s);
lpad(len() + l);
overwrite(s);
return *this;
}
TString & TString::add_front(const char * s)
{
const int l = strlen(s);
lpad(len() + l);
overwrite(s);
return *this;
}
// Certified 90%
@ -1941,6 +1956,20 @@ void TToken_string::destroy(int n)
restart();
}
const char* TToken_string::remove(const int pos)
{
// Prelevo l'informazione della stringa
TString& ret = get_tmp_string();
ret << get(pos);
// La distruggo nel TToken_string
destroy(pos);
// Ritorno
return ret;
}
TToken_string& TToken_string::pack()
{
const char sep = separator();

View File

@ -113,6 +113,12 @@ public:
int find(const char* s, int from = 0) const;
// @cmember Sostituisce le occorrenze di <p find_char> col carattere <p replace_char>
int replace(char find_char, char replace_char);
// @cmember Sostituisce le occorrenze di <p find_char> col carattere <p replace_char>
int replace(const char * find_string, const char* replace_string);
// @cmember Ritorna se è contenuta almeno un'occorrenza del carattere c nell'oggetto TString
bool contains(const char c, const int from = 0) const { return find(c, from) >= 0; }
// @cmember Ritorna se è contenuta almeno un'occorrenza della stringa s nell'oggetto TString
bool contains(const char* s, const int from = 0) const { return find(s, from) >= 0; }
// @cmember Ritorna l'oggetto TString composto dai count caratteri da sinistra
const TString& left(int count) const;
@ -648,6 +654,8 @@ public:
void insert_at(const char* s, int n);
// @cmember Toglie la stringa di posizione pos
void destroy(int pos);
// @cmember Toglie la stringa di posizione pos e la ritorna
const char* remove(int pos);
// @cmember Ritorna il prossimo token
const char* get();

View File

@ -13,11 +13,14 @@
#include <variant.h>
#endif
#include <lffiles.h>
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define SAFE_DELETE(p) { delete p; p = NULL; }
#define DEBUG_ENABLED is_debug_station()
class TPerformance_profiler : public TObject
{
TString _desc;
@ -76,4 +79,5 @@ inline const char* get_iva_sirio() // Ritorna la partita IVA della Sirio
TString& to_tstring(long n);
TString& to_tstring(int n);
inline bool is_multi_table(const int file) { return file == LF_TAB || file == LF_TABGEN || file == LF_TABCOM || file == LF_TABMOD; }
#endif /* __UTILITY_H */