1 |
// Vance Thrift and Biller File Utility 2 |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id: IndividualClient.cxx,v 1.3 2003/08/17 23:39:32 douglas Exp $ |
6 |
|
7 |
#include "IndividualClient.h" |
8 |
|
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 |
file << number << "_"; |
36 |
|
37 |
for (unsigned index = 0; index < name.length(); index++) |
38 |
{ |
39 |
if (isspace(name[index])) |
40 |
{ |
41 |
file << '_'; |
42 |
} |
43 |
else if (name[index] != ',' && name[index] != '.') |
44 |
{ |
45 |
file << char(tolower(name[index])); |
46 |
} |
47 |
} |
48 |
|
49 |
this->file = file.str(); |
50 |
} |
51 |
|
52 |
return file; |
53 |
} |
54 |
|
55 |
void IndividualClient::setNumber(unsigned number) |
56 |
{ |
57 |
this->number = number; |
58 |
file = ""; |
59 |
} |
60 |
|
61 |
void IndividualClient::setName(const string& name) |
62 |
{ |
63 |
this->name = name; |
64 |
file = ""; |
65 |
} |
66 |
|
67 |
void IndividualClient::setFile(const string& file) |
68 |
{ |
69 |
this->file = file; |
70 |
number = 0; |
71 |
name = ""; |
72 |
} |
73 |
|
74 |
void IndividualClient::demunge(void) |
75 |
{ |
76 |
istringstream file(demunge(this->file)); |
77 |
|
78 |
file >> number; |
79 |
file.get(); |
80 |
|
81 |
ostringstream name; |
82 |
unsigned count = 1; |
83 |
|
84 |
do |
85 |
{ |
86 |
string word; |
87 |
|
88 |
file >> word; |
89 |
file.get(); |
90 |
|
91 |
if (word.length() == 1 || word == "jr" || word == "sr") |
92 |
{ |
93 |
word += '.'; |
94 |
} |
95 |
else if (word == "de" && count == 1) |
96 |
{ |
97 |
--count; |
98 |
} |
99 |
else if (word == "ii" || word == "iv" || word == "iv") |
100 |
{ |
101 |
capitalize(word += '.', 0, 2); |
102 |
} |
103 |
else if (word == "iii") |
104 |
{ |
105 |
capitalize(word += '.', 0, 3); |
106 |
} |
107 |
else if (word.length() > 2 && word.find("mc") == 0) |
108 |
{ |
109 |
capitalize(word, 2); |
110 |
} |
111 |
else if (word.length() > 3 && word.find("mac") == 0) |
112 |
{ |
113 |
capitalize(word, 3); |
114 |
} |
115 |
else if (word.length() > 2 && word.find("o\'") == 0) |
116 |
{ |
117 |
capitalize(word, 2); |
118 |
} |
119 |
|
120 |
capitalize(word); |
121 |
|
122 |
switch (++count) |
123 |
{ |
124 |
case 1: |
125 |
name << word << " "; |
126 |
break; |
127 |
case 2: |
128 |
name << word; |
129 |
break; |
130 |
case 3: |
131 |
name << ", " << word; |
132 |
break; |
133 |
default: |
134 |
name << " " << word; |
135 |
break; |
136 |
} |
137 |
} |
138 |
while (file.good()); |
139 |
|
140 |
this->name = name.str(); |
141 |
} |
142 |
|
143 |
string IndividualClient::demunge(const string& munged) |
144 |
{ |
145 |
string demunged; |
146 |
|
147 |
for (unsigned index = 0; index < munged.length(); index++) |
148 |
{ |
149 |
if (munged[index] == '_') |
150 |
{ |
151 |
demunged += ' '; |
152 |
} |
153 |
else |
154 |
{ |
155 |
demunged += munged[index]; |
156 |
} |
157 |
} |
158 |
|
159 |
return demunged; |
160 |
} |
161 |
|
162 |
void IndividualClient::capitalize(string& word, unsigned index, unsigned count) |
163 |
{ |
164 |
for (unsigned number = index; number < index + count; number++) |
165 |
{ |
166 |
word[number] = toupper(word[number]); |
167 |
} |
168 |
} |