Skip to content

Conversation

@mhduiy
Copy link
Contributor

@mhduiy mhduiy commented Sep 12, 2025

Added conditional compilation to support both original key name format and camelCase format for dde-daemon v25 compatibility Implemented qtifyName function to convert hyphenated names to camelCase by removing hyphens and capitalizing following letters Added ENABLE_DSS_SNIPE macro check to maintain backward compatibility while supporting new naming convention

feat: 为键名添加驼峰命名转换支持

添加条件编译以同时支持原始键名格式和v25 dde-daemon所需的小驼峰格式
实现qtifyName函数,通过移除连字符并大写后续字母将连字符分隔的名称转换为
驼峰命名添加ENABLE_DSS_SNIPE宏检查,在支持新命名规范的同时保持向后兼容性

pms: BUG-292567

Added conditional compilation to support both original key name format
and camelCase format for dde-daemon v25 compatibility
Implemented qtifyName function to convert hyphenated names to camelCase
by removing hyphens and capitalizing following letters
Added ENABLE_DSS_SNIPE macro check to maintain backward compatibility
while supporting new naming convention

feat: 为键名添加驼峰命名转换支持

添加条件编译以同时支持原始键名格式和v25 dde-daemon所需的小驼峰格式
实现qtifyName函数,通过移除连字符并大写后续字母将连字符分隔的名称转换为
驼峰命名添加ENABLE_DSS_SNIPE宏检查,在支持新命名规范的同时保持向后兼容性

pms: BUG-292567
deepin-ci-robot added a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Sep 12, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#43
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见

总体评价

这段代码实现了一个将带有连字符的命名转换为小驼峰命名的功能,主要用于dde-daemon v25版本兼容性。代码整体结构清晰,但有一些可以改进的地方。

具体分析

1. 代码质量

  • 优点

    • 函数命名清晰(qtifyName),表达了函数的功能
    • 添加了适当的注释说明函数用途
    • 使用了const引用传递参数,避免不必要的拷贝
  • 改进建议

    • 在public_func.h中的函数注释可以更详细,包括参数说明和返回值说明
    • 建议添加边界条件处理(如空字符串输入)
    • 文件末尾缺少换行符(已在diff中显示)

2. 代码逻辑

  • 优点

    • 逻辑简单明了,使用next_cap标志位控制是否需要大写
    • 使用迭代器遍历字符串,效率较高
  • 改进建议

    • 当前实现会将连续的连字符视为一个分隔符,可以考虑显式处理这种情况
    • 可以添加对输入字符串中非法字符的处理(如非字母数字字符)

3. 代码性能

  • 优点

    • 使用const迭代器遍历字符串,避免不必要的拷贝
    • 字符串操作使用append,效率较高
  • 改进建议

    • 对于非常长的字符串,可以考虑预先分配result的内存空间
    • 可以考虑使用QStringRef来提高子字符串操作效率

4. 代码安全

  • 优点

    • 使用const引用传递参数,避免意外修改
    • 函数不会修改输入参数
  • 改进建议

    • 可以添加输入验证,确保只处理有效的字符串格式
    • 考虑添加对Unicode字符的支持,确保国际化兼容性

改进建议代码

/**
 * @brief Convert dash-separated names to camelCase format.
 * @param name Input string with dash-separated format (e.g., "some-key")
 * @return QString in camelCase format (e.g., "someKey")
 * @note If input is empty or contains only dashes, returns empty string
 * @note Consecutive dashes are treated as a single separator
 */
QString qtifyName(const QString &name) {
    if (name.isEmpty()) {
        return QString();
    }

    bool next_cap = false;
    QString result;
    result.reserve(name.size());  // Pre-allocate memory for efficiency
    
    for (auto it = name.cbegin(); it != name.cend(); ++it) {
        if (*it == '-') {
            next_cap = true;
        } else if (next_cap) {
            result.append(it->toUpper());
            next_cap = false;
        } else {
            result.append(*it);
        }
    }
    
    return result;
}

其他建议

  1. 考虑添加单元测试,确保各种边界条件都能正确处理
  2. 可以考虑添加对其他分隔符的支持(如下划线)
  3. 在LockFrame::event中,建议添加对keyValue为空的处理逻辑
  4. 考虑将ENABLE_DSS_SNIPE宏的定义位置和用途在代码中更明确地说明

这些建议可以提高代码的健壮性、可维护性和性能。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, yixinshark

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

@mhduiy mhduiy merged commit 330ee1f into linuxdeepin:master Sep 12, 2025
14 of 15 checks passed
yixinshark pushed a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Sep 18, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#43
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