Added method to extract indent and eol

This commit is contained in:
Vladimir
2013-03-13 21:12:50 +06:00
parent f8884461ac
commit faaef3fc29
3 changed files with 44 additions and 12 deletions

View File

@@ -79,7 +79,10 @@ QString Parser::convert(IDocument *document, Tags &tags) const
}
tags.setTagValue(Tags::TemplateFilename, file.fileName());
tags.setTagValue(Tags::OutputDataIndent, this->imageIndent(templateString));
QString prefix, suffix;
this->imageParticles(templateString, &prefix, &suffix);
tags.setTagValue(Tags::OutputDataIndent, prefix);
tags.setTagValue(Tags::OutputDataEOL, suffix);
this->addMatrixInfo(tags);
@@ -422,21 +425,49 @@ void Parser::addImagesInfo(Tags &tags, IDocument *doc) const
tags.setTagValue(Tags::OutputImagesMaxHeight, QString("%1").arg(maxHeight));
}
//-----------------------------------------------------------------------------
QString Parser::imageIndent(const QString &templateString) const
void Parser::imageParticles(const QString &templateString, QString *prefix, QString *suffix) const
{
QRegExp regIndent = QRegExp("([\\t\\ ]+)(\\@|\\$\\()imageData(\\@|\\))");
regIndent.setMinimal(true);
if (regIndent.indexIn(templateString) >= 0)
{
QString result = regIndent.cap(1);
if (result.isEmpty())
result = " ";
QString templateOutImageData;
return result;
// extract 'out_image_data' line
QRegExp regOutImageData = QRegExp("[^\\n\\r]*out_image_data[^\\n\\r]*[\\n\\r]*");
if (regOutImageData.indexIn(templateString) >= 0)
{
templateOutImageData = regOutImageData.cap();
}
else
{
return " ";
regOutImageData.setPattern("[^\\n\\r]*imageData[^\\n\\r]*[\\n\\r]*");
if (regOutImageData.indexIn(templateString) >= 0)
{
templateOutImageData = regOutImageData.cap();
}
}
*prefix = QString(" ");
*suffix = QString("\r\n");
if (!templateOutImageData.isEmpty())
{
QRegExp regIndent = QRegExp("^[\\t\\ ]*");
if (regIndent.indexIn(templateOutImageData) >= 0)
{
QString result = regIndent.cap();
if (!result.isEmpty())
{
*prefix = result;
}
}
QRegExp regEOL = QRegExp("[\\r\\n]*$");
if (regEOL.indexIn(templateOutImageData) >= 0)
{
QString result = regEOL.cap();
if (!result.isEmpty())
{
*suffix = result;
}
}
}
}
//-----------------------------------------------------------------------------