]> cygwin.com Git - cygwin-apps/setup.git/blobdiff - String++.cc
2003-02-16 Pavel Tsekov <ptsekov@gmx.net>
[cygwin-apps/setup.git] / String++.cc
index 90c8bdb8fc65591c88490f892902e730e25fcea0..4d089a86d706adc16c422d8022e31d3d647d0bc5 100644 (file)
 #include "String++.h"
 #include <string.h>
 #include <ctype.h>
-#include "concat.h"
 #include "io_stream.h"
+#include <iostream>
+#include <sstream>
+#include <string>
+
+using namespace std;
 
 // _data
 
@@ -50,6 +54,19 @@ String::~String ()
     delete theData;
 }
 
+String::String (int const anInt)
+{
+  ostringstream os;
+  os << anInt;
+  theData = new _data(os.str().size());
+  memcpy (theData->theString, os.str().c_str(), os.str().size());
+}
+
+String::String (string const &aString) : theData (new _data (aString.c_str() ? strlen (aString.c_str()) : 0))
+{
+  memcpy (theData->theString, aString.c_str(), theData->length);
+}
+
 // able to cache the result if needed.
 char *
 String::cstr ()
@@ -106,6 +123,13 @@ String::find(char aChar) const
   return 0;
 }
 
+String
+String::substr(size_t start, size_t len) const
+{
+  // Adapt the C++ string class
+  return string(cstr_oneuse()).substr(start, len);
+}
+
 int
 String::compare (String const &aString, size_t const count) const
 {
@@ -227,3 +251,13 @@ String::casecompare (String const lhs, String const rhs)
 {
   return lhs.casecompare (rhs);
 }
+
+/* TODO: research how wide char and unicode interoperate with
+ * C++ streams
+ */
+ostream &
+operator << (ostream &os, String const &theString)
+{
+  os << theString.cstr_oneuse();
+  return os;
+}
This page took 0.026413 seconds and 5 git commands to generate.