xref: /aosp_15_r20/external/pdfium/core/fpdfdoc/cpvt_wordrange.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2016 The PDFium Authors
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 
15 struct CPVT_WordRange {
16   CPVT_WordRange() = default;
17 
CPVT_WordRangeCPVT_WordRange18   CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end)
19       : BeginPos(begin), EndPos(end) {
20     Normalize();
21   }
22 
IsEmptyCPVT_WordRange23   inline bool IsEmpty() const { return BeginPos == EndPos; }
24   inline bool operator==(const CPVT_WordRange& wr) const {
25     return wr.BeginPos == BeginPos && wr.EndPos == EndPos;
26   }
27   inline bool operator!=(const CPVT_WordRange& wr) const {
28     return !(*this == wr);
29   }
30 
NormalizeCPVT_WordRange31   void Normalize() {
32     if (BeginPos > EndPos)
33       std::swap(BeginPos, EndPos);
34   }
35 
36   CPVT_WordPlace BeginPos;
37   CPVT_WordPlace EndPos;
38 };
39 
40 #endif  // CORE_FPDFDOC_CPVT_WORDRANGE_H_
41