OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "app/text_elider.h" | 7 #include "app/text_elider.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 453 |
454 string16 SortedDisplayURL::AfterHost() const { | 454 string16 SortedDisplayURL::AfterHost() const { |
455 size_t slash_index = display_url_.find(sort_host_, prefix_end_); | 455 size_t slash_index = display_url_.find(sort_host_, prefix_end_); |
456 if (slash_index == string16::npos) { | 456 if (slash_index == string16::npos) { |
457 NOTREACHED(); | 457 NOTREACHED(); |
458 return string16(); | 458 return string16(); |
459 } | 459 } |
460 return display_url_.substr(slash_index + sort_host_.length()); | 460 return display_url_.substr(slash_index + sort_host_.length()); |
461 } | 461 } |
462 | 462 |
| 463 bool ElideString(const std::wstring& input, int max_len, std::wstring* output) { |
| 464 DCHECK_GE(max_len, 0); |
| 465 if (static_cast<int>(input.length()) <= max_len) { |
| 466 output->assign(input); |
| 467 return false; |
| 468 } |
| 469 |
| 470 switch (max_len) { |
| 471 case 0: |
| 472 output->clear(); |
| 473 break; |
| 474 case 1: |
| 475 output->assign(input.substr(0, 1)); |
| 476 break; |
| 477 case 2: |
| 478 output->assign(input.substr(0, 2)); |
| 479 break; |
| 480 case 3: |
| 481 output->assign(input.substr(0, 1) + L"." + |
| 482 input.substr(input.length() - 1)); |
| 483 break; |
| 484 case 4: |
| 485 output->assign(input.substr(0, 1) + L".." + |
| 486 input.substr(input.length() - 1)); |
| 487 break; |
| 488 default: { |
| 489 int rstr_len = (max_len - 3) / 2; |
| 490 int lstr_len = rstr_len + ((max_len - 3) % 2); |
| 491 output->assign(input.substr(0, lstr_len) + L"..." + |
| 492 input.substr(input.length() - rstr_len)); |
| 493 break; |
| 494 } |
| 495 } |
| 496 |
| 497 return true; |
| 498 } |
| 499 |
463 } // namespace gfx | 500 } // namespace gfx |
OLD | NEW |