diff --git a/demo/jgrep/sunpro.mak b/demo/jgrep/sunpro.mak deleted file mode 100644 index 2ecd2b44..00000000 --- a/demo/jgrep/sunpro.mak +++ /dev/null @@ -1,20 +0,0 @@ -# Makefile for timer application -# -# for SUN workshop 5.0 C++ compiler -# - -CXX=CC -CPP_FLAGS = -O -I../../../../ -I./ - -%.o : %.cpp - $(CXX) -c -o $@ $(CPP_FLAGS) $< - -jgrep : jgrep.o main.o - $(CXX) -o $@ $(CPP_FLAGS) jgrep.o main.o -L../../lib -lregex++ - -clean: - rm -rf SunWS_cache - rm -f jgrep.o jgrep main.o - - - diff --git a/demo/regress/sunpro.mak b/demo/regress/sunpro.mak deleted file mode 100644 index d17ef5d4..00000000 --- a/demo/regress/sunpro.mak +++ /dev/null @@ -1,29 +0,0 @@ -# Makefile for timer application -# -# for SUN workshop 5.0 C++ compiler -# - -CXX=CC -CPP_FLAGS = -O -I../../../../ -I./ - -all: r2 r5 - r2 tests.txt - r5 tests.txt - -%.o : %.cpp - $(CXX) -c -o $@ $(CPP_FLAGS) $< - -r2 : tests.cpp parse.cpp regress.cpp - $(CXX) -o $@ $(CPP_FLAGS) tests.cpp parse.cpp regress.cpp -L../../lib -lregex++ - -r5 : tests.cpp parse.cpp regress.cpp - $(CXX) -o $@ $(CPP_FLAGS) -DTEST_UNICODE tests.cpp parse.cpp regress.cpp -L../../lib -lregex++ - -clean: - rm -rf SunWS_cache - rm -f r2.o r2 r5 r5.o - - - - - diff --git a/demo/snippets/partial_regex_grep.cpp b/demo/snippets/partial_regex_grep.cpp new file mode 100644 index 00000000..d2480c2c --- /dev/null +++ b/demo/snippets/partial_regex_grep.cpp @@ -0,0 +1,82 @@ + +#include +#include +#include +#include +#include + +// match some kind of html tag: +boost::regex e("<[^>]*>"); +// count how many: +unsigned int tags = 0; +// saved position of partial match: +char* next_pos = 0; + +bool grep_callback(const boost::match_results& m) +{ + if(m[0].matched == false) + { + // save position and return: + next_pos = m[0].first; + } + else + ++tags; + return true; +} + +void search(std::istream& is) +{ + char buf[4096]; + next_pos = buf + sizeof(buf); + bool have_more = true; + while(have_more) + { + // how much do we copy forward from last try: + unsigned leftover = (buf + sizeof(buf)) - next_pos; + // and how much is left to fill: + unsigned size = next_pos - buf; + // copy forward whatever we have left: + memcpy(buf, next_pos, leftover); + // fill the rest from the stream: + unsigned read = is.readsome(buf + leftover, size); + // check to see if we've run out of text: + have_more = read == size; + // reset next_pos: + next_pos = buf + sizeof(buf); + // and then grep: + boost::regex_grep(grep_callback, + buf, + buf + read + leftover, + e, + boost::match_default | boost::match_partial); + } +} + +int main(int argc, char* argv[]) +{ + if(argc > 1) + { + for(unsigned int i = 1; i < argc; ++i) + { + std::ifstream fs(argv[i]); + if(fs.bad()) continue; + search(fs); + } + } + else + { + std::string one(""); + std::string what; + while(what.size() < 10000) + { + what.append(one); + what.append(13, ' '); + } + std::stringstream ss; + ss.str(what); + search(ss); + } + std::cout << "total tag count was " << tags << std::endl; + return 0; +} + diff --git a/demo/snippets/partial_regex_match.cpp b/demo/snippets/partial_regex_match.cpp new file mode 100644 index 00000000..5944df37 --- /dev/null +++ b/demo/snippets/partial_regex_match.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +boost::regex e("(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})"); + +bool is_possible_card_number(const std::string& input) +{ + // + // return false for partial match, true for full match, or throw for + // impossible match based on what we have so far... + boost::match_results what; + if(0 == boost::regex_match(input, what, e, boost::match_default | boost::match_partial)) + { + // the input so far could not possibly be valid so reject it: + throw std::runtime_error("Invalid data entered - this could not possibly be a valid card number"); + } + // OK so far so good, but have we finished? + if(what[0].matched) + { + // excellent, we have a result: + return true; + } + // what we have so far is only a partial match... + return false; +} + +int main(int argc, char* argv[]) +{ + try{ + std::string input; + std::cin >> input; + if(is_possible_card_number(input)) + { + std::cout << "Matched OK..." << std::endl; + } + else + std::cout << "Got a partial match..." << std::endl; + } + catch(const std::exception& e) + { + std::cout << e.what() << std::endl; + } + return 0; +} + diff --git a/demo/timer/gcc.mak b/demo/timer/gcc.mak index bfa8d220..eabc68c8 100644 --- a/demo/timer/gcc.mak +++ b/demo/timer/gcc.mak @@ -3,13 +3,14 @@ # # GNU compiler GCC # -CXX=-I../../../../ -I./ +CXX= $(INCLUDES) -I../../../../ -I./ $(CXXFLAGS) timer : regex_timer.cpp - g++ $(CXX) -O2 -o timer regex_timer.cpp -L../../lib/gcc -lregex++ + g++ $(CXX) -O2 -o timer regex_timer.cpp -L../../lib/gcc $(LDFLAGS) -lregex++ $(LIBS) debug : regex_timer.cpp timer.cpp - g++ $(CXX) -g -o timer regex_timer.cpp -L../../lib/gcc -lregex++debug + g++ $(CXX) -g -o timer regex_timer.cpp -L../../lib/gcc $(LDFLAGS) -lregex++debug $(LIBS) + diff --git a/demo/timer/sunpro.mak b/demo/timer/sunpro.mak deleted file mode 100644 index efc77fb3..00000000 --- a/demo/timer/sunpro.mak +++ /dev/null @@ -1,24 +0,0 @@ -# Makefile for timer application -# -# for SUN workshop 5.0 C++ compiler -# - -CXX=CC -CPP_FLAGS = -O -I../../../../ -I./ - -%.o : %.cpp - $(CXX) -c -o $@ $(CPP_FLAGS) $< - -timer : regex_timer.o - $(CXX) -o $@ $(CPP_FLAGS) regex_timer.o -L../../lib -lregex++ - -timer.o : ../../../timer/timer.cpp - $(CXX) -c $(CPPFLAGS) ../../../timer/timer.cpp - -clean: - rm -rf SunWS_cache - rm -f timer.o timer - - - -