]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/regex/example/snippets/regex_split_example_1.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / regex / example / snippets / regex_split_example_1.cpp
CommitLineData
7c673cae
FG
1/*
2 *
3 * Copyright (c) 1998-2002
4 * John Maddock
5 *
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)
9 *
10 */
11
12 /*
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE regex_split_example_1.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: regex_split example: split a string into tokens.
17 */
18
19
7c673cae 20#include <boost/regex.hpp>
b32b8144 21#include <list>
7c673cae
FG
22
23
24unsigned tokenise(std::list<std::string>& l, std::string& s)
25{
26 return boost::regex_split(std::back_inserter(l), s);
27}
28
29#include <iostream>
30using namespace std;
31
32
33#if defined(BOOST_MSVC) || (defined(__BORLANDC__) && (__BORLANDC__ == 0x550))
34//
35// problem with std::getline under MSVC6sp3
36istream& getline(istream& is, std::string& s)
37{
38 s.erase();
39 char c = static_cast<char>(is.get());
40 while(c != '\n')
41 {
42 s.append(1, c);
43 c = static_cast<char>(is.get());
44 }
45 return is;
46}
47#endif
48
49
50int main(int argc, const char*[])
51{
52 string s;
53 list<string> l;
54 do{
55 if(argc == 1)
56 {
57 cout << "Enter text to split (or \"quit\" to exit): ";
58 getline(cin, s);
59 if(s == "quit") break;
60 }
61 else
62 s = "This is a string of tokens";
63 unsigned result = tokenise(l, s);
64 cout << result << " tokens found" << endl;
65 cout << "The remaining text is: \"" << s << "\"" << endl;
66 while(l.size())
67 {
68 s = *(l.begin());
69 l.pop_front();
70 cout << s << endl;
71 }
72 }while(argc == 1);
73 return 0;
74}
75
76