OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/printing_utils.h" | 5 #include "printing/printing_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "third_party/icu/source/common/unicode/uchar.h" | 14 #include "third_party/icu/source/common/unicode/uchar.h" |
15 #include "ui/gfx/text_elider.h" | 15 #include "ui/gfx/text_elider.h" |
16 | 16 |
17 namespace printing { | 17 namespace printing { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const size_t kMaxDocumentTitleLength = 80; | 21 const size_t kMaxDocumentTitleLength = 80; |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 base::string16 SimplifyDocumentTitleWithLength(const base::string16& title, | 25 base::string16 SimplifyDocumentTitleWithLength(const base::string16& title, |
26 size_t length) { | 26 size_t length) { |
27 base::string16 no_controls(title); | 27 base::string16 no_controls(title); |
28 no_controls.erase( | 28 no_controls.erase( |
29 std::remove_if(no_controls.begin(), no_controls.end(), &u_iscntrl), | 29 std::remove_if(no_controls.begin(), no_controls.end(), &u_iscntrl), |
30 no_controls.end()); | 30 no_controls.end()); |
| 31 base::ReplaceChars(no_controls, base::ASCIIToUTF16("\\"), |
| 32 base::ASCIIToUTF16("_"), &no_controls); |
31 base::string16 result; | 33 base::string16 result; |
32 gfx::ElideString(no_controls, length, &result); | 34 gfx::ElideString(no_controls, length, &result); |
33 return result; | 35 return result; |
34 } | 36 } |
35 | 37 |
36 base::string16 FormatDocumentTitleWithOwnerAndLength( | 38 base::string16 FormatDocumentTitleWithOwnerAndLength( |
37 const base::string16& owner, | 39 const base::string16& owner, |
38 const base::string16& title, | 40 const base::string16& title, |
39 size_t length) { | 41 size_t length) { |
40 const base::string16 separator = base::ASCIIToUTF16(": "); | 42 const base::string16 separator = base::ASCIIToUTF16(": "); |
41 DCHECK(separator.size() < length); | 43 DCHECK_LT(separator.size(), length); |
42 | 44 |
43 base::string16 short_title = | 45 base::string16 short_title = |
44 SimplifyDocumentTitleWithLength(owner, length - separator.size()); | 46 SimplifyDocumentTitleWithLength(owner, length - separator.size()); |
45 short_title += separator; | 47 short_title += separator; |
46 if (short_title.size() < length) { | 48 if (short_title.size() < length) { |
47 short_title += | 49 short_title += |
48 SimplifyDocumentTitleWithLength(title, length - short_title.size()); | 50 SimplifyDocumentTitleWithLength(title, length - short_title.size()); |
49 } | 51 } |
50 | 52 |
51 return short_title; | 53 return short_title; |
52 } | 54 } |
53 | 55 |
54 base::string16 SimplifyDocumentTitle(const base::string16& title) { | 56 base::string16 SimplifyDocumentTitle(const base::string16& title) { |
55 return SimplifyDocumentTitleWithLength(title, kMaxDocumentTitleLength); | 57 return SimplifyDocumentTitleWithLength(title, kMaxDocumentTitleLength); |
56 } | 58 } |
57 | 59 |
58 base::string16 FormatDocumentTitleWithOwner(const base::string16& owner, | 60 base::string16 FormatDocumentTitleWithOwner(const base::string16& owner, |
59 const base::string16& title) { | 61 const base::string16& title) { |
60 return FormatDocumentTitleWithOwnerAndLength(owner, title, | 62 return FormatDocumentTitleWithOwnerAndLength(owner, title, |
61 kMaxDocumentTitleLength); | 63 kMaxDocumentTitleLength); |
62 } | 64 } |
63 | 65 |
64 } // namespace printing | 66 } // namespace printing |
OLD | NEW |