fix(storage): compare size by raw bytes instead of localized float - #715
Conversation
Extract raw byte count before brackets for accurate comparison across locales with different thousand separators (comma/dot). 提取方括号前的原始字节数进行比较,解决不同locale下千分位 分隔符(逗号/点)导致的大小比较错误。 Log: 修复存储设备大小比较在非中文locale下出错的问题 PMS: 371721 Influence: 存储设备大小比较逻辑,影响smartctl解析的设备容量显示
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts storage size comparison to extract and compare raw byte counts from localized strings, avoiding float parsing and locale-dependent thousand separators. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 建议使用 QRegularExpression 替代 QRegExp 以兼容 Qt6
// 提取原始字节数(方括号前的数字,千分位逗号/点)比较
// zh_CN: "Total NVM Capacity: 1,024,209,543,168 [1.02 TB]"
// de_DE: "Total NVM Capacity: 1.024.209.543.168 [1,02 TB]"
// 格式2: "Total NVM Capacity: 240,057,409,536 bytes [240 GB]"
auto extractBytes = [](const QString &str) -> quint64 {
QRegularExpression reg("(\\d[\\d,.]*)\\s*(?:bytes\\s*)?\\[");
QRegularExpressionMatch match = reg.match(str);
if (match.hasMatch()) {
QString raw = match.captured(1);
raw.remove(",");
raw.remove(".");
return raw.toULongLong();
}
return 0;
};
quint64 bytes1 = extractBytes(size1);
quint64 bytes2 = extractBytes(size2);
// 返回较大值
if (bytes1 > bytes2)
return size1;
else
return size2; |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- When
extractBytesfails to find a match it returns 0, which can silently change comparison behavior; consider falling back to the original float-in-brackets logic or the original strings in that case instead of treating them as 0. - The regex
(\d[\d,.]*)\s*(?:bytes\s*)?\[is quite permissive and may match unintended numbers if the line format changes; consider anchoring it more tightly to the expectedTotal NVM Capacity/bytespatterns or at least limiting it to the last numeric block before the bracket.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When `extractBytes` fails to find a match it returns 0, which can silently change comparison behavior; consider falling back to the original float-in-brackets logic or the original strings in that case instead of treating them as 0.
- The regex `(\d[\d,.]*)\s*(?:bytes\s*)?\[` is quite permissive and may match unintended numbers if the line format changes; consider anchoring it more tightly to the expected `Total NVM Capacity`/`bytes` patterns or at least limiting it to the last numeric block before the bracket.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind 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 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
a9a1cfa
into
linuxdeepin:develop/eagle
Extract raw byte count before brackets for accurate comparison across locales with different thousand separators (comma/dot).
提取方括号前的原始字节数进行比较,解决不同locale下千分位
分隔符(逗号/点)导致的大小比较错误。
Log: 修复存储设备大小比较在非中文locale下出错的问题
PMS: 371721
Influence: 存储设备大小比较逻辑,影响smartctl解析的设备容量显示
Summary by Sourcery
Bug Fixes: