home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 3-10.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  881b  |  32 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. #include "3-10.h"
  7. #include "3-11.h"
  8.  
  9. StringRep::StringRep()           { *(rep = new char[1]) = '\e0'; }
  10.  
  11. StringRep::StringRep(const StringRep& s) {
  12.        ::strcpy(rep=new char[::strlen(s.rep)+1], s.rep);
  13. }
  14.  
  15. StringRep::~StringRep()          { delete[] rep; }
  16.  
  17. StringRep::StringRep(const char *s) {
  18.         ::strcpy(rep=new char[::strlen(s)+1], s);
  19. }
  20.  
  21. String StringRep::operator+(const String& s) const {
  22.         char *buf = new char[s->length() + length() + 1];
  23.         ::strcpy(buf, rep);
  24.         ::strcat(buf, s->rep);
  25.         String retval( &buf );
  26.         return retval;
  27. }
  28.  
  29. int StringRep::length() const    { return ::strlen(rep); }
  30.  
  31. void StringRep::print() const    { ::printf("%s\n", rep); }
  32.