// String.C -*- C++ -*-
// Copyright (c) 1997, 1998 Etienne BERNARD
+// Copyright (C) 2002,2005 Clinton Ebadi
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
String::String(const std::string & s)
{
p = new srep;
- len = s.length ();
+ // We do this instead of just s.length () because there might be a
+ // \0 in the string before the end (e.g. this is a message from the
+ // Socket's buffer).
+ const char* temp_str = s.c_str ();
+ len = strlen (temp_str);
p->s = new char[len + 1];
- std::strcpy (p->s, s.c_str ());
+ std::strcpy (p->s, temp_str);
}
String::String(const String & s)
return res;
}
+String
+String::substr (int s, int e)
+{
+ return subString (s, e);
+}
+
String
String::subString(int debut)
{
return subString(debut, len - 1);
}
+String
+String::substr (int s)
+{
+ return subString (s);
+}
+
String
String::toLower()
{
while (i < j && (p->s[i] == ' ' || p->s[i] == '\t' || p->s[i] == '\r'))
i++;
- while (j > 0 && (p->s[j] == ' ' || p->s[j] == '\t' || p->s[i] == '\r'))
+ while (j > 0 && (p->s[j] == ' ' || p->s[j] == '\t' || p->s[j] == '\r'))
j--;
return subString(i, j);