home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-1.ZIP / CLASSSRC.ZIP / STRNG.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  2KB  |  91 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  STRNG.CPP                                                             */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __CHECKS_H )
  11. #include <Checks.h>
  12. #endif    // __CHECKS_H
  13.  
  14. #if !defined( __STRNG_H )
  15. #include <Strng.h>
  16. #endif  // __STRNG_H
  17.  
  18. #ifndef __STDLIB_H
  19. #include <stdlib.h>
  20. #endif
  21.  
  22. #ifndef __STRING_H
  23. #include <string.h>
  24. #endif
  25.  
  26. #if !defined( __IOSTREAM_H )
  27. #include <iostream.h>
  28. #endif  // __IOSTREAM_H
  29.  
  30. String::String( const char *aPtr )
  31. {
  32.     if ( aPtr == 0 )
  33.         aPtr = "";
  34.  
  35.     len = strlen( aPtr ) + 1;
  36.     theString = new char[ len ];
  37.     CHECK( theString != 0 );
  38.     strcpy( theString, aPtr );
  39. }
  40.  
  41. String::String( const String& sourceString )
  42. {
  43.     len = sourceString.len;
  44.     theString = new char[ len ];
  45.     CHECK( theString != 0 );
  46.     strcpy( theString, sourceString.theString );
  47. }
  48.  
  49. String::isEqual( const Object& testString ) const
  50. {
  51.     return ( len == ((String &)testString).len &&
  52.              !strcmp( theString, ((String &)testString).theString ) );
  53. }
  54.  
  55. int String::isLessThan( const Object& testString ) const
  56. {
  57.     return ( strcmp ( theString, ((String &)testString).theString ) < 0 );
  58. }
  59.  
  60. hashValueType String::hashValue() const
  61. {
  62.     hashValueType   value = hashValueType(0);
  63.     for( int i = 0; i < len; i++ )
  64.         {
  65.         value ^= theString[i];
  66.         value = _rotl( value, 1 );
  67.         }
  68.     return value;
  69. }
  70.  
  71. void String::printOn( ostream& outputStream ) const
  72. {
  73.     outputStream << theString;
  74. }
  75.  
  76. String& String::operator =( const String& sourceString )
  77. {
  78.     if ( *this != sourceString )
  79.         {
  80.         if ( len != sourceString.len )
  81.             {
  82.             delete theString;
  83.             len = sourceString.len;
  84.             theString = new char[ len ];
  85.             CHECK( theString != 0 );
  86.             }
  87.         strcpy( theString, sourceString.theString );
  88.         }
  89.     return *this;
  90. }
  91.