This source file includes following definitions.
- ConvertAmpersandsTo
- ConvertAcceleratorsFromWindowsStyle
- RemoveWindowsStyleAccelerators
- EscapeWindowsStyleAccelerators
#include "ui/base/accelerators/menu_label_accelerator_util_linux.h"
#include "base/strings/string_util.h"
namespace {
std::string ConvertAmpersandsTo(const std::string& label,
const std::string& target) {
std::string ret;
ret.reserve(label.length() * 2);
for (size_t i = 0; i < label.length(); ++i) {
if ('_' == label[i]) {
ret.push_back('_');
ret.push_back('_');
} else if ('&' == label[i]) {
if (i + 1 < label.length() && '&' == label[i + 1]) {
ret.push_back('&');
++i;
} else {
ret.append(target);
}
} else {
ret.push_back(label[i]);
}
}
return ret;
}
}
namespace ui {
std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
return ConvertAmpersandsTo(label, "_");
}
std::string RemoveWindowsStyleAccelerators(const std::string& label) {
return ConvertAmpersandsTo(label, std::string());
}
std::string EscapeWindowsStyleAccelerators(const std::string& label) {
std::string ret;
base::ReplaceChars(label, "&", "&&", &ret);
return ret;
}
}