If there are multiple escapes, pick the first.

This commit is contained in:
Henrik Rydgård 2023-04-23 14:42:36 +02:00
parent 91d4ded3fd
commit 4ed634383f
2 changed files with 6 additions and 1 deletions

View file

@ -348,6 +348,7 @@ std::string UnescapeMenuString(const char *input, char *shortcutChar) {
std::string output;
output.reserve(len);
bool escaping = false;
bool escapeFound = false;
for (size_t i = 0; i < len; i++) {
if (input[i] == '&') {
if (escaping) {
@ -358,8 +359,9 @@ std::string UnescapeMenuString(const char *input, char *shortcutChar) {
}
} else {
output.push_back(input[i]);
if (escaping && shortcutChar) {
if (escaping && shortcutChar && !escapeFound) {
*shortcutChar = input[i];
escapeFound = true;
}
escaping = false;
}

View file

@ -908,6 +908,9 @@ bool TestEscapeMenuString() {
EXPECT_EQ_STR(temp, std::string("Edit"));
temp = UnescapeMenuString("Cut && Paste", nullptr);
EXPECT_EQ_STR(temp, std::string("Cut & Paste"));
temp = UnescapeMenuString("&A&B", &c);
EXPECT_EQ_STR(temp, std::string("AB"));
EXPECT_EQ_INT((int)c, (int)'A');
return true;
}