page_range.cc 748 B

12345678910111213141516171819202122232425262728293031
  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
  3. // found in the LICENSE file.
  4. #include "printing/page_range.h"
  5. #include <stddef.h>
  6. #include <algorithm>
  7. #include <set>
  8. namespace printing {
  9. // static
  10. void PageRange::Normalize(PageRanges& ranges) {
  11. std::sort(ranges.begin(), ranges.end());
  12. PageRanges::iterator dst = ranges.begin();
  13. for (PageRanges::iterator src = ranges.begin() + 1; src < ranges.end();
  14. ++src) {
  15. if (dst->to + 1 < src->from) {
  16. *++dst = *src;
  17. continue;
  18. }
  19. dst->to = std::max(dst->to, src->to);
  20. }
  21. if (dst < ranges.end())
  22. dst++;
  23. ranges.resize(dst - ranges.begin());
  24. }
  25. } // namespace printing