diff --git a/include/strings.cpp b/include/strings.cpp index 7deddbd43..522496616 100755 --- a/include/strings.cpp +++ b/include/strings.cpp @@ -513,6 +513,29 @@ TString& TString::lower() return *this; } +// Certified 50% +TString& TString::add_plural(long num, const char* name) +{ + const TFixed_string n(name); + const char last = n[n.len()-1]; + + if (num < 1) + { + *this << "nessun"; + if (toupper(last) == 'A' || toupper(n[0]) == 'Z' || + toupper(n[0]) == 'S' && strchr("aeiouAEIOU", n[1]) == NULL) + *this << tolower(last); + *this << ' ' << name; + } + else + { + *this << num << ' ' << name; + if (num > 1) + _str[len()-1] = (last == 'a') ? 'e' : 'i'; + } + + return *this; +} // Certified 90% TString& TString::overwrite(const char* s, int pos) @@ -614,8 +637,6 @@ TString& TFixed_string::format(const char* fmt, ...) // Filename /////////////////////////////////////////////////////////// -inline bool is_not_slash(char s) -{ return s != '\\' && s != '/'; } // Certified 90% const char* TFilename::ext() const @@ -769,10 +790,10 @@ const TFilename& TFilename::tempdir() putenv(_tempdir); } - return set(_tempdir.mid(4)); + set(_tempdir.mid(4)); + return *this; } - // Certified 50% const TFilename& TFilename::temp(const char* prefix) { @@ -800,6 +821,7 @@ const TFilename& TFilename::temp(const char* prefix) else cut(0); char* t = tempnam(NULL, (char*)_str); + CHECK(t != NULL, "Can't execute tempnam"); set(t); free(t); diff --git a/include/strings.h b/include/strings.h index 453046b29..560f1370e 100755 --- a/include/strings.h +++ b/include/strings.h @@ -103,12 +103,16 @@ public: TString& left_just(int n = -1, char c = ' '); // Giustifica a sinistra TString& picture(const char* pic, const char* s); - virtual TString& format(const char* fmt, ...); +#ifndef __WATCOMC__ + virtual +#endif + TString& format(const char* fmt, ...); TString& cut(int n); // Inserisce un '\0' alla posizione n-esima. TString& upper(); // Mette la stringa in maiuscolo - TString& lower(); // Mette la stringa in minuscolo + TString& lower(); // Mette la stringa in minuscolo + TString& add_plural(long num, const char * name); // aggiunge il plurale di name /////////////////////////////////////////////////////////// // @DES Standard operators @@ -154,7 +158,10 @@ public: TFixed_string(const char* str, int size = -1); virtual ~TFixed_string(); - virtual TString& format(const char* fmt, ...); +#ifndef __WATCOMC__ + virtual +#endif + TString& format(const char* fmt, ...); const TString& operator =(const TString& s) { return set((const char*)s); } const TString& operator=(const char* str) { return set(str); }