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

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

Issue 681123006: Fix a 'type-limits' warning in StringSlicer::FindValidBoundaryAfter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 // This file implements utility functions for eliding and formatting UI text. 5 // This file implements utility functions for eliding and formatting UI text.
6 // 6 //
7 // Note that several of the functions declared in text_elider.h are implemented 7 // Note that several of the functions declared in text_elider.h are implemented
8 // in this file using helper classes in an unnamed namespace. 8 // in this file using helper classes in an unnamed namespace.
9 9
10 #include "ui/gfx/text_elider.h" 10 #include "ui/gfx/text_elider.h"
11 11
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/i18n/break_iterator.h" 16 #include "base/i18n/break_iterator.h"
17 #include "base/i18n/char_iterator.h" 17 #include "base/i18n/char_iterator.h"
18 #include "base/i18n/rtl.h" 18 #include "base/i18n/rtl.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/numerics/safe_conversions.h"
20 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/strings/sys_string_conversions.h" 23 #include "base/strings/sys_string_conversions.h"
23 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
24 #include "third_party/icu/source/common/unicode/rbbi.h" 25 #include "third_party/icu/source/common/unicode/rbbi.h"
25 #include "third_party/icu/source/common/unicode/uloc.h" 26 #include "third_party/icu/source/common/unicode/uloc.h"
26 #include "ui/gfx/font_list.h" 27 #include "ui/gfx/font_list.h"
27 #include "ui/gfx/geometry/rect_conversions.h" 28 #include "ui/gfx/geometry/rect_conversions.h"
28 #include "ui/gfx/render_text.h" 29 #include "ui/gfx/render_text.h"
29 #include "ui/gfx/text_utils.h" 30 #include "ui/gfx/text_utils.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 140
140 size_t StringSlicer::FindValidBoundaryBefore(size_t index) const { 141 size_t StringSlicer::FindValidBoundaryBefore(size_t index) const {
141 DCHECK_LE(index, text_.length()); 142 DCHECK_LE(index, text_.length());
142 if (index != text_.length()) 143 if (index != text_.length())
143 U16_SET_CP_START(text_.data(), 0, index); 144 U16_SET_CP_START(text_.data(), 0, index);
144 return index; 145 return index;
145 } 146 }
146 147
147 size_t StringSlicer::FindValidBoundaryAfter(size_t index) const { 148 size_t StringSlicer::FindValidBoundaryAfter(size_t index) const {
148 DCHECK_LE(index, text_.length()); 149 DCHECK_LE(index, text_.length());
149 if (index != text_.length()) 150 if (index != text_.length()) {
150 U16_SET_CP_LIMIT(text_.data(), 0, index, text_.length()); 151 int32_t text_index = base::checked_cast<int32_t>(index);
152 int32_t text_length = base::checked_cast<int32_t>(text_.length());
153 U16_SET_CP_LIMIT(text_.data(), 0, text_index, text_length);
154 index = base::checked_cast<size_t>(text_index);
Peter Kasting 2014/10/29 19:17:26 How about this: if (index == text_.length())
155 }
151 return index; 156 return index;
152 } 157 }
153 158
154 base::string16 ElideFilename(const base::FilePath& filename, 159 base::string16 ElideFilename(const base::FilePath& filename,
155 const FontList& font_list, 160 const FontList& font_list,
156 float available_pixel_width) { 161 float available_pixel_width) {
157 #if defined(OS_WIN) 162 #if defined(OS_WIN)
158 base::string16 filename_utf16 = filename.value(); 163 base::string16 filename_utf16 = filename.value();
159 base::string16 extension = filename.Extension(); 164 base::string16 extension = filename.Extension();
160 base::string16 rootname = filename.BaseName().RemoveExtension().value(); 165 base::string16 rootname = filename.BaseName().RemoveExtension().value();
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 index = char_iterator.getIndex(); 822 index = char_iterator.getIndex();
818 } else { 823 } else {
819 // String has leading whitespace, return the elide string. 824 // String has leading whitespace, return the elide string.
820 return kElideString; 825 return kElideString;
821 } 826 }
822 827
823 return string.substr(0, index) + kElideString; 828 return string.substr(0, index) + kElideString;
824 } 829 }
825 830
826 } // namespace gfx 831 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698