home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
STRPP11
/
STR.H
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-23
|
4KB
|
104 lines
/* -------------------------------------------------------------------- */
/* str.h */
/* */
/* String++ Version 1.1 Last revised 03/23/92 */
/* */
/* Enhanced string class for Turbo C++/Borland C++. */
/* Copyright 1991, 1992 by Carl W. Moreland */
/* This source code may be freely distributed as long as the copyright */
/* notice remains intact. */
/* -------------------------------------------------------------------- */
#ifndef STRdotH
#define STRdotH
#include <string.h>
#define LEFT_JUSTIFY 0
#define CENTER_JUSTIFY 1
#define RIGHT_JUSTIFY 2
#define NOCLIP 0
#define CLIP 1
class string
{
private:
char *_ptr;
public:
string(); // default constructor;
string(const char c, // initialize with a character,
unsigned int n = 1); // optional # of characters
string(const char *s, // initialize with a char *,
unsigned int n = 1); // optional # of copies
string(const string& s, // initialize with another string,
unsigned int n = 1); // optional # of copies
~string(void);
const char* ptr(void) const { return _ptr; }
const char* operator()() const { return _ptr; }
const char* operator()(int n) const { return _ptr + n; }
int length(void) const { return strlen(_ptr); }
int len(void) const { return strlen(_ptr); }
string right(int len) const; // right len chars
string left(int len) const; // left len chars
string mid(int pos, int len) const; // middle len chars from pos
string justify(int mode, int len, int clip=0) const;
string& toupper(void); // convert the string to uppercase
string& tolower(void); // convert the string to lowercase
string& operator=(const char); // str1 = char
string& operator=(const char*); // str1 = char*
string& operator=(const string&); // str1 = str
string& operator+=(const char); // str1 += char
string& operator+=(const char*); // str1 += char*
string& operator+=(const string&); // str1 += str
string& operator*=(int n); // str1 *= n
const char operator[](int) const; // ch = str[i]
friend string operator + (const string&, const string&);
friend string operator + (const string&, const char*);
friend string operator + (const char*, const string&);
friend string operator * (const string&, int n);
friend int operator == (const string&, const string&);
friend int operator == (const string&, const char*);
friend int operator == (const char*, const string&);
friend int operator != (const string&, const string&);
friend int operator != (const string&, const char*);
friend int operator != (const char*, const string&);
friend int operator < (const string&, const string&);
friend int operator < (const string&, const char*);
friend int operator < (const char*, const string&);
friend int operator > (const string&, const string&);
friend int operator > (const string&, const char*);
friend int operator > (const char*, const string&);
friend int operator <= (const string&, const string&);
friend int operator <= (const string&, const char*);
friend int operator <= (const char*, const string&);
friend int operator >= (const string&, const string&);
friend int operator >= (const string&, const char*);
friend int operator >= (const char*, const string&);
/* --- Awk-style functions ------------------------------------------ */
friend int length(const string& s) { return s.len(); }
friend int index(const string& s, const string& t);
friend string substr(const string& s, unsigned int p, unsigned int n=10000);
friend int split(const string& s, string **a, const string& fs);
friend int sub(const string& from, const string& to, string& str);
friend int gsub(const string& from, const string& to, string& str, int count=10000);
/* --- Other C-style functions -------------------------------------- */
friend string toupper(const string& s);
friend string tolower(const string& s);
friend string right(const string& s, int n);
friend string left(const string& s, int n);
friend string mid(const string& s,int p,int n);
friend string justify(const string& s, int mode, int len, int clip=1);
};
#endif