| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/base/text/text_elider.h" | 7 #include "ui/base/text/text_elider.h" |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 bool strict_; | 569 bool strict_; |
| 570 | 570 |
| 571 // True when some of the input has been truncated. | 571 // True when some of the input has been truncated. |
| 572 bool suppressed_; | 572 bool suppressed_; |
| 573 | 573 |
| 574 // String onto which the output is accumulated. | 574 // String onto which the output is accumulated. |
| 575 string16 *output_; | 575 string16 *output_; |
| 576 }; | 576 }; |
| 577 | 577 |
| 578 void RectangleString::AddString(const string16& input) { | 578 void RectangleString::AddString(const string16& input) { |
| 579 base::i18n::BreakIterator lines(&input, | 579 base::i18n::BreakIterator lines(input, |
| 580 base::i18n::BreakIterator::BREAK_NEWLINE); | 580 base::i18n::BreakIterator::BREAK_NEWLINE); |
| 581 if (lines.Init()) { | 581 if (lines.Init()) { |
| 582 while (lines.Advance()) | 582 while (lines.Advance()) |
| 583 AddLine(lines.GetString()); | 583 AddLine(lines.GetString()); |
| 584 } else { | 584 } else { |
| 585 NOTREACHED() << "BreakIterator (lines) init failed"; | 585 NOTREACHED() << "BreakIterator (lines) init failed"; |
| 586 } | 586 } |
| 587 } | 587 } |
| 588 | 588 |
| 589 bool RectangleString::Finalize() { | 589 bool RectangleString::Finalize() { |
| 590 if (suppressed_) { | 590 if (suppressed_) { |
| 591 output_->append(ASCIIToUTF16("...")); | 591 output_->append(ASCIIToUTF16("...")); |
| 592 return true; | 592 return true; |
| 593 } | 593 } |
| 594 return false; | 594 return false; |
| 595 } | 595 } |
| 596 | 596 |
| 597 void RectangleString::AddLine(const string16& line) { | 597 void RectangleString::AddLine(const string16& line) { |
| 598 if (line.length() < max_cols_) { | 598 if (line.length() < max_cols_) { |
| 599 Append(line); | 599 Append(line); |
| 600 } else { | 600 } else { |
| 601 base::i18n::BreakIterator words(&line, | 601 base::i18n::BreakIterator words(line, |
| 602 base::i18n::BreakIterator::BREAK_SPACE); | 602 base::i18n::BreakIterator::BREAK_SPACE); |
| 603 if (words.Init()) { | 603 if (words.Init()) { |
| 604 while (words.Advance()) | 604 while (words.Advance()) |
| 605 AddWord(words.GetString()); | 605 AddWord(words.GetString()); |
| 606 } else { | 606 } else { |
| 607 NOTREACHED() << "BreakIterator (words) init failed"; | 607 NOTREACHED() << "BreakIterator (words) init failed"; |
| 608 } | 608 } |
| 609 } | 609 } |
| 610 // Account for naturally-occuring newlines. | 610 // Account for naturally-occuring newlines. |
| 611 ++current_row_; | 611 ++current_row_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 | 664 |
| 665 bool ElideRectangleString(const string16& input, size_t max_rows, | 665 bool ElideRectangleString(const string16& input, size_t max_rows, |
| 666 size_t max_cols, bool strict, string16* output) { | 666 size_t max_cols, bool strict, string16* output) { |
| 667 RectangleString rect(max_rows, max_cols, strict, output); | 667 RectangleString rect(max_rows, max_cols, strict, output); |
| 668 rect.Init(); | 668 rect.Init(); |
| 669 rect.AddString(input); | 669 rect.AddString(input); |
| 670 return rect.Finalize(); | 670 return rect.Finalize(); |
| 671 } | 671 } |
| 672 | 672 |
| 673 } // namespace ui | 673 } // namespace ui |
| OLD | NEW |