summaryrefslogtreecommitdiffstats
path: root/base/string_util.cc
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-05-11 20:53:37 +0100
committerKristian Monsen <kristianm@google.com>2011-05-16 13:54:48 +0100
commit21d179b334e59e9a3bfcaed4c4430bef1bc5759d (patch)
tree64e2bb6da27af6a5c93ca34f6051584aafbfcb9e /base/string_util.cc
parent0c63f00edd6ed0482fd5cbcea937ca088baf7858 (diff)
downloadexternal_chromium-21d179b334e59e9a3bfcaed4c4430bef1bc5759d.zip
external_chromium-21d179b334e59e9a3bfcaed4c4430bef1bc5759d.tar.gz
external_chromium-21d179b334e59e9a3bfcaed4c4430bef1bc5759d.tar.bz2
Merge Chromium at 10.0.621.0: Initial merge by git.
Change-Id: I070cc91c608dfa4a968a5a54c173260765ac8097
Diffstat (limited to 'base/string_util.cc')
-rw-r--r--base/string_util.cc47
1 files changed, 7 insertions, 40 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index 1c97487..0e0f17b 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -38,6 +38,10 @@ struct EmptyStrings {
const std::string s;
const std::wstring ws;
const string16 s16;
+
+ static EmptyStrings* GetInstance() {
+ return Singleton<EmptyStrings>::get();
+ }
};
// Used by ReplaceStringPlaceholders to track the position in the string of
@@ -102,15 +106,15 @@ bool IsWprintfFormatPortable(const wchar_t* format) {
const std::string& EmptyString() {
- return Singleton<EmptyStrings>::get()->s;
+ return EmptyStrings::GetInstance()->s;
}
const std::wstring& EmptyWString() {
- return Singleton<EmptyStrings>::get()->ws;
+ return EmptyStrings::GetInstance()->ws;
}
const string16& EmptyString16() {
- return Singleton<EmptyStrings>::get()->s16;
+ return EmptyStrings::GetInstance()->s16;
}
#define WHITESPACE_UNICODE \
@@ -1094,40 +1098,3 @@ size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
return lcpyT<wchar_t>(dst, src, dst_size);
}
-
-bool ElideString(const std::wstring& input, int max_len, std::wstring* output) {
- DCHECK(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;
-}