Ignore:
Timestamp:
Feb 18, 2009, 11:39:30 AM (15 years ago)
Author:
mies
Message:

implemented bootstrap info parser

Location:
source/ariba/utility/misc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/utility/misc/StringFormat.cpp

    r2444 r2452  
    44#include "boost/xpressive/xpressive.hpp"
    55
     6namespace ariba {
     7namespace utility {
     8namespace string_format {
     9
    610using namespace boost::xpressive;
    711
    812// regex: string
    9 const sregex StringFormat::rstring = '"' >> keep(*~(boost::xpressive::set = '"'))
     13const sregex rstring = '"' >> keep(*~(boost::xpressive::set = '"'))
    1014                >> '"';
    1115
    1216// regex: base64 encoding
    13 const sregex StringFormat::rbase64 = '!' >> +(range('a', 'z') | range('A', 'Z')
     17const sregex rbase64 = '!' >> +(range('a', 'z') | range('A', 'Z')
    1418                | range('0', '9') | '/' | '+') >> *(boost::xpressive::set = '=');
    1519
    1620// regex: raw alphabet
    17 const sregex StringFormat::rchars = +(range('a', 'z') | range('A', 'Z'));
     21const sregex rchars = +(range('a', 'z') | range('A', 'Z'));
    1822
    1923// regex: integer
    20 const sregex StringFormat::rint = '0' | (range('1', '9') >> !(range('0', '9')));
     24const sregex rint = '0' | (range('1', '9') >> !(range('0', '9')));
    2125
    2226// regex: binary label
    23 const sregex StringFormat::rlabel = rchars | rstring | rbase64;
     27const sregex rlabel = rchars | rstring | rbase64;
    2428
    2529// regex: dot separated identifier
    26 const sregex StringFormat::rid = rlabel >> *('.' >> rlabel) >> *('.' >> rint);
     30const sregex rid = rlabel >> *('.' >> rlabel) >> *('.' >> rint);
    2731
    2832// regex: "leaf" data
    29 const sregex StringFormat::rdata = !(boost::xpressive::set = '!') >> '{'
     33const sregex rdata = !(boost::xpressive::set = '!') >> '{'
    3034                >> *(keep(+~(boost::xpressive::set = '{', '}')) | by_ref(rdata))
    3135                >> '}';
    3236
    3337// regex: fields
    34 const sregex StringFormat::rfield_label = rlabel >> '=';
    35 const sregex StringFormat::rfield = !rfield_label >> (rid | rdata);
    36 const sregex StringFormat::rfields = '(' >> rfield >> *(',' >> rfield) >> ')';
     38const sregex rfield_label = rlabel >> '=';
     39const sregex rfield = !rfield_label >> (rid | rdata);
     40const sregex rfields = '(' >> rfield >> *(',' >> rfield) >> ')';
    3741
    38 // regex: objects
    39 const sregex StringFormat::robject_data = (rdata | rfields);
    40 const sregex StringFormat::robject = rid >> robject_data;
    41 const sregex StringFormat::robjects = robject >> *(',' >> robject);
     42// regex objects
     43const sregex robject_data = (rdata | rfields);
     44const sregex robject_id = rid;
     45const sregex robject = robject_id >> robject_data;
     46const sregex robjects = robject >> *(',' >> robject);
     47
     48}}}
  • source/ariba/utility/misc/StringFormat.h

    r2444 r2452  
    55#include "boost/xpressive/xpressive.hpp"
    66
     7namespace ariba {
     8namespace utility {
     9namespace string_format {
     10
    711using boost::xpressive::sregex;
    812
    9 /**
    10  * This class defines some regular expressions ...
    11  *
    12  * @author Sebastian Mies
    13  */
    14 class StringFormat {
     13class regex_nav {
     14private:
     15        typedef boost::xpressive::smatch _match;
     16        typedef _match::nested_results_type nested_results;
     17        typedef nested_results::const_iterator nested_iterator;
     18        const _match& match;
     19
    1520public:
    16         // regex: string
    17         static const sregex rstring;
     21        regex_nav(const _match& match) :
     22                match(match) {
     23        }
    1824
    19         // regex: base64 encoding
    20         static const sregex rbase64;
     25        regex_nav() :
     26                match(*((const _match*) NULL)) {
     27        }
    2128
    22         // regex: raw alphabet
    23         static const sregex rchars;
     29        bool matched() const {
     30                return &match != NULL;
     31        }
    2432
    25         // regex: integer
    26         static const sregex rint;
     33        regex_nav operator[] (const sregex& type) const {
     34                const nested_results& nr = match.nested_results();
     35                for (nested_iterator i = nr.begin(); i != nr.end(); i++) {
     36                        if (i->regex_id() == type.regex_id()) return regex_nav(*i);
     37                }
     38                return regex_nav();
     39        }
    2740
    28         // regex: binary label
    29         static const sregex rlabel;
     41        regex_nav operator[](int index) const {
     42                const nested_results& nr = match.nested_results();
     43                for (nested_iterator i = nr.begin(); i != nr.end() && index >= 0; i++) {
     44                        if (index == 0) return regex_nav(*i);
     45                        index--;
     46                }
     47                return regex_nav();
     48        }
    3049
    31         // regex: dot separated identifier
    32         static const sregex rid;
     50        int size() const {
     51                return match.nested_results().size();
     52        }
    3353
    34         // regex: "leaf" data
    35         static const sregex rdata;
    36 
    37         // regex: fields
    38         static const sregex rfield_label;
    39         static const sregex rfield;
    40         static const sregex rfields;
    41 
    42         // regex: objects
    43         static const sregex robject_data;
    44         static const sregex robject;
    45         static const sregex robjects;
     54        std::string str() const {
     55                if (!matched()) return std::string("<no match>");
     56                return match[0].str();
     57        }
    4658};
    4759
     60// regex: string
     61extern const sregex rstring;
     62
     63// regex: base64 encoding
     64extern const sregex rbase64;
     65
     66// regex: raw alphabet
     67extern const sregex rchars;
     68
     69// regex: integer
     70extern const sregex rint;
     71
     72// regex: binary label
     73extern const sregex rlabel;
     74
     75// regex: dot separated identifier
     76extern const sregex rid;
     77
     78// regex: "leaf" data
     79extern const sregex rdata;
     80
     81// regex: fields
     82extern const sregex rfield_label;
     83extern const sregex rfield;
     84extern const sregex rfields;
     85
     86// regex: objects
     87extern const sregex robject_data;
     88extern const sregex robject_id;
     89extern const sregex robject;
     90extern const sregex robjects;
     91
     92}}}
     93
    4894#endif /* STRINGFORMAT_H_ */
Note: See TracChangeset for help on using the changeset viewer.