Convert String to and from std::string
[libacl.git] / src / string.cpp
index 9f002bb..1235d4d 100644 (file)
@@ -74,6 +74,16 @@ String::String(const substring &x)
    p->n = 1;
 }
 
+String::String(const std::string &x)
+{
+   p = new srep;
+
+   p->n = 1;
+   p->s = new char[x.size()+1];
+   x.copy(p->s, x.size());
+
+}
+
 String::~String()
 {
    if (--p->n == 0)
@@ -138,6 +148,23 @@ String& String::operator=(const String& x)
    return *this;
 }
 
+String& String::operator=(const std::string &x)
+{
+   if (p->n > 1)
+   {                //    Disconnect self
+      p->n--;
+      p = new srep;
+   }
+   else if (p->n == 1)
+      delete p->s;
+
+   p->n = 1;
+   p->s = new char[x.size()+1];
+   x.copy(p->s, x.size());
+
+   return *this;
+}
+
 /*  Numerical conversion */
 
 String::String(int i)