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
   30
   31
   32
   33
   34
   35

printing / page_range.cc [blame]

// Copyright 2011 The Chromium Authors
// 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 <algorithm>
#include <set>

namespace printing {

// static
void PageRange::Normalize(PageRanges& ranges) {
  if (ranges.empty()) {
    return;
  }

  std::sort(ranges.begin(), ranges.end());
  PageRanges::iterator dst = ranges.begin();
  for (PageRanges::iterator src = ranges.begin() + 1; src < ranges.end();
       ++src) {
    if (dst->to + 1 < src->from) {
      *++dst = *src;
      continue;
    }
    dst->to = std::max(dst->to, src->to);
  }
  if (dst < ranges.end())
    dst++;
  ranges.resize(dst - ranges.begin());
}

}  // namespace printing