including refptr in compiler include path; added split() and trim() in TokenDefinition.cc

This commit is contained in:
Josh Holtrop 2010-05-17 15:24:35 -04:00
parent 9d6ede6106
commit 593c0d6cb6
4 changed files with 35 additions and 2 deletions

View File

@ -6,6 +6,7 @@ CXXFLAGS := -O2
DEPS := $(CXXDEPS) DEPS := $(CXXDEPS)
OBJS := $(CXXOBJS) OBJS := $(CXXOBJS)
LDFLAGS := -lpcre LDFLAGS := -lpcre
CPPFLAGS := -I$(shell pwd)/refptr
all: submodule_check tmpl.h $(TARGET) all: submodule_check tmpl.h $(TARGET)

View File

@ -5,7 +5,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "refptr/refptr.h" #include "refptr.h"
#include "TokenDefinition.h" #include "TokenDefinition.h"
#include "RuleDefinition.h" #include "RuleDefinition.h"

View File

@ -3,11 +3,41 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector>
#include "TokenDefinition.h" #include "TokenDefinition.h"
#include "refptr.h"
using namespace std; using namespace std;
#define WHITESPACE " \n\r\t\v"
static string trim(string s)
{
size_t lastpos = s.find_last_not_of(WHITESPACE);
if (lastpos == string::npos)
return "";
s.erase(lastpos + 1);
s.erase(0, s.find_first_not_of(WHITESPACE));
return s;
}
static refptr< vector<string> > split(const string & delim, const string & str)
{
refptr< vector<string> > ret = new vector<string>();
string s = str;
size_t pos;
while ( (pos = s.find(delim)) != string::npos )
{
string t = s.substr(0, pos);
ret->push_back(t);
s.erase(0, pos + 1);
}
if (s != "")
ret->push_back(s);
return ret;
}
static string c_escape(const string & orig) static string c_escape(const string & orig)
{ {
string result; string result;
@ -35,6 +65,8 @@ bool TokenDefinition::create(const string & name,
m_name = name; m_name = name;
m_definition = definition; m_definition = definition;
pcre_free(re); pcre_free(re);
refptr< vector< string > > parts = split(",", flags);
return true; return true;
} }

View File

@ -4,7 +4,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "refptr/refptr.h" #include "refptr.h"
#include "Parser.h" #include "Parser.h"
using namespace std; using namespace std;