| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_range.h" | 5 #include "printing/page_range.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 namespace printing { | 10 namespace printing { |
| 11 | 11 |
| 12 /* static */ | 12 /* static */ |
| 13 std::vector<int> PageRange::GetPages(const PageRanges& ranges) { | 13 std::vector<int> PageRange::GetPages(const PageRanges& ranges) { |
| 14 std::set<int> pages; | 14 std::set<int> pages; |
| 15 for (unsigned i = 0; i < ranges.size(); ++i) { | 15 for (unsigned i = 0; i < ranges.size(); ++i) { |
| 16 const PageRange& range = ranges[i]; | 16 const PageRange& range = ranges[i]; |
| 17 // Ranges are inclusive. | 17 // Ranges are inclusive. |
| 18 for (int i = range.from; i <= range.to; ++i) { | 18 for (int i = range.from; i <= range.to; ++i) { |
| 19 pages.insert(i); | 19 pages.insert(i); |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 return std::vector<int>(pages.begin(), pages.end()); | 22 return std::vector<int>(pages.begin(), pages.end()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 /* static */ | |
| 26 int PageRange::GetTotalPages(const PageRanges& ranges) { | |
| 27 // Since ranges can overlap we need to merge them before counting | |
| 28 std::vector<int> pages = PageRange::GetPages(ranges); | |
| 29 return pages.size(); | |
| 30 } | |
| 31 | |
| 32 } // namespace printing | 25 } // namespace printing |
| OLD | NEW |