moved trim() into its own module to be used by Config

git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@51 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
joshholtrop 2009-08-19 17:08:38 +00:00
parent 86e9c1adbc
commit 39092d710b
6 changed files with 45 additions and 15 deletions

View File

@ -1,6 +1,7 @@
#include "Config.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
@ -16,4 +17,17 @@ Config::Entry::Entry(const string & name)
void Config::read(const char * file)
{
ifstream ifs(file);
if (ifs.is_open())
{
string line;
while (!ifs.eof())
{
getline(ifs, line);
}
}
else
{
cerr << "Warning: Could not open '" << file << "'" << endl;
}
}

View File

@ -23,10 +23,10 @@ class Config
protected:
};
void read(const char * file);
std::string port;
std::vector<Entry> entries;
protected:
std::vector<Entry> m_entries;
void read(const char * file);
};
#endif

View File

@ -6,6 +6,7 @@ OBJS += resources.o
OBJS += pport.o
OBJS += parseCmdLine.o
OBJS += Config.o
OBJS += trim.o
CXXFLAGS := -O2 -Wall
LDFLAGS := -mwindows

View File

@ -1,20 +1,9 @@
#include "parseCmdLine.h"
#include "trim.h"
#include <iostream>
using namespace std;
static std::string trim(const std::string & orig)
{
const char ws[] = " \t\r\n\v\f";
size_t first = orig.find_first_not_of(ws);
size_t last = orig.find_last_not_of(ws);
if (first == string::npos || last == string::npos)
{
return "";
}
return string(orig, first, last - first + 1);
}
std::vector<std::string> parseCmdLine(char * cmdline)
{
enum { WSSKIP, GATHERING, SQUOTE, DQUOTE } state = WSSKIP;

17
trim.cc Normal file
View File

@ -0,0 +1,17 @@
#include "trim.h"
#include <string>
using namespace std;
string trim(const string & orig)
{
const char ws[] = " \t\r\n\v\f";
size_t first = orig.find_first_not_of(ws);
size_t last = orig.find_last_not_of(ws);
if (first == string::npos || last == string::npos)
{
return "";
}
return string(orig, first, last - first + 1);
}

9
trim.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef TRIM_H
#define TRIM_H
#include <string>
std::string trim(const std::string & orig);
#endif