]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/example/snippets/partial_regex_iterate.cpp
3 * Copyright (c) 1998-2007
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE partial_regex_iterate.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Search example using partial matches.
24 #include <boost/regex.hpp>
26 #ifdef BOOST_NO_STDC_NAMESPACE
27 namespace std
{ using ::memmove
; }
30 // match some kind of html tag:
31 boost::regex
e("<[^>]*>");
33 unsigned int tags
= 0;
35 void search(std::istream
& is
)
37 // buffer we'll be searching in:
39 // saved position of end of partial match:
40 const char* next_pos
= buf
+ sizeof(buf
);
41 // flag to indicate whether there is more input to come:
42 bool have_more
= true;
46 // how much do we copy forward from last try:
47 std::ptrdiff_t leftover
= (buf
+ sizeof(buf
)) - next_pos
;
48 // and how much is left to fill:
49 std::ptrdiff_t size
= next_pos
- buf
;
50 // copy forward whatever we have left:
51 std::memmove(buf
, next_pos
, leftover
);
52 // fill the rest from the stream:
53 is
.read(buf
+ leftover
, size
);
54 std::streamsize read
= is
.gcount();
55 // check to see if we've run out of text:
56 have_more
= read
== size
;
58 next_pos
= buf
+ sizeof(buf
);
60 boost::cregex_iterator
a(
62 buf
+ read
+ leftover
,
64 boost::match_default
| boost::match_partial
);
65 boost::cregex_iterator b
;
69 if((*a
)[0].matched
== false)
71 // Partial match, save position and break:
72 next_pos
= (*a
)[0].first
;
81 // move to next match:
87 int main(int argc
, char* argv
[])
91 for(int i
= 1; i
< argc
; ++i
)
93 std::ifstream
fs(argv
[i
]);
94 if(fs
.bad()) continue;
101 std::string
one("<META NAME=\"keywords\" CONTENT=\"regex++, regular expressions, regular expression library, C++\">");
103 while(what
.size() < 10000)
106 what
.append(13, ' ');
108 std::stringstream ss
;
112 std::cout
<< "total tag count was " << tags
<< std::endl
;