From 3628f8b06e4518c81971782455270d5db4ff91c9 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 13 Jul 2017 13:40:06 -0400 Subject: 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 Reviewed-by: Tom Sepez --- core/fpdfdoc/cpvt_wordrange.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'core/fpdfdoc/cpvt_wordrange.h') 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 #include #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; -- cgit v1.2.3