blob: ea2e30a38cbc262657e42209d10c1f9ab529c143 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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
3// found in the LICENSE file.
4
5#include "printing/page_range.h"
6
7#include <set>
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +01008
9namespace {
10const std::size_t kMaxNumberOfPages = 100000;
11}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000012
13namespace printing {
14
15/* static */
16std::vector<int> PageRange::GetPages(const PageRanges& ranges) {
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010017 // TODO(vitalybuka): crbug.com/95548 Remove this method as part fix.
Torne (Richard Coles)58218062012-11-14 11:43:16 +000018 std::set<int> pages;
19 for (unsigned i = 0; i < ranges.size(); ++i) {
20 const PageRange& range = ranges[i];
21 // Ranges are inclusive.
22 for (int i = range.from; i <= range.to; ++i) {
23 pages.insert(i);
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010024 if (pages.size() >= kMaxNumberOfPages)
25 return std::vector<int>(pages.begin(), pages.end());
Torne (Richard Coles)58218062012-11-14 11:43:16 +000026 }
27 }
28 return std::vector<int>(pages.begin(), pages.end());
29}
30
31} // namespace printing