本文整理汇总了C++中boost::regex::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ regex::empty方法的具体用法?C++ regex::empty怎么用?C++ regex::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::regex
的用法示例。
在下文中一共展示了regex::empty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: operator
bool operator()(const boost::regex& r) const {
try {
return !r.empty() && boost::regex_search(str, r);
} catch(const std::runtime_error&) {
// most likely a stack overflow, ignore...
return false;
}
}
示例3: copy_path
void bcp_implementation::copy_path(const fs::path& p)
{
assert(!fs::is_directory(m_boost_path / p));
if(fs::exists(m_dest_path / p))
{
std::cout << "Copying (and overwriting) file: " << p.string() << "\n";
fs::remove(m_dest_path / p);
}
else
std::cout << "Copying file: " << p.string() << "\n";
//
// create the path to the new file if it doesn't already exist:
//
create_path(p.branch_path());
//
// do text based copy if requested:
//
if(p.leaf() == "Jamroot")
{
static std::vector<char> v1, v2;
v1.clear();
v2.clear();
std::ifstream is((m_boost_path / p).c_str());
std::copy(std::istreambuf_iterator<char>(is), std::istreambuf_iterator<char>(), std::back_inserter(v1));
static boost::regex libname_matcher;
if(libname_matcher.empty())
{
libname_matcher.assign("boost_");
}
regex_replace(std::back_inserter(v2), v1.begin(), v1.end(), libname_matcher, m_namespace_name + "_");
std::swap(v1, v2);
v2.clear();
std::ofstream os;
if(m_unix_lines)
os.open((m_dest_path / p).c_str(), std::ios_base::binary | std::ios_base::out);
else
os.open((m_dest_path / p).c_str(), std::ios_base::out);
os.write(&*v1.begin(), v1.size());
os.close();
}
else if(m_namespace_name.size() && m_lib_names.size() && is_jam_file(p))
{
static std::vector<char> v1, v2;
v1.clear();
v2.clear();
std::ifstream is((m_boost_path / p).c_str());
std::copy(std::istreambuf_iterator<char>(is), std::istreambuf_iterator<char>(), std::back_inserter(v1));
static boost::regex libname_matcher;
if(libname_matcher.empty())
{
std::string re = "\\<";
re += *m_lib_names.begin();
for(std::set<std::string>::const_iterator i = ++m_lib_names.begin(); i != m_lib_names.end(); ++i)
{
re += "|" + *i;
}
re += "\\>";
libname_matcher.assign(re);
}
regex_replace(std::back_inserter(v2), v1.begin(), v1.end(), libname_matcher, get_new_library_name(m_namespace_name));
std::swap(v1, v2);
v2.clear();
std::ofstream os;
if(m_unix_lines)
os.open((m_dest_path / p).c_str(), std::ios_base::binary | std::ios_base::out);
else
os.open((m_dest_path / p).c_str(), std::ios_base::out);
os.write(&*v1.begin(), v1.size());
os.close();
}
else if(m_namespace_name.size() && is_source_file(p))
{
//
// v1 hold the current content, v2 is temp buffer.
// Each time we do a search and replace the new content
// ends up in v2: we then swap v1 and v2, and clear v2.
//
static std::vector<char> v1, v2;
v1.clear();
v2.clear();
std::ifstream is((m_boost_path / p).c_str());
std::copy(std::istreambuf_iterator<char>(is), std::istreambuf_iterator<char>(), std::back_inserter(v1));
static const boost::regex namespace_matcher(
"(?|"
"(namespace\\s+)boost(_\\w+)?(?:(\\s*::\\s*)phoenix)?"
"|"
"(namespace\\s+)(adstl|phoenix|rapidxml)\\>"
"|"
"()\\<boost((?:_(?!intrusive_tags)\\w+)?\\s*(?:::))(?:(\\s*)phoenix)?"
"|"
"()\\<((?:adstl|phoenix|rapidxml)\\s*(?:::))"
"|"
"(namespace\\s+\\w+\\s*=\\s*(?:::\\s*)?)boost(_\\w+)?(?:(\\s*::\\s*)phoenix)?"
//.........这里部分代码省略.........