Skip to content

Conversation

@liyigang1
Copy link
Contributor

检出排序的算法到1071上

- Refactor compareByStringEx to improve natural sorting, including better handling of numbers, letters, Han characters, and symbols.
- Add isFullWidthChar to normalize full-width characters for accurate comparison.
- Improve numberStr to extract numeric substrings with normalization.
- Remove unused parameters from compareByStringEx and update all call sites.
- Enhance robustness and accuracy of file name sorting, especially for mixed character types and full-width characters.

Log: enhance string comparison and sorting for file names
1. Removed the previous file extension splitting logic in
DLocalHelper::compareByStringEx that caused incorrect sorting
2. Added a new public method DFMUtils::compareFileName to expose the
corrected comparison function
3. Now comparing full strings without separating names and extensions
4. Also fixed URL handling to use toLocal8Bit() instead of toStdString()
for better compatibility

The change was necessary because:
1. The old implementation incorrectly sorted files by splitting names
and extensions
2. The new approach provides more accurate natural sorting by comparing
entire strings
3. Makes the functionality available as a public API for broader use
4. Improves compatibility with various file name encodings

Bug: https://pms.uniontech.com/bug-view-335751.html

fix: 修正文件名比较逻辑

1. 移除 DLocalHelper::compareByStringEx 中导致排序错误的扩展名分割逻辑
2. 新增公共方法 DFMUtils::compareFileName 提供正确的比较功能
3. 现在直接比较完整字符串而不分割名称和扩展名
4. 同时将 URL 处理改为使用 toLocal8Bit() 提高兼容性

修改原因:
1. 旧实现在分割文件名和扩展名时排序不正确
2. 新方法通过比较完整字符串提供更准确的自然排序
3. 将该功能作为公共 API 开放以方便其他模块使用
4. 提高对各种文件名编码的兼容性
Johnson-zs
Johnson-zs previously approved these changes Dec 24, 2025
Apply QUrl::fromPercentEncoding to g_file_get_uri result before using it
as a key to look up delete information, ensuring proper handling of
URL-encoded file URIs in trash operations.

Log: decode URL-encoded URIs in TrashHelper::getTrashUrls
Bug: https://pms.uniontech.com/bug-view-336357.html
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: liyigang1

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

1 similar comment
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: liyigang1

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

deepin pr auto review

我来对这个 diff 进行详细的代码审查:

  1. 语法逻辑:
  • 代码整体语法正确,没有明显的语法错误
  • 新增的 compareFileName 函数实现合理
  • 对全角字符的处理逻辑完整
  1. 代码质量:
  • 添加了 isFullWidthChar 函数来处理全角字符转换,提高了代码的可维护性
  • 使用了 QHash 来存储标点符号映射,查找效率高
  • compareByStringEx 函数重构后使用了更清晰的枚举类型来定义字符分类
  • 使用了 lambda 表达式来封装比较逻辑,提高了代码的可读性
  • 添加了适当的注释来解释关键逻辑
  1. 性能优化:
  • 使用 thread_local static DCollator 避免了多线程问题
  • 使用 QHash 进行标点符号映射,查找效率为 O(1)
  • 优化了数字字符串的处理逻辑,减少了不必要的字符串操作
  • 使用迭代器进行字符串遍历,效率更高
  1. 安全性改进:
  • 修复了 URL 编码问题,使用 QUrl::fromPercentEncoding
  • 改进了文件路径处理,使用 toUtf8() 替代 toStdString().c_str()
  • 正确处理了代理对字符,避免了潜在的内存访问问题
  1. 建议改进:
  • 在 numberStr 函数中,可以考虑添加对超大数字的处理,避免整数溢出
  • isFullWidthChar 中的 QHash 可以考虑使用静态初始化,避免每次调用都重新创建
  • 可以考虑添加单元测试来验证全角字符转换的正确性
  • compareByStringEx 函数中的数字比较逻辑可以进一步优化,避免重复的字符串转换
  1. 其他建议:
  • 考虑添加更多的错误处理机制
  • 可以考虑添加更多的文档注释,特别是对于复杂的比较逻辑
  • 建议添加一些边界条件的测试用例

总体来说,这次改动提高了代码的质量和性能,特别是在处理全角字符和文件名比较方面。代码结构更加清晰,维护性更好。建议在后续开发中重点关注边界条件的处理和测试覆盖。

@liyigang1
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Dec 24, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 4ecb946 into linuxdeepin:release/eagle Dec 24, 2025
20 checks passed
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.

3 participants