-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.hpp
More file actions
67 lines (59 loc) · 3.03 KB
/
string.hpp
File metadata and controls
67 lines (59 loc) · 3.03 KB
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
//File: string.hpp
//
//Version: 1.1
//Date: Fall 2023
//Author: Dr. J. Maletic
//
//Description: Interface definition of String class for use with test oracle.
// For use with Project 2, milestone 2, 3, 4.
//
// To use the supplied test oracles you will need to use this interface and namings.
// You must also have all of these methods and functions defined for your string class.
//
// You can NOT add any attributes/members. If you do the test oracles will not work.
//
// You need to implement all of the methods and funcitons declared here.
//
#ifndef CS23001_STRING_INTERFACE_HPP
#define CS23001_STRING_INTERFACE_HPP
#include <iostream>
#include <vector>
// CLASS INV: str[length()] == 0 &&
// length() == capacity() &&
// capacity() == stringSize - 1
class String {
public:
String (); //Empty string
String (char); //String('x')
String (const char[]); //String("abc")
String (const String&); //Copy Constructor
~String (); //Destructor
void swap (String&); //Constant time swap
String& operator= (String); //Assignment Copy
int capacity () const; //Max chars that can be stored
int length () const; //Actual number of chars in string
char& operator[] (int); //Accessor/Modifier
char operator[] (int) const; //Accessor
String& operator+= (const String&);
bool operator== (const String&) const;
bool operator< (const String&) const;
String substr (int, int) const; //sub from staring to ending position
int findch (int, char) const; //Location of charater starting at position
int findstr (int, const String&) const; //Location of string starting at a position
std::vector<String> split (char) const;
friend std::ostream& operator<<(std::ostream&, const String&);
friend std::istream& operator>>(std::istream&, String&);
private:
char *str; //Pointer to char[]
int stringSize; //Size includes NULL terminator
};
String operator+ (String, 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&);
#endif