summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpvt_wordplace.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_wordplace.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_wordplace.h')
-rw-r--r--core/fpdfdoc/cpvt_wordplace.h80
1 files changed, 40 insertions, 40 deletions
diff --git a/core/fpdfdoc/cpvt_wordplace.h b/core/fpdfdoc/cpvt_wordplace.h
index f4a6b087b9..c0a1a9cd5c 100644
--- a/core/fpdfdoc/cpvt_wordplace.h
+++ b/core/fpdfdoc/cpvt_wordplace.h
@@ -14,55 +14,55 @@ struct CPVT_WordPlace {
CPVT_WordPlace(int32_t other_nSecIndex,
int32_t other_nLineIndex,
- int32_t other_nWordIndex) {
- nSecIndex = other_nSecIndex;
- nLineIndex = other_nLineIndex;
- nWordIndex = other_nWordIndex;
+ int32_t other_nWordIndex)
+ : nSecIndex(other_nSecIndex),
+ nLineIndex(other_nLineIndex),
+ nWordIndex(other_nWordIndex) {}
+
+ void Reset() {
+ nSecIndex = -1;
+ nLineIndex = -1;
+ nWordIndex = -1;
}
- void Default() { nSecIndex = nLineIndex = nWordIndex = -1; }
+ void AdvanceSection() {
+ nSecIndex++;
+ nLineIndex = 0;
+ nWordIndex = -1;
+ }
- bool operator==(const CPVT_WordPlace& wp) const {
+ inline bool operator==(const CPVT_WordPlace& wp) const {
return wp.nSecIndex == nSecIndex && wp.nLineIndex == nLineIndex &&
wp.nWordIndex == nWordIndex;
}
-
- bool operator!=(const CPVT_WordPlace& wp) const { return !(*this == wp); }
-
- inline int32_t WordCmp(const CPVT_WordPlace& wp) const {
- if (nSecIndex > wp.nSecIndex)
- return 1;
- if (nSecIndex < wp.nSecIndex)
- return -1;
- if (nLineIndex > wp.nLineIndex)
- return 1;
- if (nLineIndex < wp.nLineIndex)
- return -1;
- if (nWordIndex > wp.nWordIndex)
- return 1;
- if (nWordIndex < wp.nWordIndex)
- return -1;
- return 0;
+ inline bool operator!=(const CPVT_WordPlace& wp) const {
+ return !(*this == wp);
}
-
- inline int32_t LineCmp(const CPVT_WordPlace& wp) const {
- if (nSecIndex > wp.nSecIndex)
- return 1;
- if (nSecIndex < wp.nSecIndex)
- return -1;
- if (nLineIndex > wp.nLineIndex)
- return 1;
- if (nLineIndex < wp.nLineIndex)
- return -1;
- return 0;
+ inline bool operator<(const CPVT_WordPlace& wp) const {
+ if (nSecIndex != wp.nSecIndex)
+ return nSecIndex < wp.nSecIndex;
+ if (nLineIndex != wp.nLineIndex)
+ return nLineIndex < wp.nLineIndex;
+ return nWordIndex < wp.nWordIndex;
+ }
+ inline bool operator>(const CPVT_WordPlace& wp) const {
+ if (nSecIndex != wp.nSecIndex)
+ return nSecIndex > wp.nSecIndex;
+ if (nLineIndex != wp.nLineIndex)
+ return nLineIndex > wp.nLineIndex;
+ return nWordIndex > wp.nWordIndex;
+ }
+ inline bool operator<=(const CPVT_WordPlace& wp) const {
+ return *this < wp || *this == wp;
+ }
+ inline bool operator>=(const CPVT_WordPlace& wp) const {
+ return *this > wp || *this == wp;
}
- inline int32_t SecCmp(const CPVT_WordPlace& wp) const {
- if (nSecIndex > wp.nSecIndex)
- return 1;
- if (nSecIndex < wp.nSecIndex)
- return -1;
- return 0;
+ inline int32_t LineCmp(const CPVT_WordPlace& wp) const {
+ if (nSecIndex != wp.nSecIndex)
+ return nSecIndex - wp.nSecIndex;
+ return nLineIndex - wp.nLineIndex;
}
int32_t nSecIndex;