[2444] | 1 |
|
---|
| 2 | #include "StringFormat.h"
|
---|
| 3 |
|
---|
| 4 | #include "boost/xpressive/xpressive.hpp"
|
---|
| 5 |
|
---|
[2452] | 6 | namespace ariba {
|
---|
| 7 | namespace utility {
|
---|
| 8 | namespace string_format {
|
---|
| 9 |
|
---|
[2444] | 10 | using namespace boost::xpressive;
|
---|
| 11 |
|
---|
| 12 | // regex: string
|
---|
[2452] | 13 | const sregex rstring = '"' >> keep(*~(boost::xpressive::set = '"'))
|
---|
[2444] | 14 | >> '"';
|
---|
| 15 |
|
---|
| 16 | // regex: base64 encoding
|
---|
[2452] | 17 | const sregex rbase64 = '!' >> +(range('a', 'z') | range('A', 'Z')
|
---|
[2444] | 18 | | range('0', '9') | '/' | '+') >> *(boost::xpressive::set = '=');
|
---|
| 19 |
|
---|
| 20 | // regex: raw alphabet
|
---|
[2452] | 21 | const sregex rchars = +(range('a', 'z') | range('A', 'Z'));
|
---|
[2444] | 22 |
|
---|
| 23 | // regex: integer
|
---|
[2452] | 24 | const sregex rint = '0' | (range('1', '9') >> !(range('0', '9')));
|
---|
[2444] | 25 |
|
---|
| 26 | // regex: binary label
|
---|
[2452] | 27 | const sregex rlabel = rchars | rstring | rbase64;
|
---|
[2444] | 28 |
|
---|
| 29 | // regex: dot separated identifier
|
---|
[2452] | 30 | const sregex rid = rlabel >> *('.' >> rlabel) >> *('.' >> rint);
|
---|
[2444] | 31 |
|
---|
| 32 | // regex: "leaf" data
|
---|
[2452] | 33 | const sregex rdata = !(boost::xpressive::set = '!') >> '{'
|
---|
[2444] | 34 | >> *(keep(+~(boost::xpressive::set = '{', '}')) | by_ref(rdata))
|
---|
| 35 | >> '}';
|
---|
| 36 |
|
---|
| 37 | // regex: fields
|
---|
[2452] | 38 | const sregex rfield_label = rlabel >> '=';
|
---|
| 39 | const sregex rfield = !rfield_label >> (rid | rdata);
|
---|
| 40 | const sregex rfields = '(' >> rfield >> *(',' >> rfield) >> ')';
|
---|
[2444] | 41 |
|
---|
[2452] | 42 | // regex objects
|
---|
| 43 | const sregex robject_data = (rdata | rfields);
|
---|
| 44 | const sregex robject_id = rid;
|
---|
| 45 | const sregex robject = robject_id >> robject_data;
|
---|
| 46 | const sregex robjects = robject >> *(',' >> robject);
|
---|
| 47 |
|
---|
| 48 | }}}
|
---|