From 554832217cb654a0d65ea378d775e20fe8067914 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sun, 16 Dec 2001 11:33:27 +0000 Subject: [PATCH] Updated regex examples and Jamfiles so that most now run as tests. [SVN r12067] --- example/Jamfile | 35 +++++++++++++++++------ example/snippets/partial_regex_grep.cpp | 13 +++++---- example/snippets/regex_grep_example_4.cpp | 10 +++++++ 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/example/Jamfile b/example/Jamfile index ceaa5703..f4ca6a56 100644 --- a/example/Jamfile +++ b/example/Jamfile @@ -21,7 +21,7 @@ exe jgrep : jgrep/jgrep.cpp jgrep/main.cpp debug ; -exe credit_card_example : snippets/credit_card_example.cpp +unit-test credit_card_example : snippets/credit_card_example.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -32,7 +32,7 @@ exe credit_card_example : snippets/credit_card_example.cpp ; -exe partial_regex_grep : snippets/partial_regex_grep.cpp +unit-test partial_regex_grep : snippets/partial_regex_grep.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -40,6 +40,8 @@ exe partial_regex_grep : snippets/partial_regex_grep.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + ../index.htm ; exe partial_regex_match : snippets/partial_regex_match.cpp @@ -52,7 +54,7 @@ exe partial_regex_match : snippets/partial_regex_match.cpp debug ; -exe regex_grep_example_1 : snippets/regex_grep_example_1.cpp +unit-test regex_grep_example_1 : snippets/regex_grep_example_1.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -60,9 +62,11 @@ exe regex_grep_example_1 : snippets/regex_grep_example_1.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + ../../../boost/smart_ptr.hpp ; -exe regex_grep_example_2 : snippets/regex_grep_example_2.cpp +unit-test regex_grep_example_2 : snippets/regex_grep_example_2.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -70,9 +74,11 @@ exe regex_grep_example_2 : snippets/regex_grep_example_2.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + ../../../boost/smart_ptr.hpp ; -exe regex_grep_example_3 : snippets/regex_grep_example_3.cpp +unit-test regex_grep_example_3 : snippets/regex_grep_example_3.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -80,9 +86,11 @@ exe regex_grep_example_3 : snippets/regex_grep_example_3.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + ../../../boost/smart_ptr.hpp ; -exe regex_grep_example_4 : snippets/regex_grep_example_4.cpp +unit-test regex_grep_example_4 : snippets/regex_grep_example_4.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -90,6 +98,8 @@ exe regex_grep_example_4 : snippets/regex_grep_example_4.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + ../../../boost/smart_ptr.hpp ; exe regex_match_example : snippets/regex_match_example.cpp @@ -102,7 +112,7 @@ exe regex_match_example : snippets/regex_match_example.cpp debug ; -exe regex_merge_example : snippets/regex_merge_example.cpp +unit-test regex_merge_example : snippets/regex_merge_example.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -110,9 +120,11 @@ exe regex_merge_example : snippets/regex_merge_example.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + ../../../boost/smart_ptr.hpp ; -exe regex_search_example : snippets/regex_search_example.cpp +unit-test regex_search_example : snippets/regex_search_example.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -120,6 +132,8 @@ exe regex_search_example : snippets/regex_search_example.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + ../../../boost/smart_ptr.hpp ; exe regex_split_example_1 : snippets/regex_split_example_1.cpp @@ -132,7 +146,7 @@ exe regex_split_example_1 : snippets/regex_split_example_1.cpp debug ; -exe regex_split_example_2 : snippets/regex_split_example_2.cpp +unit-test regex_split_example_2 : snippets/regex_split_example_2.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -140,6 +154,8 @@ exe regex_split_example_2 : snippets/regex_split_example_2.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + ../index.htm ; @@ -147,3 +163,4 @@ exe regex_split_example_2 : snippets/regex_split_example_2.cpp + diff --git a/example/snippets/partial_regex_grep.cpp b/example/snippets/partial_regex_grep.cpp index 1139e733..ad1c923d 100644 --- a/example/snippets/partial_regex_grep.cpp +++ b/example/snippets/partial_regex_grep.cpp @@ -10,9 +10,9 @@ boost::regex e("<[^>]*>"); // count how many: unsigned int tags = 0; // saved position of partial match: -char* next_pos = 0; +const char* next_pos = 0; -bool grep_callback(const boost::match_results& m) +bool grep_callback(const boost::match_results& m) { if(m[0].matched == false) { @@ -38,15 +38,16 @@ void search(std::istream& is) // copy forward whatever we have left: memmove(buf, next_pos, leftover); // fill the rest from the stream: - unsigned read = is.readsome(buf + leftover, size); + is.read(buf + leftover, size); + unsigned read = is.gcount(); // 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, + boost::regex_grep(grep_callback, + static_cast(buf), + static_cast(buf + read + leftover), e, boost::match_default | boost::match_partial); } diff --git a/example/snippets/regex_grep_example_4.cpp b/example/snippets/regex_grep_example_4.cpp index f524aafd..e599d7db 100644 --- a/example/snippets/regex_grep_example_4.cpp +++ b/example/snippets/regex_grep_example_4.cpp @@ -21,6 +21,8 @@ * using a C++ Builder closure as a callback. */ +#ifdef __BORLANDC__ + #include #include #include @@ -140,5 +142,13 @@ int main(int argc, const char** argv) return 0; } +#else // __BORLANDC__ + +int main() +{ + return 0; +}; +#endif +