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

Side by Side Diff: ui/gfx/text_utils.cc

Issue 1070223004: Stop combining text runs which are connected by 'COMMON' blocks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address msw@'s comments. Created 5 years, 6 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
« ui/gfx/text_utils.h ('K') | « ui/gfx/text_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/text_utils.h" 5 #include "ui/gfx/text_utils.h"
6 6
7 #include "base/i18n/char_iterator.h" 7 #include "base/i18n/char_iterator.h"
8 #include "base/logging.h"
9 #include "third_party/icu/source/common/unicode/uchar.h"
10 #include "third_party/icu/source/common/unicode/utf16.h"
8 11
9 namespace gfx { 12 namespace gfx {
10 13
14 namespace {
15
16 // Returns true if the code point |c| is a combining mark character in Unicode.
17 bool CharIsMark(UChar32 c) {
18 int8_t char_type = u_charType(c);
19 return char_type == U_NON_SPACING_MARK || char_type == U_ENCLOSING_MARK ||
20 char_type == U_COMBINING_SPACING_MARK;
21 }
22
23 // Gets the code point of |str| at the given code unit position |index|. If
24 // |index| is a surrogate code unit, returns the whole code point (unless the
25 // code unit is unpaired, in which case it just returns the surrogate value).
26 UChar32 GetCodePointAt(const base::string16& str, size_t index) {
27 UChar32 c;
28 U16_GET(str.data(), 0, index, str.size(), c);
29 return c;
30 }
31
32 } // namespace
33
11 base::string16 RemoveAcceleratorChar(const base::string16& s, 34 base::string16 RemoveAcceleratorChar(const base::string16& s,
12 base::char16 accelerator_char, 35 base::char16 accelerator_char,
13 int* accelerated_char_pos, 36 int* accelerated_char_pos,
14 int* accelerated_char_span) { 37 int* accelerated_char_span) {
15 bool escaped = false; 38 bool escaped = false;
16 ptrdiff_t last_char_pos = -1; 39 ptrdiff_t last_char_pos = -1;
17 int last_char_span = 0; 40 int last_char_span = 0;
18 base::i18n::UTF16CharIterator chars(&s); 41 base::i18n::UTF16CharIterator chars(&s);
19 base::string16 accelerator_removed; 42 base::string16 accelerator_removed;
20 43
(...skipping 18 matching lines...) Expand all
39 } 62 }
40 63
41 if (accelerated_char_pos) 64 if (accelerated_char_pos)
42 *accelerated_char_pos = last_char_pos; 65 *accelerated_char_pos = last_char_pos;
43 if (accelerated_char_span) 66 if (accelerated_char_span)
44 *accelerated_char_span = last_char_span; 67 *accelerated_char_span = last_char_span;
45 68
46 return accelerator_removed; 69 return accelerator_removed;
47 } 70 }
48 71
72 size_t FindValidBoundaryBefore(const base::string16& text, size_t index) {
73 size_t length = text.length();
74 DCHECK_LE(index, length);
75 if (index == length)
76 return index;
77
78 // If |index| straddles a combining character sequence, go back until we find
79 // a base character.
80 while (index > 0 && CharIsMark(GetCodePointAt(text, index)))
81 --index;
82
83 // If |index| straddles a UTF-16 surrogate pair, go back.
84 U16_SET_CP_START(text.data(), 0, index);
85 return index;
86 }
87
88 size_t FindValidBoundaryAfter(const base::string16& text, size_t index) {
msw 2015/06/03 00:32:04 Why did you drop the checked_casts here? Is https:
xdai1 2015/06/06 00:05:19 Sorry my bad, I should not have done that. I saw F
89 size_t length = text.length();
90 DCHECK_LE(index, length);
91 if (index == text.length())
92 return index;
93
94 // If |index| straddles a combining character sequence, go forward until we
95 // find a base character.
96 while (index < length && CharIsMark(GetCodePointAt(text, index))) {
97 ++index;
98 }
msw 2015/06/03 00:32:04 nit: drop curly braces
xdai1 2015/06/06 00:05:19 After bring back the checked_casts, it still requi
99
100 // If |index| straddles a UTF-16 surrogate pair, go forward.
101 U16_SET_CP_LIMIT(text.data(), 0, index, length);
102 return index;
103 }
104
49 } // namespace gfx 105 } // namespace gfx
OLDNEW
« ui/gfx/text_utils.h ('K') | « ui/gfx/text_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698