KShare/src/formatter.cpp

18 lines
597 B
C++
Raw Normal View History

2017-04-23 20:29:24 +02:00
#include "formatter.hpp"
#include <QDateTime>
#include <QStringList>
QString formatter::format(QString toFormat, QString ext) {
QRegExp dateRegex("%\\((.+)\\)date");
dateRegex.indexIn(toFormat);
QStringList capturedTexts(dateRegex.capturedTexts());
QString formatted(toFormat);
QDateTime date = QDateTime::currentDateTime();
for (int i = 0; i < capturedTexts.length(); i += 2) {
formatted = formatted.replace(capturedTexts.at(i), date.toString(capturedTexts.at(i + 1)));
}
formatted = formatted.replace(QRegExp("%(?!%)ext"), ext);
return formatted;
2017-04-23 20:29:24 +02:00
}