00001 #include <string.h>
00002 #include "G3string.h"
00003
00004 String::String(const char s[])
00005 {
00006 info_ = new char[strlen(s) + 1];
00007 strcpy(info_, s);
00008 }
00009
00010 String::String(const String& s)
00011 {
00012 info_ = new char[strlen(s.info_) + 1];
00013 strcpy(info_, s.info_);
00014 }
00015
00016 String::~String( )
00017 {
00018 delete [] info_;
00019 }
00020
00021 String& String::operator= (const String& rhs)
00022 {
00023 if (this != &rhs) {
00024 delete [] info_;
00025 info_ = new char[strlen(rhs.info_) +1];
00026 strcpy(info_, rhs.info_);
00027 }
00028 return *this;
00029 }
00030
00031 String& String::operator+= (const String& s)
00032 {
00033 char* temp = new char[strlen(info_) + strlen(s.info_) + 1];
00034
00035 strcpy(temp,info_);
00036 strcat(temp,s.info_);
00037
00038 delete [] info_;
00039 info_ = temp;
00040 return *this;
00041 }
00042
00043 String operator+ (const String& s, const String& t)
00044 {
00045 String temp(s);
00046 temp += t;
00047 return temp;
00048 }
00049
00050 char& String::operator[](int i)
00051 {
00052 return info_[i];
00053 }
00054
00055 char String::operator[](int i) const
00056 {
00057 return info_[i];
00058 }
00059
00060 const char* String::charString() const
00061 {
00062 return info_;
00063 }
00064
00065 OPS_Stream& operator<< (OPS_Stream& out, const String& s)
00066 {
00067 out << s.charString();
00068 return out;
00069 }
00070
00071 istream& operator>> (istream& in, String& s)
00072 {
00073 char buffer[1000];
00074 in.getline(buffer,1000,'\n');
00075
00076
00077
00078 s = String(buffer);
00079
00080 return in;
00081 }
00082
00083 int String::length() const
00084 {
00085 return strlen(info_);
00086 }
00087
00088 bool operator== (const String& s, const String& t)
00089 {
00090 return strcmp(s.info_,t.info_) == 0;
00091 }
00092
00093 bool operator!= (const String& s, const String& t)
00094 {
00095 return strcmp(s.info_,t.info_) != 0;
00096 }
00097
00098 bool operator< (const String& s, const String& t)
00099 {
00100 return strcmp(s.info_,t.info_) < 0;
00101 }
00102
00103 bool operator<= (const String& s, const String& t)
00104 {
00105 return strcmp(s.info_,t.info_) <= 0;
00106 }
00107
00108 bool operator> (const String& s, const String& t)
00109 {
00110 return strcmp(s.info_,t.info_) > 0;
00111 }
00112
00113 bool operator>= (const String& s, const String& t)
00114 {
00115 return strcmp(s.info_,t.info_) >= 0;
00116 }
00117
00118