ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/VTBFileUtil2/IndividualClient.cxx
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (16 years, 10 months ago) by douglas
File size: 3711 byte(s)
Log Message:
Rearranged everything else.

File Contents

# User Rev Content
1 douglas 260 // Vance Thrift and Biller File Utility 2
2     //
3     // Douglas Thrift
4     //
5 douglas 284 // $Id: IndividualClient.cxx,v 1.9 2003/09/02 06:05:56 douglas Exp $
6 douglas 260
7     #include "IndividualClient.h"
8 douglas 265
9 douglas 284 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 douglas 265 unsigned IndividualClient::getNumber(void)
21     {
22 douglas 277 if (number == 0 && file != "")
23 douglas 265 {
24     demunge();
25     }
26    
27     return number;
28     }
29    
30     string IndividualClient::getName(void)
31     {
32 douglas 277 if (name == "" && file != "")
33 douglas 265 {
34     demunge();
35     }
36    
37     return name;
38     }
39    
40     string IndividualClient::getFile(void)
41     {
42 douglas 277 if (file == "" && number != 0 && name != "")
43 douglas 265 {
44     ostringstream file;
45    
46 douglas 267 file << number;
47 douglas 265
48 douglas 267 istringstream name(this->name);
49    
50     do
51 douglas 265 {
52 douglas 267 string word;
53    
54     name >> word;
55     name.get();
56    
57     unsigned punk;
58    
59     do
60 douglas 265 {
61 douglas 267 punk = word.find_first_of(",.");
62    
63     if (punk != string::npos) word.erase(punk, 1);
64 douglas 265 }
65 douglas 267 while (punk != string::npos);
66    
67     lowercase(word);
68    
69     file << "_" << word;
70 douglas 265 }
71 douglas 267 while (name.good());
72 douglas 265
73 douglas 271 this->file = file.str() + '.' + extension;
74 douglas 265 }
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 douglas 284
97     if (file != "") demunge();
98 douglas 265 }
99    
100 douglas 284 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 douglas 271 string IndividualClient::extension = "pdf";
121    
122 douglas 265 void IndividualClient::demunge(void)
123     {
124     istringstream file(demunge(this->file));
125    
126     file >> number;
127     file.get();
128    
129     ostringstream name;
130 douglas 266 unsigned count = 1;
131 douglas 265
132     do
133     {
134     string word;
135    
136     file >> word;
137     file.get();
138    
139 douglas 274 if (word.length() == 1 && word != "i")
140 douglas 265 {
141 douglas 273 if (isalpha(word[0])) word += '.';
142     }
143     else if (word == "jr" || word == "sr" || word == "dr" || word == "mr"
144     || word == "ms" || word == "mrs")
145     {
146 douglas 266 word += '.';
147     }
148     else if (word == "de" && count == 1)
149     {
150     --count;
151     }
152     else if (word == "ii" || word == "iv" || word == "iv")
153     {
154 douglas 274 capitalize(word, 0, 2);
155 douglas 266 }
156     else if (word == "iii")
157     {
158 douglas 274 capitalize(word, 0, 3);
159 douglas 266 }
160     else if (word.length() > 2 && word.find("mc") == 0)
161     {
162 douglas 265 capitalize(word, 2);
163     }
164     else if (word.length() > 3 && word.find("mac") == 0)
165     {
166     capitalize(word, 3);
167     }
168 douglas 277 else if (word.length() > word.find_first_of("\'-") + 1 &&
169 douglas 284 word.find_first_of("\'-") != string::npos)
170 douglas 265 {
171 douglas 277 capitalize(word, word.find_first_of("\'-") + 1);
172 douglas 265 }
173 douglas 284 else if (word == "lefevre")
174     {
175     capitalize(word, 2);
176     }
177 douglas 271 else if (word.length() > 1)
178     {
179     if (!isalpha(word[0]))
180     {
181     capitalize(word, 1);
182     }
183     }
184 douglas 265
185     capitalize(word);
186    
187     switch (++count)
188     {
189     case 1:
190 douglas 266 name << word << " ";
191     break;
192     case 2:
193 douglas 265 name << word;
194     break;
195 douglas 266 case 3:
196 douglas 265 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 douglas 271 for (unsigned index = 0; index < munged.length() - extension.length() - 1;
213     index++)
214 douglas 265 {
215     if (munged[index] == '_')
216     {
217     demunged += ' ';
218     }
219     else
220     {
221     demunged += munged[index];
222     }
223     }
224    
225     return demunged;
226     }
227 douglas 266
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     }