1 |
// Vance Thrift and Biller File Utility 2 |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id: IndividualClient.cxx,v 1.9 2003/09/02 06:05:56 douglas Exp $ |
6 |
|
7 |
#include "IndividualClient.h" |
8 |
|
9 |
IndividualClient::IndividualClient(unsigned number, const string& name) |
10 |
{ |
11 |
setNumber(number); |
12 |
setName(name); |
13 |
} |
14 |
|
15 |
IndividualClient::IndividualClient(const string& file) |
16 |
{ |
17 |
setFile(file); |
18 |
} |
19 |
|
20 |
unsigned IndividualClient::getNumber(void) |
21 |
{ |
22 |
if (number == 0 && file != "") |
23 |
{ |
24 |
demunge(); |
25 |
} |
26 |
|
27 |
return number; |
28 |
} |
29 |
|
30 |
string IndividualClient::getName(void) |
31 |
{ |
32 |
if (name == "" && file != "") |
33 |
{ |
34 |
demunge(); |
35 |
} |
36 |
|
37 |
return name; |
38 |
} |
39 |
|
40 |
string IndividualClient::getFile(void) |
41 |
{ |
42 |
if (file == "" && number != 0 && name != "") |
43 |
{ |
44 |
ostringstream file; |
45 |
|
46 |
file << number; |
47 |
|
48 |
istringstream name(this->name); |
49 |
|
50 |
do |
51 |
{ |
52 |
string word; |
53 |
|
54 |
name >> word; |
55 |
name.get(); |
56 |
|
57 |
unsigned punk; |
58 |
|
59 |
do |
60 |
{ |
61 |
punk = word.find_first_of(",."); |
62 |
|
63 |
if (punk != string::npos) word.erase(punk, 1); |
64 |
} |
65 |
while (punk != string::npos); |
66 |
|
67 |
lowercase(word); |
68 |
|
69 |
file << "_" << word; |
70 |
} |
71 |
while (name.good()); |
72 |
|
73 |
this->file = file.str() + '.' + extension; |
74 |
} |
75 |
|
76 |
return file; |
77 |
} |
78 |
|
79 |
void IndividualClient::setNumber(unsigned number) |
80 |
{ |
81 |
this->number = number; |
82 |
file = ""; |
83 |
} |
84 |
|
85 |
void IndividualClient::setName(const string& name) |
86 |
{ |
87 |
this->name = name; |
88 |
file = ""; |
89 |
} |
90 |
|
91 |
void IndividualClient::setFile(const string& file) |
92 |
{ |
93 |
this->file = file; |
94 |
number = 0; |
95 |
name = ""; |
96 |
|
97 |
if (file != "") demunge(); |
98 |
} |
99 |
|
100 |
bool IndividualClient::operator<(const IndividualClient& data) const |
101 |
{ |
102 |
if (number == data.number) |
103 |
{ |
104 |
return mcLess(name, data.name); |
105 |
} |
106 |
|
107 |
return number < data.number; |
108 |
} |
109 |
|
110 |
bool IndividualClient::operator>(const IndividualClient& data) const |
111 |
{ |
112 |
if (number == data.number) |
113 |
{ |
114 |
return mcGreater(name, data.name); |
115 |
} |
116 |
|
117 |
return number > data.number; |
118 |
} |
119 |
|
120 |
string IndividualClient::extension = "pdf"; |
121 |
|
122 |
void IndividualClient::demunge(void) |
123 |
{ |
124 |
istringstream file(demunge(this->file)); |
125 |
|
126 |
file >> number; |
127 |
file.get(); |
128 |
|
129 |
ostringstream name; |
130 |
unsigned count = 1; |
131 |
|
132 |
do |
133 |
{ |
134 |
string word; |
135 |
|
136 |
file >> word; |
137 |
file.get(); |
138 |
|
139 |
if (word.length() == 1 && word != "i") |
140 |
{ |
141 |
if (isalpha(word[0])) word += '.'; |
142 |
} |
143 |
else if (word == "jr" || word == "sr" || word == "dr" || word == "mr" |
144 |
|| word == "ms" || word == "mrs") |
145 |
{ |
146 |
word += '.'; |
147 |
} |
148 |
else if (word == "de" && count == 1) |
149 |
{ |
150 |
--count; |
151 |
} |
152 |
else if (word == "ii" || word == "iv" || word == "iv") |
153 |
{ |
154 |
capitalize(word, 0, 2); |
155 |
} |
156 |
else if (word == "iii") |
157 |
{ |
158 |
capitalize(word, 0, 3); |
159 |
} |
160 |
else if (word.length() > 2 && word.find("mc") == 0) |
161 |
{ |
162 |
capitalize(word, 2); |
163 |
} |
164 |
else if (word.length() > 3 && word.find("mac") == 0) |
165 |
{ |
166 |
capitalize(word, 3); |
167 |
} |
168 |
else if (word.length() > word.find_first_of("\'-") + 1 && |
169 |
word.find_first_of("\'-") != string::npos) |
170 |
{ |
171 |
capitalize(word, word.find_first_of("\'-") + 1); |
172 |
} |
173 |
else if (word == "lefevre") |
174 |
{ |
175 |
capitalize(word, 2); |
176 |
} |
177 |
else if (word.length() > 1) |
178 |
{ |
179 |
if (!isalpha(word[0])) |
180 |
{ |
181 |
capitalize(word, 1); |
182 |
} |
183 |
} |
184 |
|
185 |
capitalize(word); |
186 |
|
187 |
switch (++count) |
188 |
{ |
189 |
case 1: |
190 |
name << word << " "; |
191 |
break; |
192 |
case 2: |
193 |
name << word; |
194 |
break; |
195 |
case 3: |
196 |
name << ", " << word; |
197 |
break; |
198 |
default: |
199 |
name << " " << word; |
200 |
break; |
201 |
} |
202 |
} |
203 |
while (file.good()); |
204 |
|
205 |
this->name = name.str(); |
206 |
} |
207 |
|
208 |
string IndividualClient::demunge(const string& munged) |
209 |
{ |
210 |
string demunged; |
211 |
|
212 |
for (unsigned index = 0; index < munged.length() - extension.length() - 1; |
213 |
index++) |
214 |
{ |
215 |
if (munged[index] == '_') |
216 |
{ |
217 |
demunged += ' '; |
218 |
} |
219 |
else |
220 |
{ |
221 |
demunged += munged[index]; |
222 |
} |
223 |
} |
224 |
|
225 |
return demunged; |
226 |
} |
227 |
|
228 |
void IndividualClient::capitalize(string& word, unsigned index, unsigned count) |
229 |
{ |
230 |
for (unsigned number = index; number < index + count; number++) |
231 |
{ |
232 |
word[number] = toupper(word[number]); |
233 |
} |
234 |
} |