Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: app/text_elider.cc

Issue 6355005: base/i18n: Add namespace i18n to CharIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unittests Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/i18n/char_iterator.h » ('j') | base/i18n/char_iterator.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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 "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/break_iterator.h" 9 #include "base/i18n/break_iterator.h"
10 #include "base/i18n/char_iterator.h" 10 #include "base/i18n/char_iterator.h"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/string_split.h" 12 #include "base/string_split.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "gfx/font.h" 16 #include "gfx/font.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "net/base/escape.h" 18 #include "net/base/escape.h"
19 #include "net/base/net_util.h" 19 #include "net/base/net_util.h"
20 #include "net/base/registry_controlled_domain.h" 20 #include "net/base/registry_controlled_domain.h"
21 21
22
23 namespace { 22 namespace {
24 23
25 const char* kEllipsis = "\xE2\x80\xA6"; 24 const char* kEllipsis = "\xE2\x80\xA6";
26 25
27 // Cuts |text| to be |length| characters long. If |cut_in_middle| is true, the 26 // Cuts |text| to be |length| characters long. If |cut_in_middle| is true, the
28 // middle of the string is removed to leave equal-length pieces from the 27 // middle of the string is removed to leave equal-length pieces from the
29 // beginning and end of the string; otherwise, the end of the string is removed 28 // beginning and end of the string; otherwise, the end of the string is removed
30 // and only the beginning remains. If |insert_ellipsis| is true, then an 29 // and only the beginning remains. If |insert_ellipsis| is true, then an
31 // ellipsis character will by inserted at the cut point. 30 // ellipsis character will by inserted at the cut point.
32 string16 CutString(const string16& text, 31 string16 CutString(const string16& text,
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 void RectangleString::AddWord(const string16& word) { 608 void RectangleString::AddWord(const string16& word) {
610 if (word.length() < max_cols_) { 609 if (word.length() < max_cols_) {
611 // Word can be made to fit, no need to fragment it. 610 // Word can be made to fit, no need to fragment it.
612 if (current_col_ + word.length() >= max_cols_) 611 if (current_col_ + word.length() >= max_cols_)
613 NewLine(); 612 NewLine();
614 Append(word); 613 Append(word);
615 } else { 614 } else {
616 // Word is so big that it must be fragmented. 615 // Word is so big that it must be fragmented.
617 int array_start = 0; 616 int array_start = 0;
618 int char_start = 0; 617 int char_start = 0;
619 base::UTF16CharIterator chars(&word); 618 base::i18n::UTF16CharIterator chars(&word);
620 while (!chars.end()) { 619 while (!chars.end()) {
621 // When boundary is hit, add as much as will fit on this line. 620 // When boundary is hit, add as much as will fit on this line.
622 if (current_col_ + (chars.char_pos() - char_start) >= max_cols_) { 621 if (current_col_ + (chars.char_pos() - char_start) >= max_cols_) {
623 Append(word.substr(array_start, chars.array_pos() - array_start)); 622 Append(word.substr(array_start, chars.array_pos() - array_start));
624 NewLine(); 623 NewLine();
625 array_start = chars.array_pos(); 624 array_start = chars.array_pos();
626 char_start = chars.char_pos(); 625 char_start = chars.char_pos();
627 } 626 }
628 chars.Advance(); 627 chars.Advance();
629 } 628 }
(...skipping 27 matching lines...) Expand all
657 bool ElideRectangleString(const string16& input, size_t max_rows, 656 bool ElideRectangleString(const string16& input, size_t max_rows,
658 size_t max_cols, string16* output) { 657 size_t max_cols, string16* output) {
659 RectangleString rect(max_rows, max_cols, output); 658 RectangleString rect(max_rows, max_cols, output);
660 rect.Init(); 659 rect.Init();
661 rect.AddString(input); 660 rect.AddString(input);
662 return rect.Finalize(); 661 return rect.Finalize();
663 } 662 }
664 663
665 } // namespace gfx 664 } // namespace gfx
666 665
OLDNEW
« no previous file with comments | « no previous file | base/i18n/char_iterator.h » ('j') | base/i18n/char_iterator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698