regex_search匹配全部
#include
<iostream> #include <cassert>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <fstream>
#include "boost/regex.hpp"
//".*[\u4e00-\u9fa5]+.*"
int main() {
while (true)
{
std::cout << "Enter a filename: \n";
std::string s; std::getline(std::cin, s);
if (s.compare("exit") == 0)
{
break;
}
std::ifstream fin(s.c_str());
if(!fin.is_open())
return false;
s = s + ".xml";
std::ofstream fou(s.c_str());
if(!fin.is_open())
return false;
int nCount = 1;
std::vector<std::string> strvect;
fou << "<config name=\"SDErrCode\">" << std::endl;
while(!fin.eof())
{
std::string inbuf;
getline(fin, inbuf,'\n');
strvect.push_back(inbuf);
try {
boost::regex reg("\".*[\u4e00-\u9fa5]+.*\"");
boost::smatch what;
std::string::const_iterator start = inbuf.begin();
std::string::const_iterator end = inbuf.end();
if(boost::regex_search(start,end, what, reg))
{
for(int i=0;i< what.size();i++)
{
fou << "\t<error name = \"\"\t\t" << "value=\"" << nCount++ << "\" " << "desc="<< what[i].str() << " />" << std::endl;
}
}
}
catch(const boost::bad_expression& e)
{
std::cout << "That's not a valid regular expression! (Error: " << e.what() << ") Exiting...\n";
}
}
fou << "</config>" << std::endl;
}
getchar();
return 0;
}