1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FPDFTEXT_CPDF_TEXTPAGEFIND_H_ 8 #define CORE_FPDFTEXT_CPDF_TEXTPAGEFIND_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxcrt/fx_coordinates.h" 14 #include "core/fxcrt/fx_string.h" 15 #include "core/fxcrt/fx_system.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 #include "third_party/base/optional.h" 18 19 class CPDF_TextPage; 20 21 class CPDF_TextPageFind { 22 public: 23 struct Options { 24 bool bMatchCase = false; 25 bool bMatchWholeWord = false; 26 bool bConsecutive = false; 27 }; 28 29 static std::unique_ptr<CPDF_TextPageFind> Create( 30 const CPDF_TextPage* pTextPage, 31 const WideString& findwhat, 32 const Options& options, 33 Optional<size_t> startPos); 34 35 ~CPDF_TextPageFind(); 36 37 bool FindNext(); 38 bool FindPrev(); 39 int GetCurOrder() const; 40 int GetMatchedCount() const; 41 42 private: 43 CPDF_TextPageFind(const CPDF_TextPage* pTextPage, 44 const std::vector<WideString>& findwhat_array, 45 const Options& options, 46 Optional<size_t> startPos); 47 48 // Should be called immediately after construction. 49 bool FindFirst(); 50 51 int GetCharIndex(int index) const; 52 53 UnownedPtr<const CPDF_TextPage> const m_pTextPage; 54 const WideString m_strText; 55 const std::vector<WideString> m_csFindWhatArray; 56 Optional<size_t> m_findNextStart; 57 Optional<size_t> m_findPreStart; 58 int m_resStart = 0; 59 int m_resEnd = -1; 60 const Options m_options; 61 }; 62 63 #endif // CORE_FPDFTEXT_CPDF_TEXTPAGEFIND_H_ 64