summaryrefslogtreecommitdiff
path: root/lib/String.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/String.cc')
-rw-r--r--lib/String.cc54
1 files changed, 25 insertions, 29 deletions
diff --git a/lib/String.cc b/lib/String.cc
index 0b7b3e6..c960992 100644
--- a/lib/String.cc
+++ b/lib/String.cc
@@ -40,8 +40,6 @@ extern "C" {
int isDateArgument(char *);
}
-char String::t[BUFSIZ + 1];
-
String::String(const String & s) : str((char *) malloc(s.siz + 1)), siz(s.siz) {
memcpy(str, s.str, siz);
str[siz] = 0;
@@ -157,26 +155,23 @@ const char * String::set(const char * s, va_list ap) {
r = str;
#else // !HAVE_VASPRINTF
#ifdef HAVE_VSNPRINTF
- LOCK;
+ char String::t[BUFSIZ + 1];
vsnprintf(t, BUFSIZ, s, ap);
str = Base::strdup(r = t);
- UNLOCK;
#else // !HAVE_VSNPRINTF
#ifdef _WIN32
#ifdef _MSC_VER
r = str = (char *) malloc(_vscprintf(s, ap) + 1);
vsprintf(str, s, ap);
#else
- LOCK;
+ char String::t[BUFSIZ + 1];
_vsnprintf(t, BUFSIZ, s, ap);
str = Base::strdup(r = t);
- UNLOCK;
#endif
#else
- LOCK;
+ char String::t[BUFSIZ + 1];
vsprintf(t, s, ap);
str = Base::strdup(r = t);
- UNLOCK;
#endif
#endif // HAVE_VSNPRINTF
#endif // HAVE_VASPRINTF
@@ -248,18 +243,18 @@ const char * String::to_charp(size_t from, ssize_t to) const throw (GeneralExcep
from -= (to - from) - BUFSIZ;
}
- if (((size_t) to) >= from) {
- size_t i;
- for (i = 0; i <= ((size_t) to) - from; i++) {
- t[i] = str[i + from];
- }
- t[i] = '\0';
- } else {
- t[0] = '\0';
- }
+// if (((size_t) to) >= from) {
+// size_t i;
+// for (i = 0; i <= ((size_t) to) - from; i++) {
+// t[i] = str[i + from];
+// }
+// t[i] = '\0';
+// } else {
+// t[0] = '\0';
+// }
}
- //throw GeneralException("This usage of String is deprecated.");
- return t;
+ throw GeneralException("This usage of String is deprecated.");
+// return t;
}
String String::extract(size_t from, ssize_t to) const {
@@ -370,19 +365,20 @@ size_t String::strlen() const {
return (siz);
}
-char String::operator[](size_t i) const {
+const char & String::operator[](size_t i) const {
+ static const char zero = 0;
+
if (i >= siz) {
- return 0;
+ return zero;
} else {
return str[i];
}
}
-char & String::operator[](size_t i) {
- static char zero = 0;
-
+char & String::operator[](size_t i) throw (GeneralException) {
+
if (i >= siz) {
- return zero;
+ throw GeneralException("operator[] on String out of bounds");
} else {
return str[i];
}
@@ -580,16 +576,15 @@ String & String::iconv(const String & from, const String & _to) {
#else
const char * inbuf;
#endif
- char * outbuf;
+ char * outbuf, * t;
size_t inleft, outleft;
if ((cd = iconv_open(to.str, from.str)) == (iconv_t) (-1)) {
return *this;
}
- LOCK;
inbuf = str;
- outbuf = t;
+ t = outbuf = (char *) malloc(BUFSIZ + 1);
inleft = siz;
outleft = BUFSIZ;
memset(t, 0, BUFSIZ + 1);
@@ -606,9 +601,10 @@ String & String::iconv(const String & from, const String & _to) {
str[siz + 1] = 0;
str[siz + 2] = 0;
str[siz + 3] = 0;
- UNLOCK;
iconv_close(cd);
+
+ free(t);
return *this;
}