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:
parent
86e9c1adbc
commit
39092d710b
14
Config.cc
14
Config.cc
@ -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;
|
||||
}
|
||||
}
|
||||
|
6
Config.h
6
Config.h
@ -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
|
||||
|
1
Makefile
1
Makefile
@ -6,6 +6,7 @@ OBJS += resources.o
|
||||
OBJS += pport.o
|
||||
OBJS += parseCmdLine.o
|
||||
OBJS += Config.o
|
||||
OBJS += trim.o
|
||||
CXXFLAGS := -O2 -Wall
|
||||
LDFLAGS := -mwindows
|
||||
|
||||
|
@ -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
17
trim.cc
Normal 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user