本文整理汇总了C++中boost::regex::size方法的典型用法代码示例。如果您正苦于以下问题:C++ regex::size方法的具体用法?C++ regex::size怎么用?C++ regex::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::regex
的用法示例。
在下文中一共展示了regex::size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stringToList
/**
* Generic tokenizer.
* Splits source into tokens and tries to lexically cast them to TARGET.
* If that fails, boost::bad_lexical_cast is thrown.
* \param source the source string to be split up
* \param separator regular expression to delimit the tokens (defaults to \\s+)
* \param prefix regular expression for text to be removed from the string before it is split up
* ("^" if not given, will be added at the beginning)
* \param postfix regular expression for text to be removed from the string before it is split up
* ("$" if not given, will be added at the end)
* \returns a list of the casted tokens
*/
template<typename TARGET> std::list<TARGET> stringToList(
std::string source, const boost::regex &separator,
boost::regex prefix, boost::regex postfix )
{
std::list<TARGET> ret;
assert( ! separator.empty() );
if ( ! prefix.empty() ) {
if ( prefix.str()[0] != '^' )
prefix = boost::regex( std::string( "^" ) + prefix.str(), prefix.flags() );
source = boost::regex_replace( source, prefix, "", boost::format_first_only | boost::match_default );
}
if ( ! postfix.empty() ) {
if ( postfix.str()[postfix.size() - 1] != '$' )
postfix = boost::regex( postfix.str() + "$", postfix.flags() );
source = boost::regex_replace( source, postfix, "", boost::format_first_only | boost::match_default );
}
boost::sregex_token_iterator i = boost::make_regex_token_iterator( source, separator, -1 );
const boost::sregex_token_iterator token_end;
while ( i != token_end ) {
ret.push_back( boost::lexical_cast<TARGET>( ( i++ )->str() ) );
}
return ret;
}