From 593c0d6cb656549f1b3c9ba875884d44de7d9d00 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 17 May 2010 15:24:35 -0400 Subject: [PATCH] including refptr in compiler include path; added split() and trim() in TokenDefinition.cc --- Makefile | 1 + Parser.h | 2 +- TokenDefinition.cc | 32 ++++++++++++++++++++++++++++++++ imbecile.cc | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3814e9a..d9e6007 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ CXXFLAGS := -O2 DEPS := $(CXXDEPS) OBJS := $(CXXOBJS) LDFLAGS := -lpcre +CPPFLAGS := -I$(shell pwd)/refptr all: submodule_check tmpl.h $(TARGET) diff --git a/Parser.h b/Parser.h index 10360a4..7b0773a 100644 --- a/Parser.h +++ b/Parser.h @@ -5,7 +5,7 @@ #include #include -#include "refptr/refptr.h" +#include "refptr.h" #include "TokenDefinition.h" #include "RuleDefinition.h" diff --git a/TokenDefinition.cc b/TokenDefinition.cc index 4ed808c..e085cf2 100644 --- a/TokenDefinition.cc +++ b/TokenDefinition.cc @@ -3,11 +3,41 @@ #include #include +#include #include "TokenDefinition.h" +#include "refptr.h" 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 > split(const string & delim, const string & str) +{ + refptr< vector > ret = new vector(); + 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) { string result; @@ -35,6 +65,8 @@ bool TokenDefinition::create(const string & name, m_name = name; m_definition = definition; pcre_free(re); + + refptr< vector< string > > parts = split(",", flags); return true; } diff --git a/imbecile.cc b/imbecile.cc index 4c73587..52e15b9 100644 --- a/imbecile.cc +++ b/imbecile.cc @@ -4,7 +4,7 @@ #include #include -#include "refptr/refptr.h" +#include "refptr.h" #include "Parser.h" using namespace std;