RxString regular expression string library
RxString is a string class that is interchangeable with std::string, but adds additional regex functionality, as well as convertTo / convertFrom template wrappers around std::ostringstream, a trim() and other string functions that we've come to expect from more versatile string classes.
Documentation
When I get around to generating it, it will appear here:
Doxygen documentation of RxString (Doxygen index)
for now, look at rxstring.h.
Use Case
The rconfig? project has a simple use-case (from rconfig.cpp)
/* compile a regex that matches 'key = value', and another that matches non-comments */ static RxString::Regex line_regex("^[[:space:]]*([A-Za-z_][A-Za-z0-9_]*)[[:space:]]*=[[:space:]]*(.*)"); static RxString::Regex comment_regex("[^#]+"); RxString::match_vec_type matches; RxString::match_vec_type rhs; if (line.match(line_regex, &matches)) { RxString val; matches[2].trim(); if (!matches[2].empty() && matches[2][0] == '"') { /* if value starts with a ", treat as a quoted string */ val = getquoted(matches[2]); } else if (matches[2].match(comment_regex, &rhs)) { /* otherwise match anything up to a # (comment) */ val = rhs[0]; } else { return false; /* value is empty */ } /* here matches[1] holds key and val holds value */ }
Requirements
- cmake http://www.cmake.org/
- Preferably a regex library in libc or in lregex (autodetected), otherwise an internal regex implementation is used.
SVN Checkout & Building
svn co http://code.apted.net/svn/pub/rxstring/trunk rxstring mkdir rxstring-build && cd rxstring-build cmake ../rxstring && make /* #include rxtstring.h and link something to librxstring.so */
