Updated regex examples and Jamfiles so that most now run as tests.

[SVN r12067]
This commit is contained in:
John Maddock
2001-12-16 11:33:27 +00:00
parent 63130c1ef5
commit 554832217c
3 changed files with 43 additions and 15 deletions

View File

@ -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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -40,6 +40,8 @@ exe partial_regex_grep : snippets/partial_regex_grep.cpp
<define>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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -60,9 +62,11 @@ exe regex_grep_example_1 : snippets/regex_grep_example_1.cpp
<define>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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -70,9 +74,11 @@ exe regex_grep_example_2 : snippets/regex_grep_example_2.cpp
<define>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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -80,9 +86,11 @@ exe regex_grep_example_3 : snippets/regex_grep_example_3.cpp
<define>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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -90,6 +98,8 @@ exe regex_grep_example_4 : snippets/regex_grep_example_4.cpp
<define>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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -110,9 +120,11 @@ exe regex_merge_example : snippets/regex_merge_example.cpp
<define>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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -120,6 +132,8 @@ exe regex_search_example : snippets/regex_search_example.cpp
<define>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
<lib>../build/libboost_regex$(SUFLIB)
:
<include>../../../
@ -140,6 +154,8 @@ exe regex_split_example_2 : snippets/regex_split_example_2.cpp
<define>BOOST_REGEX_STATIC_LINK=1
:
debug
:
../index.htm
;
@ -147,3 +163,4 @@ exe regex_split_example_2 : snippets/regex_split_example_2.cpp

View File

@ -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<char*>& m)
bool grep_callback(const boost::match_results<const char*>& 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<bool(*)(const boost::cmatch&), const char*>(grep_callback,
static_cast<const char*>(buf),
static_cast<const char*>(buf + read + leftover),
e,
boost::match_default | boost::match_partial);
}

View File

@ -21,6 +21,8 @@
* using a C++ Builder closure as a callback.
*/
#ifdef __BORLANDC__
#include <string>
#include <map>
#include <boost/regex.hpp>
@ -140,5 +142,13 @@ int main(int argc, const char** argv)
return 0;
}
#else // __BORLANDC__
int main()
{
return 0;
};
#endif