75
testHasttable/regexextract.cpp
Normal file
75
testHasttable/regexextract.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "regexextract.h"
|
||||
#include <iostream>
|
||||
RegexExtract::RegexExtract()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RegexExtract::endsWith(const QString& line,const QString& eleName)
|
||||
{
|
||||
QString t=line.trimmed();
|
||||
return t.startsWith(QString("</cim:")+eleName+QString(">"));
|
||||
|
||||
}
|
||||
|
||||
void RegexExtract::exportBlocks(const QString& path)
|
||||
{
|
||||
QFile file(path);
|
||||
std::cout<<"writing..."<<std::endl;
|
||||
if(file.open(QFile::WriteOnly))
|
||||
{
|
||||
QTextStream writer(&file);
|
||||
for(QStringList::iterator ite=this->blocks.begin();
|
||||
ite!=this->blocks.end();
|
||||
ite++)
|
||||
{
|
||||
writer<<*ite;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
bool RegexExtract::extract(const QString& xmlPath)
|
||||
{
|
||||
QFile file(xmlPath);
|
||||
QString line;
|
||||
QString block;
|
||||
bool isInner=false;
|
||||
if(file.open(QFile::ReadOnly))
|
||||
{
|
||||
QTextStream reader(&file);
|
||||
while(!reader.atEnd())
|
||||
{
|
||||
line=reader.readLine();
|
||||
// std::cout<<line.toStdString()<<std::endl;
|
||||
if(!isInner && this->startsWith(line,"ConnectivityNode"))
|
||||
{
|
||||
block="";
|
||||
isInner=true;
|
||||
}
|
||||
if(isInner)
|
||||
{
|
||||
block=block+line+QString("\n");
|
||||
}
|
||||
if(isInner && this->endsWith(line,"ConnectivityNode"))
|
||||
{
|
||||
isInner=false;
|
||||
this->blocks.push_back(block);
|
||||
// std::cout<<block.toStdString()<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RegexExtract::startsWith(const QString& line,const QString& eleName)
|
||||
{
|
||||
QString t=line.trimmed();
|
||||
return t.startsWith(QString("<cim:")+eleName+QString(" "));
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user