summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpvt_wordrange.h
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-21 13:42:38 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-21 22:34:49 +0000
commit52f69b39403b1ac0df0fdf45698e80e60c0f2def (patch)
tree75c62cdb179bc287f283794600f252783603ad9f /core/fpdfdoc/cpvt_wordrange.h
parent7dd72a3f39c09a7fdc34558061831620bc149420 (diff)
downloadpdfium-52f69b39403b1ac0df0fdf45698e80e60c0f2def.tar.xz
Make CPVT_WordPlace more conformant with the prevailing idioms.
Add relational operators to replace CmpWord(). Leave CmpLine() for the moment as it saves some work. Remove CmpSec() and just inline comparison of the one member. Invert IsExist() as IsEmpty(). There is a big philosophical discussion as to whether things that are empty exist. I say they do, but they're just empty. Rename Default() to Reset(). Default sounds like a noun. Add AdvanceSection() method and call as appropriate. Change-Id: I01d9479f63a4860e0fd228255540d6d94dc24a9f Reviewed-on: https://pdfium-review.googlesource.com/3139 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfdoc/cpvt_wordrange.h')
-rw-r--r--core/fpdfdoc/cpvt_wordrange.h38
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;