Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/location_bar/location_bar_util.h" | 5 #include "chrome/browser/ui/location_bar/location_bar_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "ui/gfx/text_elider.h" | 12 #include "ui/gfx/text_elider.h" |
| 13 | 13 |
| 14 namespace location_bar_util { | 14 namespace location_bar_util { |
| 15 | 15 |
| 16 base::string16 CalculateMinString(const base::string16& description) { | 16 base::string16 CalculateMinString(const base::string16& description) { |
| 17 // Chop at the first '.' or whitespace. | 17 // Chop at the first '.' or whitespace. |
| 18 const size_t chop_index = description.find_first_of( | 18 const size_t chop_index = description.find_first_of( |
| 19 base::kWhitespaceUTF16 + base::ASCIIToUTF16(".")); | 19 base::kWhitespaceUTF16 + base::ASCIIToUTF16(".")); |
| 20 base::string16 min_string((chop_index == base::string16::npos) ? | 20 base::string16 min_string( |
| 21 gfx::TruncateString(description, 3, gfx::WORD_BREAK) : | 21 (chop_index == base::string16::npos) |
| 22 description.substr(0, chop_index)); | 22 ? |
| 23 // Show at least 4 characters plus an ellipsis. | |
|
Peter Kasting
2017/02/25 06:17:11
Nit: This formatting is wacky. How about:
base
| |
| 24 gfx::TruncateString(description, 5, gfx::WORD_BREAK) | |
| 25 : description.substr(0, chop_index)); | |
| 23 base::i18n::AdjustStringForLocaleDirection(&min_string); | 26 base::i18n::AdjustStringForLocaleDirection(&min_string); |
| 24 return min_string; | 27 return min_string; |
| 25 } | 28 } |
| 26 | 29 |
| 27 } // namespace location_bar_util | 30 } // namespace location_bar_util |
| OLD | NEW |