Allow trusted brokers to restrict connections for spawned applications to whitelisted...
[chromium-blink-merge.git] / printing / printing_utils.cc
blob5f9fd2cf5b1b88322d2e552d6ddab925fb939ee2
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"
7 #include <algorithm>
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"
15 namespace printing {
17 namespace {
19 const size_t kMaxDocumentTitleLength = 80;
21 } // namespace
23 base::string16 SimplifyDocumentTitleWithLength(const base::string16& title,
24 size_t length) {
25 base::string16 no_controls(title);
26 no_controls.erase(
27 std::remove_if(no_controls.begin(), no_controls.end(), &u_iscntrl),
28 no_controls.end());
29 base::string16 result;
30 gfx::ElideString(no_controls, static_cast<int>(length), &result);
31 return result;
34 base::string16 FormatDocumentTitleWithOwnerAndLength(
35 const base::string16& owner,
36 const base::string16& title,
37 size_t length) {
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) {
45 short_title +=
46 SimplifyDocumentTitleWithLength(title, length - short_title.size());
49 return short_title;
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