]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/example/snippets/regex_token_iterator_eg_2.cpp
e3e43de964c0c112765103928dac9c70c864e17f
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 regex_token_iterator_example_2.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: regex_token_iterator example: spit out linked URL's.
23 #include <boost/regex.hpp>
25 boost::regex
e("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"",
26 boost::regex::normal
| boost::regbase::icase
);
28 void load_file(std::string
& s
, std::istream
& is
)
33 // attempt to grow string buffer to match file size,
34 // this doesn't always work...
35 s
.reserve(static_cast<std::string::size_type
>(is
.rdbuf()->in_avail()));
39 // use logarithmic growth stategy, in case
40 // in_avail (above) returned zero:
41 if(s
.capacity() == s
.size())
42 s
.reserve(s
.capacity() * 3);
47 int main(int argc
, char** argv
)
51 for(i
= 1; i
< argc
; ++i
)
53 std::cout
<< "Findings URL's in " << argv
[i
] << ":" << std::endl
;
55 std::ifstream
is(argv
[i
]);
58 boost::sregex_token_iterator
i(s
.begin(), s
.end(), e
, 1);
59 boost::sregex_token_iterator j
;
62 std::cout
<< *i
++ << std::endl
;
66 // alternative method:
67 // test the array-literal constructor, and split out the whole
68 // match as well as $1....
70 for(i
= 1; i
< argc
; ++i
)
72 std::cout
<< "Findings URL's in " << argv
[i
] << ":" << std::endl
;
74 std::ifstream
is(argv
[i
]);
77 const int subs
[] = {1, 0,};
78 boost::sregex_token_iterator
i(s
.begin(), s
.end(), e
, subs
);
79 boost::sregex_token_iterator j
;
82 std::cout
<< *i
++ << std::endl
;