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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « app/text_elider.h ('k') | app/text_elider_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/text_elider.cc
===================================================================
--- app/text_elider.cc (revision 69274)
+++ app/text_elider.cc (working copy)
@@ -460,4 +460,41 @@
return display_url_.substr(slash_index + sort_host_.length());
}
+bool ElideString(const std::wstring& input, int max_len, std::wstring* output) {
+ DCHECK_GE(max_len, 0);
+ if (static_cast<int>(input.length()) <= max_len) {
+ output->assign(input);
+ return false;
+ }
+
+ switch (max_len) {
+ case 0:
+ output->clear();
+ break;
+ case 1:
+ output->assign(input.substr(0, 1));
+ break;
+ case 2:
+ output->assign(input.substr(0, 2));
+ break;
+ case 3:
+ output->assign(input.substr(0, 1) + L"." +
+ input.substr(input.length() - 1));
+ break;
+ case 4:
+ output->assign(input.substr(0, 1) + L".." +
+ input.substr(input.length() - 1));
+ break;
+ default: {
+ int rstr_len = (max_len - 3) / 2;
+ int lstr_len = rstr_len + ((max_len - 3) % 2);
+ output->assign(input.substr(0, lstr_len) + L"..." +
+ input.substr(input.length() - rstr_len));
+ break;
+ }
+ }
+
+ return true;
+}
+
} // namespace gfx
« 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