// Vance Thrift and Biller File Utility 2 // // Douglas Thrift // // $Id: IndividualClient.cxx,v 1.5 2003/08/20 05:49:34 douglas Exp $ #include "IndividualClient.h" unsigned IndividualClient::getNumber(void) { if (number == 0) { demunge(); } return number; } string IndividualClient::getName(void) { if (name == "") { demunge(); } return name; } string IndividualClient::getFile(void) { if (file == "") { ostringstream file; file << number; istringstream name(this->name); do { string word; name >> word; name.get(); unsigned punk; do { punk = word.find_first_of(",."); if (punk != string::npos) word.erase(punk, 1); } while (punk != string::npos); lowercase(word); file << "_" << word; } while (name.good()); this->file = file.str() + '.' + extension; } return file; } void IndividualClient::setNumber(unsigned number) { this->number = number; file = ""; } void IndividualClient::setName(const string& name) { this->name = name; file = ""; } void IndividualClient::setFile(const string& file) { this->file = file; number = 0; name = ""; } string IndividualClient::extension = "pdf"; void IndividualClient::demunge(void) { istringstream file(demunge(this->file)); file >> number; file.get(); ostringstream name; unsigned count = 1; do { string word; file >> word; file.get(); if (word.length() == 1 || word == "jr" || word == "sr" || word == "dr" || word == "mr" || word == "ms" || word == "mrs") { word += '.'; } else if (word == "de" && count == 1) { --count; } else if (word == "ii" || word == "iv" || word == "iv") { capitalize(word += '.', 0, 2); } else if (word == "iii") { capitalize(word += '.', 0, 3); } else if (word.length() > 2 && word.find("mc") == 0) { capitalize(word, 2); } else if (word.length() > 3 && word.find("mac") == 0) { capitalize(word, 3); } else if (word.length() > 2 && word.find("o\'") == 0) { capitalize(word, 2); } else if (word.length() > 1) { if (!isalpha(word[0])) { capitalize(word, 1); } } capitalize(word); switch (++count) { case 1: name << word << " "; break; case 2: name << word; break; case 3: name << ", " << word; break; default: name << " " << word; break; } } while (file.good()); this->name = name.str(); } string IndividualClient::demunge(const string& munged) { string demunged; for (unsigned index = 0; index < munged.length() - extension.length() - 1; index++) { if (munged[index] == '_') { demunged += ' '; } else { demunged += munged[index]; } } return demunged; } void IndividualClient::capitalize(string& word, unsigned index, unsigned count) { for (unsigned number = index; number < index + count; number++) { word[number] = toupper(word[number]); } }