diff options
Diffstat (limited to 'core/fpdfdoc')
-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; |