Code refactor, make use of benchmarks

This commit is contained in:
Debao Zhang
2014-03-12 15:38:21 +08:00
parent 36c42eb39b
commit 1b554d4fea
7 changed files with 133 additions and 9 deletions
+2 -7
View File
@@ -31,7 +31,6 @@
#include <QXmlStreamReader>
#include <QDir>
#include <QFile>
#include <QRegularExpression>
#include <QDebug>
#include <QBuffer>
@@ -217,10 +216,8 @@ void SharedStrings::saveToXmlFile(QIODevice *device) const
writer.writeEndElement();// rPr
}
writer.writeStartElement(QStringLiteral("t"));
if (string.fragmentText(i).contains(QRegularExpression(QStringLiteral("^\\s")))
|| string.fragmentText(i).contains(QRegularExpression(QStringLiteral("\\s$")))) {
if (isSpaceReserveNeeded(string.fragmentText(i)))
writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
}
writer.writeCharacters(string.fragmentText(i));
writer.writeEndElement();// t
@@ -229,10 +226,8 @@ void SharedStrings::saveToXmlFile(QIODevice *device) const
} else {
writer.writeStartElement(QStringLiteral("t"));
QString pString = string.toPlainString();
if (pString.contains(QRegularExpression(QStringLiteral("^\\s")))
|| pString.contains(QRegularExpression(QStringLiteral("\\s$")))) {
if (isSpaceReserveNeeded(pString))
writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
}
writer.writeCharacters(pString);
writer.writeEndElement();//t
}
+8
View File
@@ -202,5 +202,13 @@ QString createSafeSheetName(const QString &nameProposal)
return ret;
}
/*
* whether the string s starts or ends with space
*/
bool isSpaceReserveNeeded(const QString &s)
{
QString spaces(QStringLiteral(" \t\n\r"));
return !s.isEmpty() && (spaces.contains(s.at(0))||spaces.contains(s.at(s.length()-1)));
}
} //namespace QXlsx
+1
View File
@@ -61,6 +61,7 @@ XLSX_AUTOTEST_EXPORT QString xl_rowcol_to_cell(int row, int col, bool row_abs=fa
XLSX_AUTOTEST_EXPORT QString xl_rowcol_to_cell_fast(int row, int col);
XLSX_AUTOTEST_EXPORT QString createSafeSheetName(const QString &nameProposal);
XLSX_AUTOTEST_EXPORT bool isSpaceReserveNeeded(const QString &string);
} //QXlsx
#endif // XLSXUTILITY_H
+8 -2
View File
@@ -1369,13 +1369,19 @@ void WorksheetPrivate::saveXmlCellData(QXmlStreamWriter &writer, int row, int co
writer.writeEndElement();// rPr
}
writer.writeStartElement(QStringLiteral("t"));
writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
if (isSpaceReserveNeeded(string.fragmentText(i)))
writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
writer.writeCharacters(string.fragmentText(i));
writer.writeEndElement();// t
writer.writeEndElement(); // r
}
} else {
writer.writeTextElement(QStringLiteral("t"), cell->value().toString());
writer.writeStartElement(QStringLiteral("t"));
QString string = cell->value().toString();
if (isSpaceReserveNeeded(string))
writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
writer.writeCharacters(string);
writer.writeEndElement(); // t
}
writer.writeEndElement();//is
} else if (cell->dataType() == Cell::Numeric){