summaryrefslogtreecommitdiffstats
path: root/chromium/printing/page_range.cc
blob: 22aea0f488e4444b571ac870d374c8b61ed9c1ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "printing/page_range.h"

#include <stddef.h>

#include <set>

namespace printing {

// static
std::vector<int> PageRange::GetPages(const PageRanges& ranges) {
  // TODO(vitalybuka): crbug.com/95548 Remove this method as part fix.
  std::set<int> pages;
  for (const PageRange& range : ranges) {
    // Ranges are inclusive.
    for (int i = range.from; i <= range.to; ++i) {
      static constexpr size_t kMaxNumberOfPages = 100000;
      pages.insert(i);
      if (pages.size() >= kMaxNumberOfPages)
        return std::vector<int>(pages.begin(), pages.end());
    }
  }
  return std::vector<int>(pages.begin(), pages.end());
}

}  // namespace printing