ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/IndividualClient.cxx
Revision: 267
Committed: 2003-08-18T15:25:29-07:00 (21 years, 10 months ago) by douglas
File size: 2701 byte(s)
Log Message:
istringstream in IndividualClient.getFile().

File Contents

# User Rev Content
1 douglas 260 // Vance Thrift and Biller File Utility 2
2     //
3     // Douglas Thrift
4     //
5 douglas 267 // $Id: IndividualClient.cxx,v 1.4 2003/08/18 22:25:29 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     this->file = file.str();
63     }
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     void IndividualClient::demunge(void)
88     {
89     istringstream file(demunge(this->file));
90    
91     file >> number;
92     file.get();
93    
94     ostringstream name;
95 douglas 266 unsigned count = 1;
96 douglas 265
97     do
98     {
99     string word;
100    
101     file >> word;
102     file.get();
103    
104 douglas 267 if (word.length() == 1 || word == "jr" || word == "sr" || word == "dr"
105     || word == "mr" || word == "ms" || word == "mrs")
106 douglas 265 {
107 douglas 266 word += '.';
108     }
109     else if (word == "de" && count == 1)
110     {
111     --count;
112     }
113     else if (word == "ii" || word == "iv" || word == "iv")
114     {
115     capitalize(word += '.', 0, 2);
116     }
117     else if (word == "iii")
118     {
119     capitalize(word += '.', 0, 3);
120     }
121     else if (word.length() > 2 && word.find("mc") == 0)
122     {
123 douglas 265 capitalize(word, 2);
124     }
125     else if (word.length() > 3 && word.find("mac") == 0)
126     {
127     capitalize(word, 3);
128     }
129     else if (word.length() > 2 && word.find("o\'") == 0)
130     {
131     capitalize(word, 2);
132     }
133    
134     capitalize(word);
135    
136     switch (++count)
137     {
138     case 1:
139 douglas 266 name << word << " ";
140     break;
141     case 2:
142 douglas 265 name << word;
143     break;
144 douglas 266 case 3:
145 douglas 265 name << ", " << word;
146     break;
147     default:
148     name << " " << word;
149     break;
150     }
151     }
152     while (file.good());
153    
154     this->name = name.str();
155     }
156    
157     string IndividualClient::demunge(const string& munged)
158     {
159     string demunged;
160    
161     for (unsigned index = 0; index < munged.length(); index++)
162     {
163     if (munged[index] == '_')
164     {
165     demunged += ' ';
166     }
167     else
168     {
169     demunged += munged[index];
170     }
171     }
172    
173     return demunged;
174     }
175 douglas 266
176     void IndividualClient::capitalize(string& word, unsigned index, unsigned count)
177     {
178     for (unsigned number = index; number < index + count; number++)
179     {
180     word[number] = toupper(word[number]);
181     }
182     }