| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/page_overlays.h" | 5 #include "printing/page_overlays.h" |
| 6 | 6 |
| 7 #include "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" |
| 10 #include "printing/printed_document.h" | 11 #include "printing/printed_document.h" |
| 11 #include "printing/printed_page.h" | 12 #include "printing/printed_page.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Replaces a subpart of a string by other value, and returns the position right | 16 // Replaces a subpart of a string by other value, and returns the position right |
| 16 // after the new value. | 17 // after the new value. |
| 17 size_t ReplaceKey(std::wstring* string, | 18 size_t ReplaceKey(std::wstring* string, |
| 18 size_t offset, | 19 size_t offset, |
| 19 size_t old_string_len, | 20 size_t old_string_len, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 NOTREACHED(); | 127 NOTREACHED(); |
| 127 break; | 128 break; |
| 128 } | 129 } |
| 129 break; | 130 break; |
| 130 default: | 131 default: |
| 131 NOTREACHED(); | 132 NOTREACHED(); |
| 132 break; | 133 break; |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 | 136 |
| 136 //static | 137 // static |
| 137 std::wstring PageOverlays::ReplaceVariables(const std::wstring& input, | 138 std::wstring PageOverlays::ReplaceVariables(const std::wstring& input, |
| 138 const PrintedDocument& document, | 139 const PrintedDocument& document, |
| 139 const PrintedPage& page) { | 140 const PrintedPage& page) { |
| 140 std::wstring output(input); | 141 std::wstring output(input); |
| 141 for (size_t offset = output.find(L'{', 0); | 142 for (size_t offset = output.find(L'{', 0); |
| 142 offset != std::wstring::npos; | 143 offset != std::wstring::npos; |
| 143 offset = output.find(L'{', offset)) { | 144 offset = output.find(L'{', offset)) { |
| 144 | |
| 145 if (0 == output.compare(offset, | 145 if (0 == output.compare(offset, |
| 146 wcslen(kTitle), | 146 wcslen(kTitle), |
| 147 kTitle)) { | 147 kTitle)) { |
| 148 offset = ReplaceKey(&output, | 148 offset = ReplaceKey(&output, |
| 149 offset, | 149 offset, |
| 150 wcslen(kTitle), | 150 wcslen(kTitle), |
| 151 document.name()); | 151 document.name()); |
| 152 } else if (0 == output.compare(offset, | 152 } else if (0 == output.compare(offset, |
| 153 wcslen(kTime), | 153 wcslen(kTime), |
| 154 kTime)) { | 154 kTime)) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 UTF8ToWide(document.url().spec())); | 198 UTF8ToWide(document.url().spec())); |
| 199 } else { | 199 } else { |
| 200 // There is just a { in the string. | 200 // There is just a { in the string. |
| 201 ++offset; | 201 ++offset; |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 return output; | 204 return output; |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace printing | 207 } // namespace printing |
| OLD | NEW |