home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume43 / gen / part02 / String.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-24  |  1.4 KB  |  83 lines

  1. /*
  2. File: String.c
  3.  
  4. Author: Bruce Kritt
  5.  
  6. Description:
  7. */
  8.  
  9. #include "string.h"
  10.  
  11. #include "String.h"
  12.  
  13. // allowed constructors
  14.  
  15. String::String(const String& copy)
  16. {
  17.         length = copy.Length();
  18.         v = new char[Length()+1];
  19.         copy.GetContents(v);
  20.  
  21.         return;
  22.  
  23. }       // end constructor
  24.  
  25. String::String(char* init)
  26. {
  27.         length = str_len(init);
  28.         v = new char[Length()+1];
  29.         str_copy(v,init);
  30.  
  31.         return;
  32.  
  33. }       // end constructor
  34.  
  35. // comparison operators
  36.  
  37. int operator==(String lhs,String rhs)
  38. {
  39.         return (str_comp(lhs.v,rhs.v) == 0);
  40. }
  41.  
  42. int operator!=(String lhs,String rhs)
  43. {
  44.         return (str_comp(lhs.v,rhs.v) != 0);
  45. }
  46.  
  47. int operator<(String lhs,String rhs)
  48. {
  49.         return (str_comp(lhs.v,rhs.v) < 0);
  50. }
  51.  
  52. int operator>(String lhs,String rhs)
  53. {
  54.         return (str_comp(lhs.v,rhs.v) > 0);
  55. }
  56.  
  57. int operator<=(String lhs,String rhs)
  58. {
  59.         return (str_comp(lhs.v,rhs.v) <= 0);
  60. }
  61.  
  62. int operator>=(String lhs,String rhs)
  63. {
  64.         return (str_comp(lhs.v,rhs.v) >= 0);
  65. }
  66.  
  67. // concatenation operator
  68.  
  69. String operator+(String lhs,String rhs)
  70. {
  71.         char* hold_result = new char[lhs.Length()+rhs.Length()+1];
  72.  
  73.         lhs.GetContents(hold_result);
  74.         rhs.GetContents(hold_result+lhs.Length());
  75.  
  76.         String result = hold_result;
  77.  
  78.         delete[lhs.Length()+rhs.Length()+1] hold_result;
  79.  
  80.         return result;
  81.  
  82. }       // end operator +
  83.