1 |
|
---|
2 |
|
---|
3 | #include <boost/tokenizer.hpp>
|
---|
4 | #include <boost/format.hpp>
|
---|
5 | #include <boost/lexical_cast.hpp>
|
---|
6 | #include <boost/regex.hpp>
|
---|
7 | #include <boost/foreach.hpp>
|
---|
8 |
|
---|
9 | #include <iostream>
|
---|
10 |
|
---|
11 | bool parseBusName(const std::string& busName, char busOpen, char busDivide, char busClose, std::string& baseName, size_t& firstIndex, size_t& secondIndex) {
|
---|
12 |
|
---|
13 | boost::regex regularExpressionBus (
|
---|
14 | //Name - anything but bus_open
|
---|
15 | "^([^" + std::string(1, busOpen) + "]+)"
|
---|
16 | // bus_open
|
---|
17 | + std::string(1, busOpen) +
|
---|
18 | //End bus index
|
---|
19 | "([0-9]+)"
|
---|
20 | //Colon
|
---|
21 | + std::string(1, busDivide) +
|
---|
22 | //Start bus index
|
---|
23 | "([0-9]+)"
|
---|
24 | //bus_close
|
---|
25 | + std::string(1, busClose), boost::regex::extended);
|
---|
26 | boost::cmatch what;
|
---|
27 | if(!regex_match(busName.c_str(), what, regularExpressionBus))
|
---|
28 | return false;
|
---|
29 |
|
---|
30 | std::cerr << what.size() << " >" << what[1] << "< >" << what[2] << "< >" << what[3] << "<" << std::endl;
|
---|
31 |
|
---|
32 | baseName = what[1];
|
---|
33 | firstIndex = boost::lexical_cast<int>(what[2]);
|
---|
34 | secondIndex = boost::lexical_cast<int>(what[3]);
|
---|
35 | return true;
|
---|
36 |
|
---|
37 | }
|
---|
38 |
|
---|
39 | int main()
|
---|
40 | {
|
---|
41 | char busOpen = '<';
|
---|
42 | char busDivide = ':';
|
---|
43 | char busClose = '>';
|
---|
44 |
|
---|
45 | std::string baseName;
|
---|
46 | size_t first, second;
|
---|
47 | parseBusName("abc<3:1>", busOpen, busDivide, busClose, baseName, first, second);
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|