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

Side by Side Diff: app/text_elider.cc

Issue 6017001: Move ElideString() from base/string_util.cc to app/text_elider.cc to ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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 | « app/text_elider.h ('k') | app/text_elider_unittest.cc » ('j') | no next file with comments »
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) 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
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
OLDNEW
« no previous file with comments | « app/text_elider.h ('k') | app/text_elider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698