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

Side by Side Diff: base/string_util.cc

Issue 6043: Added dangerous download prompting. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/string_util.h" 5 #include "base/string_util.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <math.h> 9 #include <math.h>
10 #include <stdarg.h> 10 #include <stdarg.h>
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 1427
1428 } // namespace 1428 } // namespace
1429 1429
1430 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { 1430 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
1431 return lcpyT<char>(dst, src, dst_size); 1431 return lcpyT<char>(dst, src, dst_size);
1432 } 1432 }
1433 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 1433 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
1434 return lcpyT<wchar_t>(dst, src, dst_size); 1434 return lcpyT<wchar_t>(dst, src, dst_size);
1435 } 1435 }
1436 1436
1437 bool ElideString(const std::wstring& input, int max_len, std::wstring* output) {
1438 DCHECK(max_len >= 0);
1439 if (static_cast<int>(input.length()) <= max_len) {
1440 output->assign(input);
1441 return false;
1442 }
1443
1444 switch (max_len) {
1445 case 0:
1446 output->clear();
1447 break;
1448 case 1:
1449 output->assign(input.substr(0, 1));
1450 break;
1451 case 2:
1452 output->assign(input.substr(0, 2));
1453 break;
1454 case 3:
1455 output->assign(input.substr(0, 1) + L"." +
1456 input.substr(input.length() - 1));
1457 break;
1458 case 4:
1459 output->assign(input.substr(0, 1) + L".." +
1460 input.substr(input.length() - 1));
1461 break;
1462 default: {
1463 int rstr_len = (max_len - 3) / 2;
1464 int lstr_len = rstr_len + ((max_len - 3) % 2);
1465 output->assign(input.substr(0, lstr_len) + L"..." +
1466 input.substr(input.length() - rstr_len));
1467 break;
1468 }
1469 }
1470
1471 return true;
1472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698