Project

General

Profile

« Previous | Next » 

Revision 0a32fd63

Added by david.sorber over 2 years ago

Improved filtering and added parsing input from a plaintext file.

View differences:

src/Catalog.cc
#include <algorithm>
#include <fstream>
#include <iostream>
#include "Catalog.h"
Catalog::Catalog()
{
// Temporarily fill the catalog with some test data
/*
{"Target", "baranovich@gmail.com\nF-B-3-7"},
{"United", "david.sorber@gmail.com\nF-B-3-7"},
{"Pepco", "david.sorber@gmail.com\nNZ-98-O"},
{"Washington Gas", "baranovich@gmail.com\nS-N-718"}
*/
#if 0
m_catalog.push_back({"Target", "baranovich@gmail.com\nF-B-3-7"});
m_catalog.push_back({"United", "david.sorber@gmail.com\nF-B-3-7"});
m_catalog.push_back({"Pepco", "david.sorber@gmail.com\nNZ-98-O"});
m_catalog.push_back({"Washington Gas", "baranovich@gmail.com\nS-N-718"});
#else
const std::string pwFile("/home/dsorber/Documents/chicken_soup/chicken_soup.txt");
std::ifstream infile(pwFile);
if (! infile)
{
return;
}
// Iterate over the PW file and parse it (key is first line of each stanza
// and the value are the remaining lines)
std::string line;
std::string key;
std::string value;
bool firstLine = true;
while (std::getline(infile, line))
{
if (line.size() == 0)
{
// Debuggery
// std::cout << "KEY: " << key << std::endl;
// std::cout << "VAL: " << value << "\n" << std::endl;
m_catalog.push_back({key, value});
firstLine = true;
}
else
{
if (firstLine)
{
key.clear();
value.clear();
key.swap(line);
firstLine = false;
}
else
{
value += line + "\n";
}
}
}
// Debuggery
// std::cout << "KEY: " << key << std::endl;
// std::cout << "VAL: " << value << "\n" << std::endl;
m_catalog.push_back({key, value});
// Close the input file
infile.close();
#endif
// Sort the catalog (A -> Z) for display purposes
std::sort(

Also available in: Unified diff