1 // Copyright 2016 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FPDFDOC_CPVT_WORDRANGE_H_
8 #define CORE_FPDFDOC_CPVT_WORDRANGE_H_
9 
10 #include <algorithm>
11 #include <utility>
12 
13 #include "core/fpdfdoc/cpvt_wordplace.h"
14 #include "core/fxcrt/fx_system.h"
15 
16 struct CPVT_WordRange {
17   CPVT_WordRange() = default;
18 
CPVT_WordRangeCPVT_WordRange19   CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end)
20       : BeginPos(begin), EndPos(end) {
21     Normalize();
22   }
23 
IsEmptyCPVT_WordRange24   inline bool IsEmpty() const { return BeginPos == EndPos; }
25   inline bool operator==(const CPVT_WordRange& wr) const {
26     return wr.BeginPos == BeginPos && wr.EndPos == EndPos;
27   }
28   inline bool operator!=(const CPVT_WordRange& wr) const {
29     return !(*this == wr);
30   }
31 
NormalizeCPVT_WordRange32   void Normalize() {
33     if (BeginPos > EndPos)
34       std::swap(BeginPos, EndPos);
35   }
36 
37   CPVT_WordPlace BeginPos;
38   CPVT_WordPlace EndPos;
39 };
40 
41 #endif  // CORE_FPDFDOC_CPVT_WORDRANGE_H_
42