Repository navigation
Expand file tree
/
Copy pathDSString.h
More file actions
157 lines (135 loc) · 4.14 KB
/
Copy pathDSString.h
File metadata and controls
157 lines (135 loc) · 4.14 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef INC_20F_AUTO_IDX_DSSTRING_H
#define INC_20F_AUTO_IDX_DSSTRING_H
#include <iostream>
#include <cstring>
#include <vector>
#include <list>
#include <deque>
#include "DSVector.h"
using namespace std;
class DSString{
private:
/**
* You will need to add some private data members here.
* This is up to your discretion. However, we **strongly**
* encourage you to implement your string class as a wrapper
* for typical null-terminated c-strings. In doing this, you
* may use c-sting functions in the methods in this class such
* as:
* * strlen(...)
* * strcpy(...)
* * strcmp(...)
* * strncpy(...)
* * strcat(...)
* * strncat(...)
*
* A quick google search will return plenty of references on
* the c-string functions.
**/
//Member Variable
typedef char String;
String* string;
int size = 0;
public:
/**
* Constructors and destructor
*
* Make sure you do proper memory management.
**/
DSString();
DSString(const char*);
DSString(const DSString&);
~DSString(){
if(string != NULL) {
string = nullptr;
}
delete[] string;
};
/**
* Standard relational operators. You are free to expand this
* list if you'd like.
*
* Note that for each operator, there are two overloaded versions:
* one that takes a String object
* one that takes a null-terminated c-string
*
**/
DSString& operator= (const char*);
DSString& operator=(const DSString&);
DSString& operator+=(const DSString&);
DSString operator+(const DSString&);
bool operator== (const char*);
bool operator== (const DSString&);
bool operator> (const DSString&);
char& operator[] (const int);
/**
* getLength() returns the number (count) of characters in the string.
**/
int getLength();
/**
* The substring method returns a string object that contains a
* sequence of characters from this string object.
*
* param start - the index of where to start
* param numChars - the number (count) of characters to copy into
* the substring
**/
DSString substring(int, int end = -1);
/**
* the c_str function returns a null-terminated c-string holding the
* contents of this object.
**/
char* c_str();
/**
* Calculate the size of the string
* cal_size()
*/
void cal_Size();
/** String split takes in an delimiter then return back a vector
* @param delimiter, deque, number of time you want to split
*
*/
void split(const char*, DSVector<DSString>&,int times = -1);
/**Find
* find character
* return the position
* @param key, start
* @return index if found otherwise -1
*/
int find(DSString& key, int start = 0);
int find(const char* key, int start = 0);
bool findWord(DSString& key, int start = 0);
/**Lower
* Lower all characters in the string
*/
void lower();
/**Upper
* Upper all characters in the string
*/
void upper();
/** Overloaded stream insertion operator to print the contents of this
* string to the output stream in the first argument.
**/
/** check if the character exist in the string
* @param character
* @return true if exist elese false
*/
bool isExist(char*);
bool isExist(DSString);
void removePunctuation(char*);
void removeChar(char);
void concat(const char*);
void concatChar(char);
void clear();
void changeValStringAt(int index, char val);
void erase(int pos, int length);
friend std::ostream& operator<< (std::ostream&, const DSString&);
friend std::istream& operator>> (std::istream&, DSString&);
//You are free to add more functionality to the class. For example,
//you may want to add a find(...) function that will search for a
//string within a string. (just an example)
//
//Further - you will be able to update and modify this class as the
//semester progresses.
};
#endif //INC_20F_AUTO_IDX_DSSTRING_H