From 52f69b39403b1ac0df0fdf45698e80e60c0f2def Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 21 Mar 2017 13:42:38 -0700 Subject: 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 Reviewed-by: dsinclair --- core/fpdfdoc/cpvt_wordplace.h | 80 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'core/fpdfdoc/cpvt_wordplace.h') 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; -- cgit v1.2.3