1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#ifndef CS23001_STRING_INTERFACE_HPP
#define CS23001_STRING_INTERFACE_HPP
#include <iostream>
#include <vector>
class String {
private:
// helper constructors and methods
String(int);
String(int, const char *);
void reset_capacity(int);
char * str;
// size includes NULL terminator
int string_size;
public:
// constructor: empty string, String('x'), and String("abcd")
String();
String(char);
String(const char *);
// copy ctor, destructor, constant time swap, and assignment
String(const String &);
~String();
void swap(String &);
String & operator= (String);
// subscript: accessor/modifier and accessor
char & operator[](int);
char operator[](int) const;
// max chars that can be stored (not including null terminator)
int capacity() const;
// number of char in string
int length() const;
// concatenation
String operator+ (const String &) const;
String & operator+=(String);
// relational methods
bool operator==(const String &) const;
bool operator< (const String &) const;
// i/o
friend std::ostream& operator<<(std::ostream &, const String &);
friend std::istream& operator>>(std::istream &, String &);
String substr(int, int) const;
int find(char, int) const;
int find(const String & , int) const;
std::vector<String> split(char) const;
};
// free functios for concatenation and relational
String operator+ (const char *, const String &);
String operator+ (char, const String &);
bool operator== (const char *, const String &);
bool operator== (char, const String &);
bool operator< (const char *, const String &);
bool operator< (char, const String &);
bool operator<= (const String &, const String &);
bool operator!= (const String &, const String &);
bool operator>= (const String &, const String &);
bool operator> (const String &, const String &);
int toInt(const String &);
int Pow(int, int);
#endif
|