home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 10 / string / striass.cpp < prev    next >
C/C++ Source or Header  |  1991-07-30  |  798b  |  45 lines

  1. #include <string.h>
  2. #include <ctype.h>
  3. #include <errno.h>
  4. #include <string.hpp>
  5.  
  6. String &String::operator=(const String&s)
  7. {
  8.     if (this == &s)
  9.         return *this;
  10.     if (--rp->refs < 1)
  11.         delete rp;
  12.     rp = s.rp;
  13.     if (rp)
  14.         rp->refs++;
  15.     return *this;
  16. }
  17.  
  18. String &String::operator=(const char *s)
  19. {
  20.     if (--rp->refs < 1)
  21.         delete rp;
  22.     int n = strlen(s);
  23.     if (n) {
  24.         rp = new(n) srep(n,s);
  25.         if (!rp)
  26.             errno = ENOMEM;
  27.         else
  28.             rp->refs++;
  29.     } else
  30.         rp = 0;
  31.     return *this;
  32. }
  33.  
  34. String &String::operator=(char c)
  35. {
  36.     if (--rp->refs < 1)
  37.         delete rp;
  38.     rp = new(1) srep(1,&c);
  39.     if (!rp)
  40.         errno = ENOMEM;
  41.     else
  42.         rp->refs++;
  43.     return *this;
  44. }
  45.