| Index: ui/base/text/text_elider.cc
|
| diff --git a/ui/base/text/text_elider.cc b/ui/base/text/text_elider.cc
|
| index 525cea0df61eb373507b91372f144dbf327cf419..8ea7c09c4beb00f926a1e7e0a2b45f33b8194efb 100644
|
| --- a/ui/base/text/text_elider.cc
|
| +++ b/ui/base/text/text_elider.cc
|
| @@ -35,6 +35,8 @@ namespace ui {
|
| const char kEllipsis[] = "\xE2\x80\xA6";
|
| const char16 kForwardSlash = '/';
|
|
|
| +const size_t kMaxProfileUsernameLength = 20;
|
| +
|
| namespace {
|
|
|
| // Helper class to split + elide text, while respecting UTF16 surrogate pairs.
|
| @@ -149,6 +151,41 @@ string16 ElideComponentizedPath(const string16& url_path_prefix,
|
|
|
| } // namespace
|
|
|
| +string16 ElideEmail(const string16& email, size_t max_email_length) {
|
| + DCHECK_GE(max_email_length, 5U);
|
| +
|
| + if (email.length() <= max_email_length)
|
| + return email;
|
| +
|
| + std::vector<string16> email_split;
|
| + base::SplitString(email, '@', &email_split);
|
| + DCHECK_EQ(email_split.size(), 2U);
|
| + string16 username = email_split.front();
|
| + string16 domain = email_split.back();
|
| +
|
| + const string16 kEllipsisUTF16 = UTF8ToUTF16(kEllipsis);
|
| + const size_t kEllipsisLength = kEllipsisUTF16.length();
|
| +
|
| + // Reserve characters for each of: username ellipsis, @ sign, and at least
|
| + // one character remaining in the username.
|
| + const size_t available_domain_chars = max_email_length - kEllipsisLength - 2;
|
| + if (domain.length() > available_domain_chars) {
|
| + StringSlicer slicer(domain, kEllipsisUTF16, true);
|
| + const size_t length = max_email_length / 2 - kEllipsisLength;
|
| + domain = slicer.CutString(length, true);
|
| + }
|
| +
|
| + const size_t final_domain_length = domain.length();
|
| + if (username.length() + final_domain_length + 1 > max_email_length) {
|
| + StringSlicer slicer(username, kEllipsisUTF16, false);
|
| + const size_t length = max_email_length - final_domain_length -
|
| + kEllipsisLength - 1;
|
| + username = slicer.CutString(length, true);
|
| + }
|
| +
|
| + return username + ASCIIToUTF16("@") + domain;
|
| +}
|
| +
|
| // This function takes a GURL object and elides it. It returns a string
|
| // which composed of parts from subdomain, domain, path, filename and query.
|
| // A "..." is added automatically at the end if the elided string is bigger
|
|
|