• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/fpdfdoc/cpvt_wordplace.h"
11 #include "core/fxcrt/fx_system.h"
12 
13 struct CPVT_WordRange {
CPVT_WordRangeCPVT_WordRange14   CPVT_WordRange() {}
15 
CPVT_WordRangeCPVT_WordRange16   CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) {
17     Set(begin, end);
18   }
19 
DefaultCPVT_WordRange20   void Default() {
21     BeginPos.Default();
22     EndPos.Default();
23   }
24 
SetCPVT_WordRange25   void Set(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) {
26     BeginPos = begin;
27     EndPos = end;
28     SwapWordPlace();
29   }
30 
SetBeginPosCPVT_WordRange31   void SetBeginPos(const CPVT_WordPlace& begin) {
32     BeginPos = begin;
33     SwapWordPlace();
34   }
35 
SetEndPosCPVT_WordRange36   void SetEndPos(const CPVT_WordPlace& end) {
37     EndPos = end;
38     SwapWordPlace();
39   }
40 
IsExistCPVT_WordRange41   bool IsExist() const { return BeginPos != EndPos; }
42 
43   bool operator!=(const CPVT_WordRange& wr) const {
44     return wr.BeginPos != BeginPos || wr.EndPos != EndPos;
45   }
46 
SwapWordPlaceCPVT_WordRange47   void SwapWordPlace() {
48     if (BeginPos.WordCmp(EndPos) > 0) {
49       CPVT_WordPlace place = EndPos;
50       EndPos = BeginPos;
51       BeginPos = place;
52     }
53   }
54 
55   CPVT_WordPlace BeginPos;
56   CPVT_WordPlace EndPos;
57 };
58 
59 #endif  // CORE_FPDFDOC_CPVT_WORDRANGE_H_
60