diff options
Diffstat (limited to 'core/fpdfdoc/cpvt_wordrange.h')
-rw-r--r-- | core/fpdfdoc/cpvt_wordrange.h | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/core/fpdfdoc/cpvt_wordrange.h b/core/fpdfdoc/cpvt_wordrange.h index b291e50e53..ed06d6f0de 100644 --- a/core/fpdfdoc/cpvt_wordrange.h +++ b/core/fpdfdoc/cpvt_wordrange.h @@ -7,49 +7,51 @@ #ifndef CORE_FPDFDOC_CPVT_WORDRANGE_H_ #define CORE_FPDFDOC_CPVT_WORDRANGE_H_ +#include <utility> + #include "core/fpdfdoc/cpvt_wordplace.h" #include "core/fxcrt/fx_system.h" struct CPVT_WordRange { CPVT_WordRange() {} - CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) { - Set(begin, end); + CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) + : BeginPos(begin), EndPos(end) { + Normalize(); } - void Default() { - BeginPos.Default(); - EndPos.Default(); + void Reset() { + BeginPos.Reset(); + EndPos.Reset(); } void Set(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) { BeginPos = begin; EndPos = end; - SwapWordPlace(); + Normalize(); } void SetBeginPos(const CPVT_WordPlace& begin) { BeginPos = begin; - SwapWordPlace(); + Normalize(); } void SetEndPos(const CPVT_WordPlace& end) { EndPos = end; - SwapWordPlace(); + Normalize(); } - bool IsExist() const { return BeginPos != EndPos; } - - bool operator!=(const CPVT_WordRange& wr) const { - return wr.BeginPos != BeginPos || wr.EndPos != EndPos; + inline bool IsEmpty() const { return BeginPos == EndPos; } + inline bool operator==(const CPVT_WordRange& wr) const { + return wr.BeginPos == BeginPos && wr.EndPos == EndPos; + } + inline bool operator!=(const CPVT_WordRange& wr) const { + return !(*this == wr); } - void SwapWordPlace() { - if (BeginPos.WordCmp(EndPos) > 0) { - CPVT_WordPlace place = EndPos; - EndPos = BeginPos; - BeginPos = place; - } + void Normalize() { + if (BeginPos > EndPos) + std::swap(BeginPos, EndPos); } CPVT_WordPlace BeginPos; |