Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1149)

Side by Side Diff: ui/base/accelerators/menu_label_accelerator_util_linux.cc

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/base/accelerators/menu_label_accelerator_util_linux.h"
6
7 #include "base/strings/string_util.h"
8
9 namespace {
10
11 // Common implementation of ConvertAcceleratorsFromWindowsStyle() and
12 // RemoveWindowsStyleAccelerators().
13 // Replaces all ampersands (as used in our grd files to indicate mnemonics)
14 // to |target|, except ampersands appearing in pairs which are replaced by
15 // a single ampersand. Any underscores get replaced with two underscores as
16 // is needed by GTK.
17 std::string ConvertAmpersandsTo(const std::string& label,
18 const std::string& target) {
19 std::string ret;
20 ret.reserve(label.length() * 2);
21 for (size_t i = 0; i < label.length(); ++i) {
22 if ('_' == label[i]) {
23 ret.push_back('_');
24 ret.push_back('_');
25 } else if ('&' == label[i]) {
26 if (i + 1 < label.length() && '&' == label[i + 1]) {
27 ret.push_back('&');
28 ++i;
29 } else {
30 ret.append(target);
31 }
32 } else {
33 ret.push_back(label[i]);
34 }
35 }
36
37 return ret;
38 }
39
40 } // namespace
41
42 namespace ui {
43
44 std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
45 return ConvertAmpersandsTo(label, "_");
46 }
47
48 std::string RemoveWindowsStyleAccelerators(const std::string& label) {
49 return ConvertAmpersandsTo(label, std::string());
50 }
51
52 // Replaces all ampersands in |label| with two ampersands. This effectively
53 // escapes strings for later processing by ConvertAmpersandsTo(), so that
54 // ConvertAmpersandsTo(EscapeWindowsStyleAccelerators(x), *) is |x| with
55 // underscores doubled, making the string that appears to the user just |x|.
56 std::string EscapeWindowsStyleAccelerators(const std::string& label) {
57 std::string ret;
58 base::ReplaceChars(label, "&", "&&", &ret);
59 return ret;
60 }
61
62 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698