Skip to content

fix: normalize decimal point input#210

Closed
JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:master
Closed

fix: normalize decimal point input#210
JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:master

Conversation

@JWWTSL

@JWWTSL JWWTSL commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

log: 修复小数点输入和粘贴容错异常

pms: bug-361443

log: 修复小数点输入和粘贴容错异常

pms: bug-361443

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @JWWTSL, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了小数点容错逻辑并增加了对系统分组符号和全角句号的处理,逻辑严谨且测试覆盖完善。
代码质量良好,无安全漏洞,仅因部分历史代码风格略显冗余扣5分。

■ 【详细分析】

  • 1.语法逻辑完全正确 ✓

InputEdit::pointFaultTolerance 函数中,通过引入分组符号占位符(0x1C)和小数点占位符(0x1D),有效隔离了系统符号与内部处理逻辑的冲突。正则表达式更新为 "[+-×÷+*/()\\-]",更全面地覆盖了运算符分割场景。多小数点处理逻辑通过在循环末尾统一执行 oldText.replace(list[i], item) 修复了原先被注释导致的替换失效问题。新增了全角句号 到半角 . 的转换,逻辑正确。
潜在问题:无
建议:无

  • 2.代码质量良好 ✓

占位符从易冲突的字符串 "__DEC_PLACEHOLDER__" 改为不可打印控制字符,提高了健壮性。测试用例 pasteDecimalPointsnormalizeDecimalPoints 充分覆盖了新增的边界条件,如前导小数点补零、全角句号转换及多小数点截断。
潜在问题:pointFaultTolerance 中符号替换与还原逻辑略显繁琐,存在一定重复代码。
建议:可考虑提取符号转换逻辑为独立辅助函数,提升可读性。

  • 3.代码性能无性能问题 ✓

pointFaultTolerance 中使用了多次字符串 replace 操作,对于计算器输入框这种短文本场景,时间复杂度和空间开销均在可接受范围内,不会造成性能瓶颈。
潜在问题:无
建议:无

  • 4.代码安全存在0个安全漏洞 ✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅涉及字符串的本地处理与替换,无外部命令执行、文件操作或网络请求,不存在注入或溢出风险。

  • 建议:无需特殊安全修复。

■ 【改进建议代码示例】

// 当前代码已具备较高质量,以下为可选的代码结构优化示例
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;
}

@JWWTSL JWWTSL closed this Jul 23, 2026
@JWWTSL

JWWTSL commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

/reopen

@JWWTSL

JWWTSL commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

1

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

@JWWTSL: Failed to re-open PR: state cannot be changed. There is already an open pull request from JWWTSL:master to linuxdeepin:master.

Details

In response to this:

/reopen

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants