1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/printing_utils.h"
9 #include "base/logging.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "third_party/icu/source/common/unicode/uchar.h"
13 #include "ui/gfx/text_elider.h"
19 const size_t kMaxDocumentTitleLength
= 80;
23 base::string16
SimplifyDocumentTitleWithLength(const base::string16
& title
,
25 base::string16
no_controls(title
);
27 std::remove_if(no_controls
.begin(), no_controls
.end(), &u_iscntrl
),
29 base::string16 result
;
30 gfx::ElideString(no_controls
, static_cast<int>(length
), &result
);
34 base::string16
FormatDocumentTitleWithOwnerAndLength(
35 const base::string16
& owner
,
36 const base::string16
& title
,
38 const base::string16 separator
= base::ASCIIToUTF16(": ");
39 DCHECK(separator
.size() < length
);
41 base::string16 short_title
=
42 SimplifyDocumentTitleWithLength(owner
, length
- separator
.size());
43 short_title
+= separator
;
44 if (short_title
.size() < length
) {
46 SimplifyDocumentTitleWithLength(title
, length
- short_title
.size());
52 base::string16
SimplifyDocumentTitle(const base::string16
& title
) {
53 return SimplifyDocumentTitleWithLength(title
, kMaxDocumentTitleLength
);
56 base::string16
FormatDocumentTitleWithOwner(const base::string16
& owner
,
57 const base::string16
& title
) {
58 return FormatDocumentTitleWithOwnerAndLength(owner
, title
,
59 kMaxDocumentTitleLength
);
62 } // namespace printing