| OLD | NEW |
| 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 "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <ctype.h> | 9 #include <ctype.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 } // namespace | 1089 } // namespace |
| 1090 | 1090 |
| 1091 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 1091 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
| 1092 return lcpyT<char>(dst, src, dst_size); | 1092 return lcpyT<char>(dst, src, dst_size); |
| 1093 } | 1093 } |
| 1094 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 1094 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
| 1095 return lcpyT<wchar_t>(dst, src, dst_size); | 1095 return lcpyT<wchar_t>(dst, src, dst_size); |
| 1096 } | 1096 } |
| 1097 | |
| 1098 bool ElideString(const std::wstring& input, int max_len, std::wstring* output) { | |
| 1099 DCHECK(max_len >= 0); | |
| 1100 if (static_cast<int>(input.length()) <= max_len) { | |
| 1101 output->assign(input); | |
| 1102 return false; | |
| 1103 } | |
| 1104 | |
| 1105 switch (max_len) { | |
| 1106 case 0: | |
| 1107 output->clear(); | |
| 1108 break; | |
| 1109 case 1: | |
| 1110 output->assign(input.substr(0, 1)); | |
| 1111 break; | |
| 1112 case 2: | |
| 1113 output->assign(input.substr(0, 2)); | |
| 1114 break; | |
| 1115 case 3: | |
| 1116 output->assign(input.substr(0, 1) + L"." + | |
| 1117 input.substr(input.length() - 1)); | |
| 1118 break; | |
| 1119 case 4: | |
| 1120 output->assign(input.substr(0, 1) + L".." + | |
| 1121 input.substr(input.length() - 1)); | |
| 1122 break; | |
| 1123 default: { | |
| 1124 int rstr_len = (max_len - 3) / 2; | |
| 1125 int lstr_len = rstr_len + ((max_len - 3) % 2); | |
| 1126 output->assign(input.substr(0, lstr_len) + L"..." + | |
| 1127 input.substr(input.length() - rstr_len)); | |
| 1128 break; | |
| 1129 } | |
| 1130 } | |
| 1131 | |
| 1132 return true; | |
| 1133 } | |
| OLD | NEW |