diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-07-13 13:40:06 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-13 18:26:14 +0000 |
commit | 3628f8b06e4518c81971782455270d5db4ff91c9 (patch) | |
tree | 25b61cbb0d783ba59947341ff6d1dc80613acdb8 /core/fpdfdoc/cpvt_wordrange.h | |
parent | 469186a47d6ac939acbd80754ed9be5c085bdc22 (diff) | |
download | pdfium-3628f8b06e4518c81971782455270d5db4ff91c9.tar.xz |
Move CPWL_Utils::OverlapWordRange to CPVT_WordRange::Intersect
This method only deals with CPVT_WordRange objects so move to the correct class.
Change-Id: If5f28178301affa8633f8ef8e89894dfb94f1ac9
Reviewed-on: https://pdfium-review.googlesource.com/7713
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfdoc/cpvt_wordrange.h')
-rw-r--r-- | core/fpdfdoc/cpvt_wordrange.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/fpdfdoc/cpvt_wordrange.h b/core/fpdfdoc/cpvt_wordrange.h index ed06d6f0de..638f6c17c0 100644 --- a/core/fpdfdoc/cpvt_wordrange.h +++ b/core/fpdfdoc/cpvt_wordrange.h @@ -7,6 +7,7 @@ #ifndef CORE_FPDFDOC_CPVT_WORDRANGE_H_ #define CORE_FPDFDOC_CPVT_WORDRANGE_H_ +#include <algorithm> #include <utility> #include "core/fpdfdoc/cpvt_wordplace.h" @@ -41,6 +42,16 @@ struct CPVT_WordRange { Normalize(); } + CPVT_WordRange Intersect(const CPVT_WordRange& that) const { + if (that.EndPos < BeginPos || that.BeginPos > EndPos || + EndPos < that.BeginPos || BeginPos > that.EndPos) { + return CPVT_WordRange(); + } + + return CPVT_WordRange(std::max(BeginPos, that.BeginPos), + std::min(EndPos, that.EndPos)); + } + inline bool IsEmpty() const { return BeginPos == EndPos; } inline bool operator==(const CPVT_WordRange& wr) const { return wr.BeginPos == BeginPos && wr.EndPos == EndPos; |