而且我剛纔的問題正則表達式: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("<([^>]+)>:([^<]*)\\n", std::regex_constants::ECMAScript | std::regex_constants::optimize);
std::ifstream inFile(szFileName);
inFile.exceptions(std::ifstream::badbit);
std::string szFileData((std::istreambuf_iterator<char>(inFile)), (std::istreambuf_iterator<char>()));
inFile.close();
std::vector<std::future<void>> 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();
}
}
然而,在一個堆棧溢出這個文件會導致加載它(參數:00000001,0x00332FE4) :
=== OBJECT2 ===
<Name>:Test Manufacturer
<Supplier>:Test Supplier
<Address>:Test Multiline
Contact
Address
<Email>:[email protected]
<Telephone Number>:
=== END OBJECT2 ===
=== OBJECT1 ===
<Number>:1
<Name>:Test
<Location>:Here
<Manufacturer>:
<Model Number>:12345
<Serial Number>:54321
<Owner>:Me
<IP Address>:0.0.0.0
=== END OBJECT1 ===
我一直無法找到堆棧溢出的來源,但它看起來像外std::sregex_iterator
循環負責。
在此先感謝!
編譯器和操作系統? –
編譯器:MSVC 2012更新3,操作系統:Windows 7 x64 –
一些類似的問題:http://stackoverflow.com/questions/15696435/c-11-regex-stack-overflow-vs2012和http://stackoverflow.com/ question/12828079/why-does-stdregex-iterator-cause-a-stack-overflow-with-this-data –