- metodi lower() e upper() con parametri from-to

- nuovi metodi shift


git-svn-id: svn://10.65.10.50/trunk@5325 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
augusto 1997-10-06 09:54:03 +00:00
parent d9bc2873d2
commit a768fc142a
2 changed files with 36 additions and 9 deletions

View File

@ -143,6 +143,24 @@ TString::~TString()
delete _str; delete _str;
} }
char TString::shift(int n)
{
CHECK(n>0,"Scorrimento a destra delle stringhe non ancora supportato");
CHECK(n<_size,"Errore di scorrimento");
char r=*(_str+n-1);
if (n)
{
char *c=_str;
while (*c)
{
*(c)=*(c+n);
c++;
}
}
return r;
}
TString& TString::operator <<(const char* s) TString& TString::operator <<(const char* s)
{ {
if (s && *s) if (s && *s)
@ -738,17 +756,21 @@ char* TString::get_buffer(int min_size)
return _str; return _str;
} }
// Certified 100% // Certified 99%
TString& TString::upper() TString& TString::upper(int from, int to)
{ {
for (char* s = _str; *s; s++) *s = toupper(*s); for (int c=0; *(_str+c) && (to<0 || c<=to); c++)
if (c>=from)
*(_str+c) = toupper(*(_str+c));
return *this; return *this;
} }
// Certified 100% // Certified 99%
TString& TString::lower() TString& TString::lower(int from, int to)
{ {
for (char* s = _str; *s; s++) *s = tolower(*s); for (int c=0; *(_str+c) && (to<0 || c<=to); c++)
if (c>=from)
*(_str+c) = tolower(*(_str+c));
return *this; return *this;
} }

View File

@ -179,10 +179,10 @@ public:
char* get_buffer(int min_size = -1); char* get_buffer(int min_size = -1);
// @cmember Converte la stringa in maiuscolo // @cmember Converte la stringa in maiuscolo
TString& upper(); TString& upper(int from =0, int to=-1);
// @cmember Converte la stringa in minuscolo // @cmember Converte la stringa in minuscolo
TString& lower(); TString& lower(int from =0, int to=-1);
// @cmember Permette di ttrovare il plurale di una stringa // @cmember Permette di trovare il plurale di una stringa
TString& add_plural(long num, const char * name); TString& add_plural(long num, const char * name);
// @cmember Assegna la stringa passata con indirizzo // @cmember Assegna la stringa passata con indirizzo
@ -192,6 +192,11 @@ public:
const TString& operator =(const char* s) const TString& operator =(const char* s)
{ return set(s); } { return set(s); }
// @cmember Fa scorrere a sinistra la stringa e restituisce l'ultimo carattere scartato
char shift(int n=1);
// @cmember Fa scorrere a destra la stringa e restituisce l'ultimo carattere scartato
char rshift(int n=1)
{return shift(-n);}
// @cmember Concatena una stringa all'oggetto stringa // @cmember Concatena una stringa all'oggetto stringa
TString& operator <<(const char*); TString& operator <<(const char*);
// @cmember Concatena un carattere all'oggetto stringa // @cmember Concatena un carattere all'oggetto stringa