[TD]trap bad format spec
- bad format spec can break QString::asprintf
This commit is contained in:
@@ -320,12 +320,26 @@ QString DimensionFormatter::formatValueToSpec(double value, QString formatSpecif
|
||||
formattedValue.replace(QRegularExpression(QStringLiteral("([0-9][0-9]*\\.[0-9]*[1-9])00*$")), QStringLiteral("\\1"));
|
||||
formattedValue.replace(QRegularExpression(QStringLiteral("([0-9][0-9]*)\\.0*$")), QStringLiteral("\\1"));
|
||||
} else {
|
||||
formattedValue = QString::asprintf(Base::Tools::toStdString(formatSpecifier).c_str(), value);
|
||||
if (isNumericFormat(formatSpecifier)) {
|
||||
formattedValue = QString::asprintf(Base::Tools::toStdString(formatSpecifier).c_str(), value);
|
||||
}
|
||||
}
|
||||
|
||||
return formattedValue;
|
||||
}
|
||||
|
||||
bool DimensionFormatter::isNumericFormat(QString formatSpecifier)
|
||||
{
|
||||
QRegularExpression rxFormat(QStringLiteral("%[+-]?[0-9]*\\.*[0-9]*[aefgwAEFGW]")); //printf double format spec
|
||||
QRegularExpressionMatch rxMatch;
|
||||
int pos = formatSpecifier.indexOf(rxFormat, 0, &rxMatch);
|
||||
if (pos != -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO: similiar code here and above
|
||||
QStringList DimensionFormatter::getPrefixSuffixSpec(QString fSpec)
|
||||
{
|
||||
QStringList result;
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
std::string getDefaultFormatSpec(bool isToleranceFormat) const;
|
||||
bool isTooSmall(double value, QString formatSpec);
|
||||
QString formatValueToSpec(double value, QString formatSpecifier);
|
||||
bool isNumericFormat(QString formatSpecifier);
|
||||
|
||||
private:
|
||||
DrawViewDimension* m_dimension;
|
||||
|
||||
Reference in New Issue
Block a user