Dec 292017
Yet Another String class for BC++. All source included. 1.0 Initial Release. Freeware. | |||
---|---|---|---|
File Name | File Size | Zip Size | Zip Type |
ADDC.CPP | 631 | 202 | deflated |
ADDC.OBJ | 596 | 437 | deflated |
ADDP.CPP | 851 | 271 | deflated |
ADDP.OBJ | 717 | 518 | deflated |
ADDS.CPP | 785 | 251 | deflated |
ADDS.OBJ | 724 | 515 | deflated |
CONCATC.CPP | 593 | 182 | deflated |
CONCATC.OBJ | 620 | 451 | deflated |
CONCATP.CPP | 594 | 185 | deflated |
CONCATP.OBJ | 621 | 450 | deflated |
CONCATS.CPP | 596 | 183 | deflated |
CONCATS.OBJ | 631 | 447 | deflated |
CONSTRUC.CPP | 651 | 202 | deflated |
CONSTRUC.OBJ | 698 | 535 | deflated |
CONSTRUD.CPP | 409 | 158 | deflated |
CONSTRUD.OBJ | 689 | 528 | deflated |
CONSTRUP.CPP | 797 | 223 | deflated |
CONSTRUP.OBJ | 729 | 556 | deflated |
CONSTRUS.CPP | 429 | 165 | deflated |
CONSTRUS.OBJ | 719 | 549 | deflated |
COPYP.CPP | 693 | 236 | deflated |
COPYP.OBJ | 751 | 565 | deflated |
COPYS.CPP | 744 | 257 | deflated |
COPYS.OBJ | 741 | 556 | deflated |
FILE.DIZ | 157 | 107 | deflated |
IN.CPP | 667 | 221 | deflated |
IN.OBJ | 623 | 476 | deflated |
MAKEC.CPP | 926 | 271 | deflated |
MAKEC.OBJ | 546 | 413 | deflated |
MAKEFILE | 1517 | 434 | deflated |
OUT.CPP | 397 | 143 | deflated |
OUT.OBJ | 541 | 407 | deflated |
STRING.DOC | 5721 | 1486 | deflated |
STRING.H | 3259 | 853 | deflated |
STRINGS.LIB | 11776 | 2396 | deflated |
STRINGS.LST | 955 | 278 | deflated |
SUBSTR.CPP | 948 | 301 | deflated |
SUBSTR.OBJ | 714 | 533 | deflated |
TEST.CPP | 1362 | 492 | deflated |
TEST.MAP | 874 | 292 | deflated |
TEST.OBJ | 2619 | 1369 | deflated |
Download File STRINGV1.ZIP Here
Contents of the STRING.DOC file
This doc isn't fancy, but here you go!
This Class is gathered up from various sources. Add your own
favourite string routines to it.
Constructors
String();
eg: String fred;
String(char *P);
eg: String fred("initialized");
char *p = "initialized";
String fred(p);
String(String &S);
eg: String fred("xyz");
String barney(fred);
String(char c);
eg: char c;
String fred(c);
Destructor
You can't call it directly, but here it is anyway.
~String() {delete s;}
Assignments
String operator=(String &S);
eg: String a;
String b("hi there");
a = b;
String operator=(char *P);
eg: String a;
char *b = "hi there";
a = b;
Concatenation
void operator += (String& S) { *this = (*this+S); }
eg: String a("hi ");
String b("there");
a += b; //a is now "hi there"
void operator += (char* P) { *this = (*this+P); }
eg: String a("hi ");
char *b = "there";
a += b; //a is now "hi there"
void operator += (char c) { *this = (*this+c); }
eg: String a("hi");
char b = '.';
a += b; //a is now "hi."
String operator+(String &S);
eg: String a("hi ");
String b("there");
String c("not important");
c = a+b; //c is now "hi there"
String operator+(char *P);
eg: String a("hi ");
char *b = "there";
String c("not important");
c = a+b; //c is now "hi there"
String operator+(char c);
eg: String a("hi");
char b = '.';
String c("not important");
c = a+b; //c is now "hi."
Comparisions
These functions are fairly self explanatory. These are overloaded for all
the various permutations of "String .op. char*", "String .op. String" and
"char* .op. String", so you can put them in any order.
Use them something like:
eg: String a("hi");
String b("there");
if ( a < b ) ....
int operator <= (char* P) { return strcmp(s,P) <= 0; }
int operator < (char* P) { return strcmp(s,P) < 0; }
int operator == (char* P) { return strcmp(s,P) == 0; }
int operator > (char* P) { return strcmp(s,P) > 0; }
int operator >= (char* P) { return strcmp(s,P) >= 0; }
int operator != (char* P) { return strcmp(s,P) != 0; }
int operator < (String& S) { return strcmp(s,S.s) < 0; }
int operator == (String& S) { return strcmp(s,S.s) == 0; }
int operator > (String& S) { return strcmp(s,S.s) > 0; }
int operator >= (String& S) { return strcmp(s,S.s) >= 0; }
int operator != (String& S) { return strcmp(s,S.s) != 0; }
int operator <= (String& S) { return strcmp(s,S.s) <= 0; }
friend int operator < (char* P,String& S) { return strcmp(P, S.s) <0; }
friend int operator == (char* P,String& S) { return strcmp(P, S.s)==0; }
friend int operator > (char* P,String& S) { return strcmp(P, S.s) >0; }
friend int operator >= (char* P,String& S) { return strcmp(P, S.s)>=0; }
friend int operator != (char* P,String& S) { return strcmp(P, S.s)!=0; }
friend int operator <= (char* P,String& S) { return strcmp(P, S.s)<=0; }
Array Operator
char &operator[](unsigned i) { return s[i]; }
This is handy for directly referencing or setting characters in the
string. (remember, zero-based!)
eg: String a(":abcdefghi");
char c;
c = a[4]; //c is now 'd'
a[4] = 'x' // a is now ":abcxefghi"
Miscellaneous
int Length(void) { return (len-1);};
Returns the length of the string (not including the Zero byte on the
end)
char *makeCString(void);
Allocates (new) and returns a pointer to a C string. You may want to
free (delete) this when you are done with it!
eg: String a(":abcdefghi");
char *p;
p = a.makeCString();
String SubString(int first,int length);
Returns a sub-string of the original string, starting at character
'first' for 'length' columns.
eg: String a(":abcdefghi");
String b; b = a.SubString(3,5) // b is now "cdefg"
void Upper(void) { strupr(s); };
void Lower(void) { strlwr(s); };
Upper and Lower case the string.
eg: String a(":abcdefghi");
a.Upper(); //a is now ":ABCDEFGHI"
a.Lower(); //a is now ":abcdefghi"
int isEmpty(void) { return (len<=1);};
Boolean. Returns FALSE if the string is empty (ie, only the Zero
byte terminator is in the string.
I/O
The following two are mostly for debug.
void display() { cout << s << '\n';};
void ddisplay() { cout << s << " [" << len << "]\n";};
IOSTREAM
friend ostream &operator<<(ostream &stream, String &S);
eg: String a("Hello,");
String b(" world.");
cout << a << b << endl; // "Hello, world."
friend istream &operator>>(istream &stream, String &S);
eg: String a;
cin >> a; // a will be whatever you type.
This Class is gathered up from various sources. Add your own
favourite string routines to it.
Constructors
String();
eg: String fred;
String(char *P);
eg: String fred("initialized");
char *p = "initialized";
String fred(p);
String(String &S);
eg: String fred("xyz");
String barney(fred);
String(char c);
eg: char c;
String fred(c);
Destructor
You can't call it directly, but here it is anyway.
~String() {delete s;}
Assignments
String operator=(String &S);
eg: String a;
String b("hi there");
a = b;
String operator=(char *P);
eg: String a;
char *b = "hi there";
a = b;
Concatenation
void operator += (String& S) { *this = (*this+S); }
eg: String a("hi ");
String b("there");
a += b; //a is now "hi there"
void operator += (char* P) { *this = (*this+P); }
eg: String a("hi ");
char *b = "there";
a += b; //a is now "hi there"
void operator += (char c) { *this = (*this+c); }
eg: String a("hi");
char b = '.';
a += b; //a is now "hi."
String operator+(String &S);
eg: String a("hi ");
String b("there");
String c("not important");
c = a+b; //c is now "hi there"
String operator+(char *P);
eg: String a("hi ");
char *b = "there";
String c("not important");
c = a+b; //c is now "hi there"
String operator+(char c);
eg: String a("hi");
char b = '.';
String c("not important");
c = a+b; //c is now "hi."
Comparisions
These functions are fairly self explanatory. These are overloaded for all
the various permutations of "String .op. char*", "String .op. String" and
"char* .op. String", so you can put them in any order.
Use them something like:
eg: String a("hi");
String b("there");
if ( a < b ) ....
int operator <= (char* P) { return strcmp(s,P) <= 0; }
int operator < (char* P) { return strcmp(s,P) < 0; }
int operator == (char* P) { return strcmp(s,P) == 0; }
int operator > (char* P) { return strcmp(s,P) > 0; }
int operator >= (char* P) { return strcmp(s,P) >= 0; }
int operator != (char* P) { return strcmp(s,P) != 0; }
int operator < (String& S) { return strcmp(s,S.s) < 0; }
int operator == (String& S) { return strcmp(s,S.s) == 0; }
int operator > (String& S) { return strcmp(s,S.s) > 0; }
int operator >= (String& S) { return strcmp(s,S.s) >= 0; }
int operator != (String& S) { return strcmp(s,S.s) != 0; }
int operator <= (String& S) { return strcmp(s,S.s) <= 0; }
friend int operator < (char* P,String& S) { return strcmp(P, S.s) <0; }
friend int operator == (char* P,String& S) { return strcmp(P, S.s)==0; }
friend int operator > (char* P,String& S) { return strcmp(P, S.s) >0; }
friend int operator >= (char* P,String& S) { return strcmp(P, S.s)>=0; }
friend int operator != (char* P,String& S) { return strcmp(P, S.s)!=0; }
friend int operator <= (char* P,String& S) { return strcmp(P, S.s)<=0; }
Array Operator
char &operator[](unsigned i) { return s[i]; }
This is handy for directly referencing or setting characters in the
string. (remember, zero-based!)
eg: String a(":abcdefghi");
char c;
c = a[4]; //c is now 'd'
a[4] = 'x' // a is now ":abcxefghi"
Miscellaneous
int Length(void) { return (len-1);};
Returns the length of the string (not including the Zero byte on the
end)
char *makeCString(void);
Allocates (new) and returns a pointer to a C string. You may want to
free (delete) this when you are done with it!
eg: String a(":abcdefghi");
char *p;
p = a.makeCString();
String SubString(int first,int length);
Returns a sub-string of the original string, starting at character
'first' for 'length' columns.
eg: String a(":abcdefghi");
String b; b = a.SubString(3,5) // b is now "cdefg"
void Upper(void) { strupr(s); };
void Lower(void) { strlwr(s); };
Upper and Lower case the string.
eg: String a(":abcdefghi");
a.Upper(); //a is now ":ABCDEFGHI"
a.Lower(); //a is now ":abcdefghi"
int isEmpty(void) { return (len<=1);};
Boolean. Returns FALSE if the string is empty (ie, only the Zero
byte terminator is in the string.
I/O
The following two are mostly for debug.
void display() { cout << s << '\n';};
void ddisplay() { cout << s << " [" << len << "]\n";};
IOSTREAM
friend ostream &operator<<(ostream &stream, String &S);
eg: String a("Hello,");
String b(" world.");
cout << a << b << endl; // "Hello, world."
friend istream &operator>>(istream &stream, String &S);
eg: String a;
cin >> a; // a will be whatever you type.
December 29, 2017
Add comments