home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1991 / 02 / grdlagen / cstring.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-11  |  3.8 KB  |  148 lines

  1. //----------------------------------------------------------
  2. //                      CSTRING.H                          -
  3. //        (c) 1991 by Thole Groeneveld & toolbox           -
  4. //----------------------------------------------------------
  5.  
  6. #ifndef __CSTRING_H
  7. #define __CSTRING_H
  8.  
  9. #include <iostream.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13.  
  14. class String {
  15. public:
  16. String();
  17. String (const char*);
  18. String (const String&);
  19. ~String();
  20. String& ToLower();
  21. String& ToUpper();
  22. String& Reverse();
  23. String  Left (unsigned);
  24. String  Right (unsigned);
  25. String& InsertAt (unsigned, const String&);
  26. String& WriteAt  (unsigned, const String&);
  27. int     len() { return length; };
  28. int     Find (const char);
  29. int     Find (const String&);
  30. int     Find (const char*);
  31. friend String ToString (int);
  32. friend String ToString (long);
  33. friend String ToString (double);
  34.  
  35. String& operator =  (const String&);
  36. friend String operator + (const String&,const String&);
  37.    void    operator += (const String&);
  38.    String  operator () (unsigned, unsigned);
  39.    operator int();
  40.    operator double();
  41.    operator long();
  42.    char&   operator [] (unsigned int);
  43. friend int operator == (const String&, const String&);
  44. friend int operator <  (const String&, const String&);
  45. friend int operator <= (const String&, const String&);
  46. friend int operator >  (const String&, const String&);
  47. friend int operator >= (const String&, const String&);
  48. friend int operator != (const String&, const String&);
  49. friend ostream& operator << (ostream&, const String&);
  50. friend istream& operator >> (istream&, String&);
  51. static void SetToErrHandler (void (*)());
  52. private:
  53. String (unsigned);  // Konstruktor nur für Memberfkt.
  54. char *str;
  55. int  length;
  56. static void (*ErrHandler)();
  57. };
  58.  
  59. inline String::~String() {
  60.                            delete str;
  61.                          }
  62.  
  63. inline String& String::ToLower() {
  64.                                    strlwr(str);
  65.                                    return *this;
  66.                                  }
  67.  
  68. inline String& String::ToUpper() {
  69.                                    strupr(str);
  70.                                    return *this;
  71.                                  };
  72.  
  73. inline String& String::Reverse() {
  74.                                    strrev (str);
  75.                                    return *this;
  76.                                  }
  77.  
  78. inline int String::Find (const char c) {
  79. char *pos = strchr (str, int(c));
  80. return pos ? int(pos - str) : -1;
  81. }
  82.  
  83. inline int String::Find (const String& s) {
  84. char *pos = strstr (str, s.str);
  85. return pos ? int(pos - str) : -1;
  86. }
  87.  
  88. inline int String::Find (const char* s) {
  89. char *pos = strstr (str, s);
  90. return pos ? int(pos - str) : -1;
  91. }
  92.  
  93. inline String::operator int() {
  94. return atoi (str);
  95. }
  96.  
  97. inline String::operator double() {
  98.     return atof (str);
  99. }
  100.  
  101. inline String::operator long() {
  102.     return atol (str);
  103. }
  104.  
  105. inline int operator == (const String& s1, const String& s2)
  106. {
  107.  return stricmp(s1.str, s2.str) == 0;
  108. }
  109.  
  110. inline int operator <  (const String& s1, const String& s2)
  111. {
  112.  return stricmp(s1.str, s2.str) < 0;
  113. }
  114.  
  115. inline int operator <= (const String& s1, const String& s2)
  116. {
  117.  return stricmp(s1.str, s2.str) <= 0;
  118. }
  119.  
  120. inline int operator >= (const String& s1, const String& s2)
  121. {
  122.  return stricmp(s1.str, s2.str) >= 0;
  123. }
  124.  
  125. inline int operator >  (const String& s1, const String& s2)
  126. {
  127.  return stricmp(s1.str, s2.str) > 0;
  128. }
  129.  
  130. inline int operator != (const String& s1, const String& s2)
  131. {
  132.  return ! (s1 == s2);
  133. }
  134.  
  135. inline ostream& operator << (ostream& os, const String& s)
  136. {
  137.  return os << s.str;
  138. }
  139.  
  140. inline void String::SetToErrHandler (void (*Handler)())
  141. {
  142.  ErrHandler = Handler;
  143. }
  144.  
  145. #endif
  146. //----------------------------------------------------------
  147. //                 Ende von CSTRING.H                      -
  148.