Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 size_t StringSlicer::FindValidBoundaryBefore(size_t index) const { | 140 size_t StringSlicer::FindValidBoundaryBefore(size_t index) const { |
| 141 DCHECK_LE(index, text_.length()); | 141 DCHECK_LE(index, text_.length()); |
| 142 if (index != text_.length()) | 142 if (index != text_.length()) |
| 143 U16_SET_CP_START(text_.data(), 0, index); | 143 U16_SET_CP_START(text_.data(), 0, index); |
| 144 return index; | 144 return index; |
| 145 } | 145 } |
| 146 | 146 |
| 147 size_t StringSlicer::FindValidBoundaryAfter(size_t index) const { | 147 size_t StringSlicer::FindValidBoundaryAfter(size_t index) const { |
| 148 DCHECK_LE(index, text_.length()); | 148 DCHECK_LE(index, text_.length()); |
| 149 if (index != text_.length()) | 149 if (index != text_.length()) |
| 150 U16_SET_CP_LIMIT(text_.data(), 0, index, text_.length()); | 150 U16_SET_CP_LIMIT(text_.data(), 0, index, -1); |
|
Peter Kasting
2014/10/29 17:33:38
For safety, this should use c_str() instead of dat
Ben Chan
2014/10/29 17:36:01
Done.
| |
| 151 return index; | 151 return index; |
| 152 } | 152 } |
| 153 | 153 |
| 154 base::string16 ElideFilename(const base::FilePath& filename, | 154 base::string16 ElideFilename(const base::FilePath& filename, |
| 155 const FontList& font_list, | 155 const FontList& font_list, |
| 156 float available_pixel_width) { | 156 float available_pixel_width) { |
| 157 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
| 158 base::string16 filename_utf16 = filename.value(); | 158 base::string16 filename_utf16 = filename.value(); |
| 159 base::string16 extension = filename.Extension(); | 159 base::string16 extension = filename.Extension(); |
| 160 base::string16 rootname = filename.BaseName().RemoveExtension().value(); | 160 base::string16 rootname = filename.BaseName().RemoveExtension().value(); |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 index = char_iterator.getIndex(); | 817 index = char_iterator.getIndex(); |
| 818 } else { | 818 } else { |
| 819 // String has leading whitespace, return the elide string. | 819 // String has leading whitespace, return the elide string. |
| 820 return kElideString; | 820 return kElideString; |
| 821 } | 821 } |
| 822 | 822 |
| 823 return string.substr(0, index) + kElideString; | 823 return string.substr(0, index) + kElideString; |
| 824 } | 824 } |
| 825 | 825 |
| 826 } // namespace gfx | 826 } // namespace gfx |
| OLD | NEW |