summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/range/range_mac.mm
blob: 3f78fb618e39fc410caa64772f0fd82fd0d172e7 (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
30
31
32
33
34
35
36
// 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 "ui/gfx/range/range.h"

#include <limits>

#include "base/logging.h"

namespace gfx {

Range::Range(const NSRange& range) {
  *this = range;
}

Range& Range::operator=(const NSRange& range) {
  if (range.location == NSNotFound) {
    DCHECK_EQ(0U, range.length);
    *this = InvalidRange();
  } else {
    set_start(range.location);
    // Don't overflow |end_|.
    DCHECK_LE(range.length, std::numeric_limits<size_t>::max() - start());
    set_end(start() + range.length);
  }
  return *this;
}

NSRange Range::ToNSRange() const {
  if (!IsValid())
    return NSMakeRange(NSNotFound, 0);
  return NSMakeRange(GetMin(), length());
}

}  // namespace gfx