ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/IndividualClient.cxx
(Generate patch)

Comparing trunk/VTBFileUtil2/IndividualClient.cxx (file contents):
Revision 265 by douglas, 2003-08-16T20:55:39-07:00 vs.
Revision 284 by douglas, 2003-09-01T23:05:56-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: IndividualClient.cxx,v 1.2 2003/08/17 03:55:39 douglas Exp $
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)
22 >        if (number == 0 && file != "")
23          {
24                  demunge();
25          }
# Line 18 | Line 29 | unsigned IndividualClient::getNumber(voi
29  
30   string IndividualClient::getName(void)
31   {
32 <        if (name == "")
32 >        if (name == "" && file != "")
33          {
34                  demunge();
35          }
# Line 28 | Line 39 | string IndividualClient::getName(void)
39  
40   string IndividualClient::getFile(void)
41   {
42 <        if (file == "")
42 >        if (file == "" && number != 0 && name != "")
43          {
44                  ostringstream file;
45  
46 <                file << number << "_";
46 >                file << number;
47 >
48 >                istringstream name(this->name);
49  
50 <                for (unsigned index = 0; index < name.length(); index++)
50 >                do
51                  {
52 <                        if (isspace(name[index]))
53 <                        {
54 <                                file << '_';
55 <                        }
56 <                        else if (name[index] != ',' && name[index] != '.')
52 >                        string word;
53 >
54 >                        name >> word;
55 >                        name.get();
56 >
57 >                        unsigned punk;
58 >
59 >                        do
60                          {
61 <                                file << char(tolower(name[index]));
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();
73 >                this->file = file.str() + '.' + extension;
74          }
75  
76          return file;
# Line 69 | Line 93 | void IndividualClient::setFile(const str
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));
# Line 79 | Line 127 | void IndividualClient::demunge(void)
127          file.get();
128  
129          ostringstream name;
130 <        unsigned count = 0;
130 >        unsigned count = 1;
131  
132          do
133          {
# Line 88 | Line 136 | void IndividualClient::demunge(void)
136                  file >> word;
137                  file.get();
138  
139 <                if (word.length() == 1) word += '.';
140 <
141 <                if (word.length() > 2 && word.find("mc") == 0)
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                  }
# Line 98 | Line 165 | void IndividualClient::demunge(void)
165                  {
166                          capitalize(word, 3);
167                  }
168 <                else if (word.length() > 2 && word.find("o\'") == 0)
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;
190 >                        name << word << " ";
191                          break;
192                  case 2:
193 +                        name << word;
194 +                        break;
195 +                case 3:
196                          name << ", " << word;
197                          break;
198                  default:
# Line 127 | Line 209 | string IndividualClient::demunge(const s
209   {
210          string demunged;
211  
212 <        for (unsigned index = 0; index < munged.length(); index++)
212 >        for (unsigned index = 0; index < munged.length() - extension.length() - 1;
213 >                index++)
214          {
215                  if (munged[index] == '_')
216                  {
# Line 141 | Line 224 | string IndividualClient::demunge(const s
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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines