Add function UnescapeMenuString

Turns E&dit into Edit and 'd'. Double ampersands are translated to just a single one,
hence the unescaping part of this.

Useful in the Mac port to deal with desktop UI translation strings with included
Windows hotkeys.
This commit is contained in:
Henrik Rydgård 2023-04-23 14:36:34 +02:00
parent 3d7e73a37a
commit 91d4ded3fd
3 changed files with 49 additions and 0 deletions

View file

@ -342,3 +342,27 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st
}
return result;
}
std::string UnescapeMenuString(const char *input, char *shortcutChar) {
size_t len = strlen(input);
std::string output;
output.reserve(len);
bool escaping = false;
for (size_t i = 0; i < len; i++) {
if (input[i] == '&') {
if (escaping) {
output.push_back(input[i]);
escaping = false;
} else {
escaping = true;
}
} else {
output.push_back(input[i]);
if (escaping && shortcutChar) {
*shortcutChar = input[i];
}
escaping = false;
}
}
return output;
}