summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_variabletext.cpp15
-rw-r--r--core/fpdfdoc/cpvt_wordplace.h80
-rw-r--r--core/fpdfdoc/cpvt_wordrange.h38
-rw-r--r--core/fpdfdoc/csection.cpp6
4 files changed, 68 insertions, 71 deletions
diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp
index 24dd9b065d..4e46969dc4 100644
--- a/core/fpdfdoc/cpdf_variabletext.cpp
+++ b/core/fpdfdoc/cpdf_variabletext.cpp
@@ -432,9 +432,7 @@ void CPDF_VariableText::SetText(const CFX_WideString& swText) {
if (swText.GetAt(i + 1) == 0x0A)
i += 1;
- wp.nSecIndex++;
- wp.nLineIndex = 0;
- wp.nWordIndex = -1;
+ wp.AdvanceSection();
AddSection(wp, secinfo);
}
break;
@@ -443,9 +441,7 @@ void CPDF_VariableText::SetText(const CFX_WideString& swText) {
if (swText.GetAt(i + 1) == 0x0D)
i += 1;
- wp.nSecIndex++;
- wp.nLineIndex = 0;
- wp.nWordIndex = -1;
+ wp.AdvanceSection();
AddSection(wp, secinfo);
}
break;
@@ -537,7 +533,7 @@ CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace(
return GetEndWordPlace();
CSection* pSection = m_SectionArray[place.nSecIndex].get();
- if (place.WordCmp(pSection->GetBeginWordPlace()) > 0)
+ if (place > pSection->GetBeginWordPlace())
return pSection->GetPrevWordPlace(place);
if (!pdfium::IndexInBounds(m_SectionArray, place.nSecIndex - 1))
return GetBeginWordPlace();
@@ -552,7 +548,7 @@ CPVT_WordPlace CPDF_VariableText::GetNextWordPlace(
return GetEndWordPlace();
CSection* pSection = m_SectionArray[place.nSecIndex].get();
- if (place.WordCmp(pSection->GetEndWordPlace()) < 0)
+ if (place < pSection->GetEndWordPlace())
return pSection->GetNextWordPlace(place);
if (!pdfium::IndexInBounds(m_SectionArray, place.nSecIndex + 1))
return GetEndWordPlace();
@@ -638,8 +634,7 @@ CPVT_WordPlace CPDF_VariableText::GetDownWordPlace(
return pSection->SearchWordPlace(pt.x - pSection->m_SecInfo.rcSection.left,
temp);
}
- ++temp.nSecIndex;
- temp.nLineIndex = 0;
+ temp.AdvanceSection();
if (!pdfium::IndexInBounds(m_SectionArray, temp.nSecIndex))
return place;
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;
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;
diff --git a/core/fpdfdoc/csection.cpp b/core/fpdfdoc/csection.cpp
index 6198d780fd..b6f45a274c 100644
--- a/core/fpdfdoc/csection.cpp
+++ b/core/fpdfdoc/csection.cpp
@@ -237,14 +237,14 @@ void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) {
void CSection::ClearWords(const CPVT_WordRange& PlaceRange) {
CPVT_WordPlace SecBeginPos = GetBeginWordPlace();
CPVT_WordPlace SecEndPos = GetEndWordPlace();
- if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) {
- if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) {
+ if (PlaceRange.BeginPos >= SecBeginPos) {
+ if (PlaceRange.EndPos <= SecEndPos) {
ClearMidWords(PlaceRange.BeginPos.nWordIndex,
PlaceRange.EndPos.nWordIndex);
} else {
ClearRightWords(PlaceRange.BeginPos.nWordIndex);
}
- } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) {
+ } else if (PlaceRange.EndPos <= SecEndPos) {
ClearLeftWords(PlaceRange.EndPos.nWordIndex);
} else {
m_WordArray.clear();