mirror of
https://github.com/riuson/lcd-image-converter.git
synced 2026-03-09 09:37:05 +01:00
Added method to extract indent and eol
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user