home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------
- // CSTRING.H -
- // (c) 1991 by Thole Groeneveld & toolbox -
- //----------------------------------------------------------
-
- #ifndef __CSTRING_H
- #define __CSTRING_H
-
- #include <iostream.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- class String {
- public:
- String();
- String (const char*);
- String (const String&);
- ~String();
- String& ToLower();
- String& ToUpper();
- String& Reverse();
- String Left (unsigned);
- String Right (unsigned);
- String& InsertAt (unsigned, const String&);
- String& WriteAt (unsigned, const String&);
- int len() { return length; };
- int Find (const char);
- int Find (const String&);
- int Find (const char*);
- friend String ToString (int);
- friend String ToString (long);
- friend String ToString (double);
-
- String& operator = (const String&);
- friend String operator + (const String&,const String&);
- void operator += (const String&);
- String operator () (unsigned, unsigned);
- operator int();
- operator double();
- operator long();
- char& operator [] (unsigned int);
- friend int operator == (const String&, const String&);
- friend int operator < (const String&, const String&);
- friend int operator <= (const String&, const String&);
- friend int operator > (const String&, const String&);
- friend int operator >= (const String&, const String&);
- friend int operator != (const String&, const String&);
- friend ostream& operator << (ostream&, const String&);
- friend istream& operator >> (istream&, String&);
- static void SetToErrHandler (void (*)());
- private:
- String (unsigned); // Konstruktor nur für Memberfkt.
- char *str;
- int length;
- static void (*ErrHandler)();
- };
-
- inline String::~String() {
- delete str;
- }
-
- inline String& String::ToLower() {
- strlwr(str);
- return *this;
- }
-
- inline String& String::ToUpper() {
- strupr(str);
- return *this;
- };
-
- inline String& String::Reverse() {
- strrev (str);
- return *this;
- }
-
- inline int String::Find (const char c) {
- char *pos = strchr (str, int(c));
- return pos ? int(pos - str) : -1;
- }
-
- inline int String::Find (const String& s) {
- char *pos = strstr (str, s.str);
- return pos ? int(pos - str) : -1;
- }
-
- inline int String::Find (const char* s) {
- char *pos = strstr (str, s);
- return pos ? int(pos - str) : -1;
- }
-
- inline String::operator int() {
- return atoi (str);
- }
-
- inline String::operator double() {
- return atof (str);
- }
-
- inline String::operator long() {
- return atol (str);
- }
-
- inline int operator == (const String& s1, const String& s2)
- {
- return stricmp(s1.str, s2.str) == 0;
- }
-
- inline int operator < (const String& s1, const String& s2)
- {
- return stricmp(s1.str, s2.str) < 0;
- }
-
- inline int operator <= (const String& s1, const String& s2)
- {
- return stricmp(s1.str, s2.str) <= 0;
- }
-
- inline int operator >= (const String& s1, const String& s2)
- {
- return stricmp(s1.str, s2.str) >= 0;
- }
-
- inline int operator > (const String& s1, const String& s2)
- {
- return stricmp(s1.str, s2.str) > 0;
- }
-
- inline int operator != (const String& s1, const String& s2)
- {
- return ! (s1 == s2);
- }
-
- inline ostream& operator << (ostream& os, const String& s)
- {
- return os << s.str;
- }
-
- inline void String::SetToErrHandler (void (*Handler)())
- {
- ErrHandler = Handler;
- }
-
- #endif
- //----------------------------------------------------------
- // Ende von CSTRING.H -
-