From f4877f669817109f59fd4a1de712bb868bee6b74 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 22 May 2007 09:47:28 +0000 Subject: [PATCH] Added new example. Updated ICU support for VC8 [SVN r37738] --- build/Jamfile.v2 | 5 + example/Jamfile.v2 | 2 + example/snippets/partial_regex_iterate.cpp | 118 +++++++++++++++++++++ test/regress/test_icu.cpp | 2 +- 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 example/snippets/partial_regex_iterate.cpp diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index b1acde23..7eab6fda 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -45,6 +45,10 @@ rule check-icu-config ( ) { gICU_CORE_LIB = icuuc ; } + else if [ GLOB $(dir)/lib : icuuc.* ] + { + gICU_CORE_LIB = icuuc ; + } else if [ GLOB $(dir)/lib : libicuuc.* ] { gICU_CORE_LIB = icuuc ; @@ -188,3 +192,4 @@ lib boost_regex : ../src/$(SOURCES) $(ICU_EXTRA_SOURCE) + diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 8a31b1a2..67b5633e 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -34,6 +34,7 @@ test-suite regex-examples : [ regex-test-run snippets/mfc_example.cpp ] [ regex-test-run snippets/icu_example.cpp ] [ regex-test-run snippets/partial_regex_grep.cpp : $(BOOST_ROOT)/libs/regex/index.htm ] +[ regex-test-run snippets/partial_regex_iterate.cpp : $(BOOST_ROOT)/libs/regex/index.htm ] [ regex-test-run snippets/partial_regex_match.cpp : 1234-5678-8765-4 ] [ regex-test-run snippets/regex_grep_example_1.cpp : $(BOOST_ROOT)/boost/rational.hpp ] [ regex-test-run snippets/regex_grep_example_2.cpp : $(BOOST_ROOT)/boost/rational.hpp ] @@ -62,3 +63,4 @@ test-suite regex-examples : + diff --git a/example/snippets/partial_regex_iterate.cpp b/example/snippets/partial_regex_iterate.cpp new file mode 100644 index 00000000..9ebf33d8 --- /dev/null +++ b/example/snippets/partial_regex_iterate.cpp @@ -0,0 +1,118 @@ +/* + * + * Copyright (c) 1998-2007 + * John Maddock + * + * Use, modification and distribution are subject to the + * Boost Software License, Version 1.0. (See accompanying file + * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ + + /* + * LOCATION: see http://www.boost.org for most recent version. + * FILE partial_regex_iterate.cpp + * VERSION see + * DESCRIPTION: Search example using partial matches. + */ + +#include +#include +#include +#include +#include +#include + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ using ::memmove; } +#endif + +// match some kind of html tag: +boost::regex e("<[^>]*>"); +// count how many: +unsigned int tags = 0; + +void search(std::istream& is) +{ + // buffer we'll be searching in: + char buf[4096]; + // saved position of end of partial match: + const char* next_pos = buf + sizeof(buf); + // flag to indicate whether there is more input to come: + 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: + std::memmove(buf, next_pos, leftover); + // fill the rest from the stream: + 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 iterate: + boost::cregex_iterator a( + buf, + buf + read + leftover, + e, + boost::match_default | boost::match_partial); + boost::cregex_iterator b; + + while(a != b) + { + if((*a)[0].matched == false) + { + // Partial match, save position and break: + next_pos = (*a)[0].first; + break; + } + else + { + // full match: + ++tags; + } + + // move to next match: + ++a; + } + } +} + +int main(int argc, char* argv[]) +{ + if(argc > 1) + { + for(int i = 1; i < argc; ++i) + { + std::ifstream fs(argv[i]); + if(fs.bad()) continue; + search(fs); + fs.close(); + } + } + 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/test/regress/test_icu.cpp b/test/regress/test_icu.cpp index 5379c567..88d6fe4a 100644 --- a/test/regress/test_icu.cpp +++ b/test/regress/test_icu.cpp @@ -39,8 +39,8 @@ class back_insert_iterator { private: Seq* container; - typedef const typename Seq::value_type value_type; public: + typedef const typename Seq::value_type value_type; typedef Seq container_type; typedef std::output_iterator_tag iterator_category;