// Programmed by Anthony Barbachan // Programmed in Turbo C++ 3.0 // Note: This is the header file for the string library (STRING.LIB) // Version 4.00 // Last Modified On 7/3/95 // Version: 4.01 // Last modified on: 1/21/1999 // Changes: Changed name from string to b_string to prevent compatability // errors with newer versions of C++. Header and source filenames // were also adjusted for name change. // Notes: Functions may be added to all full interface compatability the with // next version of the string class (br_string), optimized string // class with reference counters and length variables. MemError will // also be modified to call the new_handler so that it will share the // same memory error handling function as all the "new" allocated // objects in the program. Class will probably not be changed to use // the new/delete operations instead of calloc/free due to the // non-existance of a calloc nor a realloc. #ifndef __BSTRING_HPP__ #define __BSTRING_HPP__ #include #include #include #include #include #include "dos_comp.h" using std::ostream; using std::istream; ////////////////////////////////////////////////////////////////////////////// class b_string { protected: void MemError() { fprintf(stderr, "\nOut of heap memory.\n"); exit(1); } char* str; public: b_string() { str = NULL; } b_string(const char* s); b_string(b_string& s); void Del(); void clear() { Del(); } int Exists() { return str != NULL; } int HasString() { return str != NULL; } int HasNoString() { return str == NULL; } size_t Len() { return strlen(str); } size_t length() { return Len(); } size_t Size() { return strlen(str); } size_t StrLen() { return strlen(str); } #ifndef unix b_string& StrLwr() { if(str != NULL) strlwr(str); return *this; } b_string& StrUpr() { if(str != NULL) strupr(str); return *this; } b_string& StrRev() { if(str != NULL) strrev(str); return *this; } b_string& StrSet(int c){if(str != NULL) strset(str, c); return *this;} b_string& StrNSet(int c, size_t n) { if(str != NULL) strnset(str, c, n); return *this; } #endif char* StrChr(int c) { return strchr(str, c); } size_t StrCSpn(char* s) { return strcspn(str, s); } size_t StrCSpn(b_string& s) { return strcspn(str, (char *) s); } size_t StrSpn(char* s) { return strspn(str, s); } size_t StrSpn(b_string& s) { return strspn(str, (char *) s); } char* StrPbrk(char* s) { return strpbrk(str, s); } char* StrPbrk(b_string& s) { return strpbrk(str, (char *) s); } char* StrStr(char* s) { return strstr(str, s); } char* StrStr(b_string& s) { return strstr(str, (char *) s); } char* StrRChr(int c) { return strrchr(str, c); } size_t StrXfrm(char* s, size_t n) { return (str != NULL) ? strxfrm(str, s, n) : 0u; } size_t StrXfrm(b_string& s, size_t n) { return (str != NULL) ? strxfrm(str, (char *) s, n) : 0u; } b_string& StrCpy(const char* s) { return *this = s; } b_string& StrCpy(b_string& s) { return *this = (char *) s; } b_string& StrNCpy(const char* s, size_t maxlen); b_string& StrNCpy(b_string& s, size_t m){return StrNCpy((char *) s, m);} b_string& StrCat(const char* s) { return *this += s; } b_string& StrCat(b_string& s) { return *this += (char *) s; } b_string& StrNCat(const char* s, size_t maxlen); b_string& StrNCat(b_string& s, size_t m){return StrNCat((char *) s, m);} b_string& StpCpy(const char* s); b_string& StpCpy(b_string& s) { return StrCpy((char *) s); } b_string StrTok(const char* s); b_string StrTok(b_string& s) { return StrTok((char *) s); } b_string& StrTok(b_string& tokbuf, const char* s); b_string& StrTok(b_string& t, b_string& s){ return StrTok(t,(char *) s); } int StrCmp(const char* s) { return strcmp(str, s); } int StrCmp(b_string& s) { return strcmp(str, (char *) s); } int StrICmp(const char* s) { return stricmp(str, s); } int StrICmp(b_string& s) { return stricmp(str, (char *) s); } int StrNCmp(const char* s, size_t m) { return strncmp(str, s, m); } int StrNCmp(b_string& s,size_t m){return strncmp(str, (char *) s, m);} int StrNICmp(const char* s,size_t m) { return strnicmp(str, s, m); } int StrNICmp(b_string& s,size_t m){return strnicmp(str,(char*) s, m);} void Exchange(b_string& s) { char* temp = s.str; s.str = str; str = temp; } b_string& operator = (const char* s); b_string& operator = (b_string& s) { return *this = (char *) s; } b_string& operator += (const char* s); b_string& operator += (b_string& s) { return *this += (char *) s; } b_string operator + (const char* s); b_string operator + (b_string& s) { return *this + (char *) s; } char& operator [] (size_t cell) { return str[cell]; } int operator == (const char* s) { return strcmp(str, s) == 0; } int operator == (b_string& s) { return strcmp(str, (char *) s) == 0; } int operator != (const char* s) { return strcmp(str, s); } int operator != (b_string& s) { return strcmp(str, (char *) s); } int operator < (const char* s) { return strcmp(str, s) < 0; } int operator < (b_string& s) { return strcmp(str, (char *) s) < 0; } int operator > (const char* s) { return strcmp(str, s) > 0; } int operator > (b_string& s) { return strcmp(str, (char *) s) > 0; } int operator ! () { return str == NULL; } operator char * () { return str; } }; ///////////////////////////////////////*************************************** //*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/ inline ostream& operator << (ostream& output, b_string& str) { return output << (const char *) str; } istream& operator >> (istream& input, b_string& str); //*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/ #endif