summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjschuh@google.com <jschuh@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-17 17:24:59 +0000
committerjschuh@google.com <jschuh@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-17 17:24:59 +0000
commit173293170c18302eae5d2cf77d995daad74d4db1 (patch)
tree07b1516c8dc0e42859ae538e4a217d68f6bea958 /base
parent1f2d03b835c575406136a347cbbee6074b284793 (diff)
downloadchromium_src-173293170c18302eae5d2cf77d995daad74d4db1.zip
chromium_src-173293170c18302eae5d2cf77d995daad74d4db1.tar.gz
chromium_src-173293170c18302eae5d2cf77d995daad74d4db1.tar.bz2
Move ElideString() from base/string_util.cc to app/text_elider.cc to
reduce size of widely-included base libraries. Committing for tsepez. BUG=49747 TEST=TextEliderTest.* Review URL: http://codereview.chromium.org/6017001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/string_util.cc37
-rw-r--r--base/string_util.h8
-rw-r--r--base/string_util_unittest.cc27
3 files changed, 0 insertions, 72 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index fc1372b..ce12705 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -1094,40 +1094,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;
-}
diff --git a/base/string_util.h b/base/string_util.h
index 498ccc5..f65652c 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -523,14 +523,6 @@ string16 ReplaceStringPlaceholders(const string16& format_string,
const string16& a,
size_t* offset);
-// If the size of |input| is more than |max_len|, this function returns true and
-// |input| is shortened into |output| by removing chars in the middle (they are
-// replaced with up to 3 dots, as size permits).
-// Ex: ElideString(L"Hello", 10, &str) puts Hello in str and returns false.
-// ElideString(L"Hello my name is Tom", 10, &str) puts "Hell...Tom" in str and
-// returns true.
-bool ElideString(const std::wstring& input, int max_len, std::wstring* output);
-
// Returns true if the string passed in matches the pattern. The pattern
// string can contain wildcards like * and ?
// The backslash character (\) is an escape character for * and ?
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index b7639bb..cd45642 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -1056,33 +1056,6 @@ TEST(StringUtilTest, WprintfFormatPortabilityTest) {
}
}
-TEST(StringUtilTest, ElideString) {
- struct TestData {
- const wchar_t* input;
- int max_len;
- bool result;
- const wchar_t* output;
- } cases[] = {
- { L"Hello", 0, true, L"" },
- { L"", 0, false, L"" },
- { L"Hello, my name is Tom", 1, true, L"H" },
- { L"Hello, my name is Tom", 2, true, L"He" },
- { L"Hello, my name is Tom", 3, true, L"H.m" },
- { L"Hello, my name is Tom", 4, true, L"H..m" },
- { L"Hello, my name is Tom", 5, true, L"H...m" },
- { L"Hello, my name is Tom", 6, true, L"He...m" },
- { L"Hello, my name is Tom", 7, true, L"He...om" },
- { L"Hello, my name is Tom", 10, true, L"Hell...Tom" },
- { L"Hello, my name is Tom", 100, false, L"Hello, my name is Tom" }
- };
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
- std::wstring output;
- EXPECT_EQ(cases[i].result,
- ElideString(cases[i].input, cases[i].max_len, &output));
- EXPECT_TRUE(output == cases[i].output);
- }
-}
-
TEST(StringUtilTest, RemoveChars) {
const char* kRemoveChars = "-/+*";
std::string input = "A-+bc/d!*";