1 /* searchtextstorage.hh
2  * This file belongs to Worker, a file manager for UN*X/X11.
3  * Copyright (C) 2008-2015 Ralf Hoffmann.
4  * You can contact me at: ralf@boomerangsworld.de
5  *   or http://www.boomerangsworld.de/worker
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 #ifndef SEARCHTEXTSTORAGE_HH
23 #define SEARCHTEXTSTORAGE_HH
24 
25 #include "aguixdefs.h"
26 #include <string>
27 #include <utility>
28 #include "compregex.hh"
29 
30 class TextStorage;
31 class TextView;
32 
33 class SearchTextStorage
34 {
35 public:
36     SearchTextStorage( TextStorage &ts );
37     virtual ~SearchTextStorage();
38 
39     void search( const std::string &search_string );
40     void searchBackwards( const std::string &search_string );
41     void highlightCurMatch( TextView &tv );
42 
43     void setSearchStartLine( int line );
44 
45     int getCurMatchLine() const;
46 private:
47     TextStorage &m_ts;
48     std::string m_last_search_string;
49     std::pair<int, int> m_start_search;
50     struct {
51         int line;
52         int start_offset;
53         int end_offset;
54     } m_cur_match;
55 
56     CompRegEx m_cre;
57 
58     int prevPos( std::pair< int, int > &pos );
59 };
60 
61 #endif
62