-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.cpp
70 lines (59 loc) · 1.41 KB
/
record.cpp
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
// Parke Lovett
/* record.cpp file Class Definition (Implementation of all functions from
* record.h) */
#include "record.h"
Record::~Record() {
if (fields != nullptr) {
delete[] fields;
fields = nullptr;
}
}
Record Record::upper() {
Record tmp = *this;
for (int i = 0; i < tmp.length(); i++) {
tmp[i] = std::toupper(tmp[i]);
}
return tmp;
}
Record Record::lower() {
Record tmp = *this;
for (int i = 0; i < tmp.length(); i++) {
tmp[i] = std::tolower(tmp[i]);
}
return tmp;
}
int Record::compareIgnoreCase(const Record &record) {
Record tmp = *this;
Record tmp2 = record;
return tmp.lower().compare(tmp2.lower());
}
std::istream &operator>>(std::istream &is, Record &r) {
if (is.peek() == '\n')
is.ignore(1);
std::getline(is, r, '\n');
return is;
}
std::ifstream &operator>>(std::ifstream &is, Record &r) {
if (is.peek() == '\n')
is.ignore(1);
std::getline(is, r, '\n');
return is;
}
Record *Record::split(char delimeter) {
Record str = *this;
used = 0;
maxSize = 1;
fields = new Record[maxSize];
int endIndex = str.find(delimeter);
while (endIndex != std::string::npos) {
Record *tmp = new Record[++maxSize];
std::copy(fields, fields + used, tmp);
delete[] fields;
fields = tmp;
fields[used++] = str.substr(0, endIndex);
str.erase(0, endIndex + 1);
endIndex = str.find(delimeter);
}
fields[used++] = str;
return fields;
}