fix: normalize decimal point input#210
Conversation
log: 修复小数点输入和粘贴容错异常 pms: bug-361443
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: JWWTSL The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 当前代码已具备较高质量,以下为可选的代码结构优化示例
QString InputEdit::pointFaultTolerance(const QString &text)
{
const auto sys = Settings::instance();
QString decSym = sys->getSystemDecimalSymbol();
QString grpSym = sys->getSystemDigitGroupingSymbol();
const QString decimalPlaceholder = QString(QChar(0x1D));
const QString groupingPlaceholder = QString(QChar(0x1C));
QString workingText = text;
// 统一符号转换
if (!grpSym.isEmpty() && grpSym != QLatin1String(","))
workingText.replace(grpSym, groupingPlaceholder);
if (!decSym.isEmpty() && decSym != QLatin1String("."))
workingText.replace(decSym, decimalPlaceholder);
workingText.replace(groupingPlaceholder, ",");
workingText.replace(decimalPlaceholder, ".");
workingText.replace(QString::fromUtf8("。"), ".");
QString exp = workingText;
QString oldText = workingText;
QStringList list = exp.split(QRegularExpression("[+-×÷+*/()\\-]"));
for (int i = 0; i < list.size(); ++i) {
QString item = list[i];
int firstPoint = item.indexOf(".");
if (firstPoint == -1)
continue;
if (firstPoint == 0) {
item.insert(firstPoint, "0");
++firstPoint;
} else {
if (item.at(firstPoint - 1) == QChar(')') || item.at(firstPoint - 1) == QChar('%')) {
item.remove(firstPoint, 1);
}
}
if (item.count(".") > 1) {
int cur = cursorPosition();
item.remove(".");
item.insert(firstPoint, ".");
setCursorPosition(cur);
}
if (item != list[i])
oldText.replace(list[i], item);
}
QString result = oldText;
// 统一符号还原
if (!grpSym.isEmpty() && grpSym != QLatin1String(","))
result.replace(",", groupingPlaceholder);
if (!decSym.isEmpty() && decSym != QLatin1String("."))
result.replace(".", decimalPlaceholder);
if (!grpSym.isEmpty() && grpSym != QLatin1String(","))
result.replace(groupingPlaceholder, grpSym);
if (!decSym.isEmpty() && decSym != QLatin1String("."))
result.replace(decimalPlaceholder, decSym);
return result;
} |
|
/reopen |
|
1 |
|
@JWWTSL: Failed to re-open PR: state cannot be changed. There is already an open pull request from JWWTSL:master to linuxdeepin:master. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
log: 修复小数点输入和粘贴容错异常
pms: bug-361443