diff options
author | pixel <pixel> | 2002-11-29 20:39:44 +0000 |
---|---|---|
committer | pixel <pixel> | 2002-11-29 20:39:44 +0000 |
commit | ed0ed93bc9a64412c04a73938b04079cad95c4af (patch) | |
tree | 985cbfc9e800d0ee6d28ebb542d6ee79c9a4cc96 /lib/String.cc | |
parent | a69ef2131749e05bb43106d48139638de0144f69 (diff) |
Yeah... reworking on it!
Diffstat (limited to 'lib/String.cc')
-rw-r--r-- | lib/String.cc | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/lib/String.cc b/lib/String.cc index 786c623..c7cfce6 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -1,18 +1,27 @@ #include <iostream> #include <string.h> #include <stdarg.h> +#include <ctype.h> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "String.h" #include "Exceptions.h" -#include "config.h" +#ifdef USE_DATE extern "C" { double dateCalc(char *, char *); int isDateArgument(char *); } +#endif char String::t[BUFSIZ + 1]; -String::String(const String & s) : str(Base::strdup(s.str)), siz(s.siz) { } +String::String(const String & s) : str(Base::strdup(s.str)), siz(s.siz) { +#ifdef DEBUG + fprintf(stderr, "Duplicating string `%s', from %p to %p\n", str, s.str, str); +#endif +} String::String(char c) : siz(1) { char * t = (char *) malloc(2); @@ -21,9 +30,27 @@ String::String(char c) : siz(1) { str = t; } -String::String(const char * s) : str(s ? Base::strdup(s) : Base::strdup("")) { +String::String(const char * s) : str(Base::strdup(s)), siz(::strlen(str)) { +#ifdef DEBUG + fprintf(stderr, "Creating a string with `%s' at %p\n", str, str); +#endif +} + +#if 0 +String::String(const char * s, ...) { + va_list ap; + +#ifdef DEBUG + fprintf(stderr, "Creating a String with s = '%s'\n", s); +#endif + + va_start(ap, s); + vsnprintf(t, BUFSIZ, s, ap); + str = Base::strdup(t); + va_end(ap); siz = ::strlen(str); -} +} +#endif String::String(int hs, const char * s) : str(s ? Base::strdup(s) : Base::strdup("")), siz(hs) { } @@ -43,6 +70,7 @@ String::String(unsigned int i) { siz = ::strlen(str); } +#ifdef USE_LONG_LONG String::String(long long l) { char t[40]; @@ -58,6 +86,7 @@ String::String(unsigned long long l) { str = Base::strdup(t); siz = ::strlen(str); } +#endif String::String(double d) { char t[30]; @@ -74,6 +103,13 @@ String::~String() { const char * String::set(const char * s, ...) { va_list ap; + if (!s) { + free(str); + str = Base::strdup(""); + t[0] = 0; + return t; + } + /* This causes a warning: cannot pass objects of type `const String' through `...' but it is not really a problem. */ va_start(ap, s); @@ -268,10 +304,12 @@ int String::strchrcnt(char c) const { return cnt; } +#ifdef USE_DATE String String::to_sqldate(void) const { /* DD/MM/YYYY ==> YYYYMMMDD */ return (is_date() ? extract(6, 9) + extract(3, 4) + extract(0, 1) : ""); } +#endif String String::to_sqltime(void) const { /* h:m ==> h * 60 + m */ @@ -279,10 +317,12 @@ String String::to_sqltime(void) const { return (is_time() ? String(extract(0, p - 1).to_int() * 60 + extract(p + 1).to_int()) : ""); } +#ifdef USE_DATE String String::from_sqldate(void) const { /* YYYYMMDD ==> DD/MM/YYYY */ return ((strlen() == 8) && is_number() ? extract(6, 7) + '/' + extract(4, 5) + '/' + extract(0, 3) : ""); } +#endif String String::from_sqltime(void) const { /* t ==> (t / 60):(t % 60) */ @@ -290,6 +330,7 @@ String String::from_sqltime(void) const { return (is_number() ? String((int) (t / 60)) + ':' + (t % 60) : ""); } +#ifdef USE_DATE bool String::is_date(void) const { /* 'DD/MM/YYYY' 0123456789 */ @@ -314,6 +355,7 @@ double String::datedif(const String & s) const { return -1; } +#endif bool String::is_number(void) const { for (size_t i = ((str[0] == '-') ? 1 : 0); i < siz; i++) { @@ -350,3 +392,23 @@ bool String::is_time(void) const { return (extract(p + 1).to_int() < 60) ? true : false; } + +String operator+(const char * a, const String & b) { + return String(a) + b; +} + +String & String::toupper() { + for (int i = 0; i < strlen(); i++) { + str[i] = ::toupper(str[i]); + } + + return *this; +} + +String & String::tolower() { + for (int i = 0; i < strlen(); i++) { + str[i] = ::tolower(str[i]); + } + + return *this; +} |