summaryrefslogtreecommitdiff
path: root/lib/String.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/String.cc')
-rw-r--r--lib/String.cc31
1 files changed, 14 insertions, 17 deletions
diff --git a/lib/String.cc b/lib/String.cc
index 948f012..529a8dd 100644
--- a/lib/String.cc
+++ b/lib/String.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: String.cc,v 1.48 2007-09-05 14:11:44 pixel Exp $ */
+/* $Id: String.cc,v 1.49 2008-01-25 10:09:19 pixel Exp $ */
#include <stdio.h>
#include <string.h>
@@ -44,7 +44,9 @@ extern "C" {
char String::t[BUFSIZ + 1];
-String::String(const String & s) : str(Base::strdup(s.str)), siz(s.siz) {
+String::String(const String & s) : str((char *) malloc(s.siz + 1)), siz(s.siz) {
+ memcpy(str, s.str, siz);
+ str[siz] = 0;
#ifdef DEBUG
fprintf(stderr, _("Duplicating string `%s', from %p to %p, from this %p to this %p\n"), str, s.str, str, &s, this);
#endif
@@ -58,16 +60,15 @@ String::String(char c) : siz(1) {
#ifdef DEBUG
fprintf(stderr, _("Creating a string with `%c' at %p, this = %p\n"), c, str, this);
#endif
-#ifndef HAVE_ASPRINTF
- char * t = (char *) malloc(2);
- sprintf(t, "%c", c);
- str = t;
-#else
- asprintf(&str, "%c", c);
-#endif
+ str = (char *) malloc(2);
+ str[0] = c;
+ str[1] = 0;
}
-String::String(const char * s) : str(Base::strdup(s)), siz(::strlen(str)) {
+String::String(const char * s, int _siz) : str(0), siz(_siz < 0 ? ::strlen(s) : _siz) {
+ str = (char *) malloc(siz + 1);
+ memcpy(str, s, siz);
+ str[siz] = 0;
#ifdef DEBUG
fprintf(stderr, _("Creating a string with `%s' at %p from %p, this = %p\n"), str, str, s, this);
#endif
@@ -236,11 +237,7 @@ int String::scanf(const ugly_string & s, ...) const {
const char * String::to_charp(size_t from, ssize_t to) const throw (GeneralException) {
if (to < 0) {
- if (from) {
- //throw GeneralException("This usage of String is deprecated.");
- strncpy(t, &(str[from]), BUFSIZ);
- } else
- return str;
+ return str + from;
} else {
if (((size_t) to) >= siz) {
to = siz - 1;
@@ -599,8 +596,8 @@ String & String::iconv(const String & from, const String & _to) {
free(str);
- str = Base::strdup(t);
- siz = ::strlen(t);
+ str = (char *) malloc(outbuf - t + 1);
+ memcpy(str, t, outbuf - t);
UNLOCK;
iconv_close(cd);