summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-09-19 11:35:17 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-20 15:19:33 +0000
commitbc48185643b3983fd9620ba2f987ada1478fbdc2 (patch)
treef38e4ac373b47b1907da5a4ca5853a6f93df5624 /xfa
parenteea631943cb9535db8be2885a7c81bda956758e5 (diff)
downloadpdfium-bc48185643b3983fd9620ba2f987ada1478fbdc2.tar.xz
Convert FindNextBreakPos to return position
This CL changes FindNextBreakPos to return the found index instead of requiring a call to GetAt(). This also fixes the issue that we may return -1 from GetAt which would cause issues in the BoundsForWordAt method when it gets shoved into a size_t variable. Change-Id: I29e09de5d0837921a027208fc2471a9b1de287f1 Reviewed-on: https://pdfium-review.googlesource.com/14293 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fde/cfde_texteditengine.cpp29
-rw-r--r--xfa/fde/cfde_texteditengine.h5
2 files changed, 13 insertions, 21 deletions
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index 233d958094..c619a984d2 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -975,11 +975,9 @@ std::pair<size_t, size_t> CFDE_TextEditEngine::BoundsForWordAt(
CFDE_TextEditEngine::Iterator iter(this);
iter.SetAt(idx);
- iter.FindNextBreakPos(true);
- size_t start_idx = iter.GetAt();
- iter.FindNextBreakPos(false);
- size_t end_idx = iter.GetAt();
+ size_t start_idx = iter.FindNextBreakPos(true);
+ size_t end_idx = iter.FindNextBreakPos(false);
return {start_idx, end_idx - start_idx + 1};
}
@@ -1006,19 +1004,13 @@ wchar_t CFDE_TextEditEngine::Iterator::GetChar() const {
return engine_->GetChar(current_position_);
}
-void CFDE_TextEditEngine::Iterator::SetAt(int32_t nIndex) {
- if (nIndex < 0)
- current_position_ = 0;
- else if (static_cast<size_t>(nIndex) >= engine_->GetLength())
+void CFDE_TextEditEngine::Iterator::SetAt(size_t nIndex) {
+ if (static_cast<size_t>(nIndex) >= engine_->GetLength())
current_position_ = engine_->GetLength();
else
current_position_ = nIndex;
}
-int32_t CFDE_TextEditEngine::Iterator::GetAt() const {
- return current_position_;
-}
-
bool CFDE_TextEditEngine::Iterator::IsEOF(bool bPrev) const {
return bPrev ? current_position_ == -1
: current_position_ > -1 &&
@@ -1026,9 +1018,9 @@ bool CFDE_TextEditEngine::Iterator::IsEOF(bool bPrev) const {
engine_->GetLength();
}
-void CFDE_TextEditEngine::Iterator::FindNextBreakPos(bool bPrev) {
+size_t CFDE_TextEditEngine::Iterator::FindNextBreakPos(bool bPrev) {
if (IsEOF(bPrev))
- return;
+ return current_position_ > -1 ? current_position_ : 0;
WordBreakProperty ePreType = WordBreakProperty::kNone;
if (!IsEOF(!bPrev)) {
@@ -1047,14 +1039,14 @@ void CFDE_TextEditEngine::Iterator::FindNextBreakPos(bool bPrev) {
if (wBreak) {
if (IsEOF(bPrev)) {
Next(!bPrev);
- return;
+ break;
}
if (bFirst) {
int32_t nFlags = GetBreakFlagsFor(eCurType, eNextType);
if (nFlags > 0) {
if (BreakFlagsChanged(nFlags, ePreType)) {
Next(!bPrev);
- return;
+ break;
}
Next(bPrev);
wBreak = false;
@@ -1064,7 +1056,7 @@ void CFDE_TextEditEngine::Iterator::FindNextBreakPos(bool bPrev) {
int32_t nFlags = GetBreakFlagsFor(eNextType, eCurType);
if (nFlags <= 0) {
Next(!bPrev);
- return;
+ break;
}
Next(bPrev);
@@ -1072,11 +1064,12 @@ void CFDE_TextEditEngine::Iterator::FindNextBreakPos(bool bPrev) {
if (BreakFlagsChanged(nFlags, eNextType)) {
Next(!bPrev);
Next(!bPrev);
- return;
+ break;
}
}
}
eCurType = eNextType;
bFirst = false;
}
+ return current_position_ > -1 ? current_position_ : 0;
}
diff --git a/xfa/fde/cfde_texteditengine.h b/xfa/fde/cfde_texteditengine.h
index fc5a5fb490..e26487aaf6 100644
--- a/xfa/fde/cfde_texteditengine.h
+++ b/xfa/fde/cfde_texteditengine.h
@@ -44,9 +44,8 @@ class CFDE_TextEditEngine {
void Next(bool bPrev);
wchar_t GetChar() const;
- void SetAt(int32_t nIndex);
- int32_t GetAt() const;
- void FindNextBreakPos(bool bPrev);
+ void SetAt(size_t nIndex);
+ size_t FindNextBreakPos(bool bPrev);
bool IsEOF(bool bPrev) const;
private: