home *** CD-ROM | disk | FTP | other *** search
- /*
- File: String.c
-
- Author: Bruce Kritt
-
- Description:
- */
-
- #include "string.h"
-
- #include "String.h"
-
- // allowed constructors
-
- String::String(const String& copy)
- {
- length = copy.Length();
- v = new char[Length()+1];
- copy.GetContents(v);
-
- return;
-
- } // end constructor
-
- String::String(char* init)
- {
- length = str_len(init);
- v = new char[Length()+1];
- str_copy(v,init);
-
- return;
-
- } // end constructor
-
- // comparison operators
-
- int operator==(String lhs,String rhs)
- {
- return (str_comp(lhs.v,rhs.v) == 0);
- }
-
- int operator!=(String lhs,String rhs)
- {
- return (str_comp(lhs.v,rhs.v) != 0);
- }
-
- int operator<(String lhs,String rhs)
- {
- return (str_comp(lhs.v,rhs.v) < 0);
- }
-
- int operator>(String lhs,String rhs)
- {
- return (str_comp(lhs.v,rhs.v) > 0);
- }
-
- int operator<=(String lhs,String rhs)
- {
- return (str_comp(lhs.v,rhs.v) <= 0);
- }
-
- int operator>=(String lhs,String rhs)
- {
- return (str_comp(lhs.v,rhs.v) >= 0);
- }
-
- // concatenation operator
-
- String operator+(String lhs,String rhs)
- {
- char* hold_result = new char[lhs.Length()+rhs.Length()+1];
-
- lhs.GetContents(hold_result);
- rhs.GetContents(hold_result+lhs.Length());
-
- String result = hold_result;
-
- delete[lhs.Length()+rhs.Length()+1] hold_result;
-
- return result;
-
- } // end operator +
-