summaryrefslogtreecommitdiffstats
path: root/chromium/ui/gfx/text_utils.cc
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
committerZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
commit679147eead574d186ebf3069647b4c23e8ccace6 (patch)
treefc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/ui/gfx/text_utils.cc
Initial import.
Diffstat (limited to 'chromium/ui/gfx/text_utils.cc')
-rw-r--r--chromium/ui/gfx/text_utils.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/chromium/ui/gfx/text_utils.cc b/chromium/ui/gfx/text_utils.cc
new file mode 100644
index 00000000000..a31ef3d3cc9
--- /dev/null
+++ b/chromium/ui/gfx/text_utils.cc
@@ -0,0 +1,49 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/text_utils.h"
+
+#include "base/i18n/char_iterator.h"
+
+namespace gfx {
+
+base::string16 RemoveAcceleratorChar(const base::string16& s,
+ base::char16 accelerator_char,
+ int* accelerated_char_pos,
+ int* accelerated_char_span) {
+ bool escaped = false;
+ ptrdiff_t last_char_pos = -1;
+ int last_char_span = 0;
+ base::i18n::UTF16CharIterator chars(&s);
+ base::string16 accelerator_removed;
+
+ accelerator_removed.reserve(s.size());
+ while (!chars.end()) {
+ int32 c = chars.get();
+ int array_pos = chars.array_pos();
+ chars.Advance();
+
+ if (c != accelerator_char || escaped) {
+ int span = chars.array_pos() - array_pos;
+ if (escaped && c != accelerator_char) {
+ last_char_pos = accelerator_removed.size();
+ last_char_span = span;
+ }
+ for (int i = 0; i < span; i++)
+ accelerator_removed.push_back(s[array_pos + i]);
+ escaped = false;
+ } else {
+ escaped = true;
+ }
+ }
+
+ if (accelerated_char_pos)
+ *accelerated_char_pos = last_char_pos;
+ if (accelerated_char_span)
+ *accelerated_char_span = last_char_span;
+
+ return accelerator_removed;
+}
+
+} // namespace gfx