继上一个问题:
ECMAScript Regex for a multilined string之后,我实现了以下加载过程:
void Load( const std::string& szFileName )
{
static const std::regex regexObject( "=== ([^=]+) ===\\n((?:.|\\n)*)\\n=== END \\1 ===", std::regex_constants::ECMAScript | std::regex_constants::optimize );
static const std::regex regexData( "]+)>:([^
std::ifstream inFile( szFileName );
inFile.exceptions( std::ifstream::badbit );
std::string szFileData( (std::istreambuf_iterator(inFile)), (std::istreambuf_iterator()) );
inFile.close();
std::vector<:future>> vecFutures;
for( std::sregex_iterator itObject( szFileData.cbegin(), szFileData.cend(), regexObject ), end; itObject != end; ++itObject )
{
if( (*itObject)[1] == "OBJECT1" )
{
vecFutures.emplace_back( std::async( []( std::string szDataString ) {
for( std::sregex_iterator itData( szDataString.cbegin(), szDataString.cend(), regexData ) { // Do Stuff }
}, (*itObject)[2].str() ) );
}
else if( (*itObject)[1] == "OBJECT2" )
{
vecFutures.emplace_back( std::async( []( std::string szDataString ) {
for( std::sregex_iterator itData( szDataString.cbegin(), szDataString.cend(), regexData ) { // Do Stuff }
}, (*itObject)[2].str() ) );
}
}
for( auto& future : vecFutures )
{
future.get();
}
}
但是,使用此文件加载会导致堆栈溢出(参数:0x00000001,0x00332FE4):
=== OBJECT2 ===
:Test Manufacturer
:Test Supplier
:Test MultilineContact
Address
:test@test.co.uk
:0123456789
=== END OBJECT2 ===
=== OBJECT1 ===
:1
:Test
:Here
:
:12345
:54321
:Me
:0.0.0.0
=== END OBJECT1 ===
我一直无法找到Stack Overflow的源代码,但看起来外部的std :: sregex_iterator循环负责.
提前致谢!