从资源文件生成快捷方式列表(由包含 & 符号的按钮标题表示)

发布于 2024-12-28 18:33:16 字数 408 浏览 2 评论 0原文

我有一个包含 429 个 MFC 资源文件的列表,我必须为其生成快捷方式列表,其中包含与符号的按钮(例如按钮“&Close”),指示 ALT-C 是关闭该特定对话框的快捷方式。

问题是资源文件包含许多不同格式的对话框:

IDD_VIDEO DIALOG  0, 0, 471, 187
...
BEGIN
    ...
    PUSHBUTTON      "&Close",IDC_CLOSE,89,166,53,14
    ...
END

我想要提取的格式将是“&Close”(或理想情况下“ALT-C &Close”)和其他带有快捷方式的标签的列表,按它们所在的对话框进行分区(例如 IDD_VIDEO)。正则表达式似乎是最好的解决方案,但我还没有找到一个有效的正则表达式。

I have a list of 429 MFC resource files that I have to generate a list of shortcuts for, which would be buttons containing an ampersand symbol (e.g. BUTTON "&Close") indicating that ALT-C is the shortcut for closing that particular dialog.

The problem is that the resource files contain many different dialogs formatted as such:

IDD_VIDEO DIALOG  0, 0, 471, 187
...
BEGIN
    ...
    PUSHBUTTON      "&Close",IDC_CLOSE,89,166,53,14
    ...
END

The format I would like to pull out would be a list of "&Close" (Or ideally "ALT-C &Close") and other labels with shortcuts, sectioned by which dialog they're under (e.g. IDD_VIDEO). Regex seems like the best solution but I haven't been able to figure a working regex out for this yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謌踐踏愛綪 2025-01-04 18:33:16

感谢您添加的规格。这应该有效:

^                  # Start of line
(IDD_\w+)          # Alphanumeric identifier, starting with IDD_
\s+DIALOG\b        # followed by "DIALOG"
((?:(?!^END\b).)*) # and any number of characters unless there's an END in-between

这将匹配从 IDD_whatever 到下一个 END 的整个部分。然后,您需要获取该字符串并对其应用以下正则表达式:

"([^"]*&[^"]*)"  # String containing at least one &

这是一个 C# 示例:

Regex sectionRegex = new Regex(
    @"^                 # Start of line
    (IDD_\w+)           # Alphanumeric identifier, starting with IDD_
    \s+DIALOG\b         # followed by ""DIALOG""
    ((?:(?!^END\b).)*)  # and any number of characters unless there's an END in-between",
    RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);

Regex altCRegex = new Regex(
    @"""([^""]*&[^""]*)"" # String containing at least one &", 
    RegexOptions.IgnorePatternWhitespace);

Match matchResults = sectionRegex.Match(subjectString);
while (matchResults.Success) {
    identifier = matchResults.Groups[1].Value;
    section = matchResults.Groups[2].Value;
    Match sectionResults = altCRegex.Match(section);
    while (sectionResults.Success) {
        altCString = sectionResult.Groups[1].Value;
        sectionResults = sectionResults.NextMatch();
    }
    matchResults = matchResults.NextMatch();
} 

当然,此代码片段不会对 identifieraltCString 执行任何操作,但是我想你明白了。

Thanks for the added specifications. This should work:

^                  # Start of line
(IDD_\w+)          # Alphanumeric identifier, starting with IDD_
\s+DIALOG\b        # followed by "DIALOG"
((?:(?!^END\b).)*) # and any number of characters unless there's an END in-between

This will match the entire section from IDD_whatever until the next END. Then you need to take that string and apply the following regex to it:

"([^"]*&[^"]*)"  # String containing at least one &

Here's a C# example:

Regex sectionRegex = new Regex(
    @"^                 # Start of line
    (IDD_\w+)           # Alphanumeric identifier, starting with IDD_
    \s+DIALOG\b         # followed by ""DIALOG""
    ((?:(?!^END\b).)*)  # and any number of characters unless there's an END in-between",
    RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);

Regex altCRegex = new Regex(
    @"""([^""]*&[^""]*)"" # String containing at least one &", 
    RegexOptions.IgnorePatternWhitespace);

Match matchResults = sectionRegex.Match(subjectString);
while (matchResults.Success) {
    identifier = matchResults.Groups[1].Value;
    section = matchResults.Groups[2].Value;
    Match sectionResults = altCRegex.Match(section);
    while (sectionResults.Success) {
        altCString = sectionResult.Groups[1].Value;
        sectionResults = sectionResults.NextMatch();
    }
    matchResults = matchResults.NextMatch();
} 

Of course this code snippet doesn't do anything with identifier and altCString, but I think you get the idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文