| 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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 | 771 |
| 772 int32_t index = static_cast<int32_t>(length - 1); | 772 int32_t index = static_cast<int32_t>(length - 1); |
| 773 if (word_break) { | 773 if (word_break) { |
| 774 // Use a word iterator to find the first boundary. | 774 // Use a word iterator to find the first boundary. |
| 775 UErrorCode status = U_ZERO_ERROR; | 775 UErrorCode status = U_ZERO_ERROR; |
| 776 std::unique_ptr<icu::BreakIterator> bi( | 776 std::unique_ptr<icu::BreakIterator> bi( |
| 777 icu::RuleBasedBreakIterator::createWordInstance( | 777 icu::RuleBasedBreakIterator::createWordInstance( |
| 778 icu::Locale::getDefault(), status)); | 778 icu::Locale::getDefault(), status)); |
| 779 if (U_FAILURE(status)) | 779 if (U_FAILURE(status)) |
| 780 return string.substr(0, length - 1) + kElideString; | 780 return string.substr(0, length - 1) + kElideString; |
| 781 bi->setText(string.c_str()); | 781 icu::UnicodeString bi_text(string.c_str()); |
| 782 bi->setText(bi_text); |
| 782 index = bi->preceding(static_cast<int32_t>(length)); | 783 index = bi->preceding(static_cast<int32_t>(length)); |
| 783 if (index == icu::BreakIterator::DONE || index == 0) { | 784 if (index == icu::BreakIterator::DONE || index == 0) { |
| 784 // We either found no valid word break at all, or one right at the | 785 // We either found no valid word break at all, or one right at the |
| 785 // beginning of the string. Go back to the end; we'll have to break in the | 786 // beginning of the string. Go back to the end; we'll have to break in the |
| 786 // middle of a word. | 787 // middle of a word. |
| 787 index = static_cast<int32_t>(length - 1); | 788 index = static_cast<int32_t>(length - 1); |
| 788 } | 789 } |
| 789 } | 790 } |
| 790 | 791 |
| 791 // By this point, |index| should point at the character that's a candidate for | 792 // By this point, |index| should point at the character that's a candidate for |
| (...skipping 19 matching lines...) Expand all Loading... |
| 811 // of, and we can fit at least one character of the word in the elided string. | 812 // of, and we can fit at least one character of the word in the elided string. |
| 812 // Do that rather than just returning an ellipsis. | 813 // Do that rather than just returning an ellipsis. |
| 813 if (word_break && (index != static_cast<int32_t>(length - 1))) | 814 if (word_break && (index != static_cast<int32_t>(length - 1))) |
| 814 return string.substr(0, length - 1) + kElideString; | 815 return string.substr(0, length - 1) + kElideString; |
| 815 | 816 |
| 816 // Trying to break after only whitespace, elide all of it. | 817 // Trying to break after only whitespace, elide all of it. |
| 817 return kElideString; | 818 return kElideString; |
| 818 } | 819 } |
| 819 | 820 |
| 820 } // namespace gfx | 821 } // namespace gfx |
| OLD | NEW |