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