teditor  1.8.0@@fee5e94
Terminal based editor written in C++
isearch.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 #include <unordered_map>
6 #include "cmd_msg_bar.h"
7 #include "logger.h"
8 
9 
10 namespace teditor {
11 
12 class Buffer;
13 class CmdMsgBar;
14 class Window;
15 
19 class ISearch: public Choices {
20 public:
21  ISearch(Window& w, bool _noCase);
22 
23  const std::string& at(int idx) const;
24  int size() const { return ml.length(); }
25  bool updateChoices(const std::string& str);
26  std::string getFinalStr(int idx, const std::string& str) const;
27  void updateMainBuffer(CmdMsgBar& cmBar);
28  void resetLocations(CmdMsgBar& cmBar);
29 
31  void reset();
32 
34  bool emptyAt(int i) const { return matches.find(i) == matches.end(); }
35 
37  const std::vector<int>& matchesAt(int i) const;
38 
39 private:
41  Window& win;
43  Buffer& ml;
45  std::string curr;
47  std::unordered_map<int, std::vector<int>> matches;
49  bool noCase;
50 
51  void searchBuffer();
52  void searchLine(const std::string& str, std::vector<int>& res);
53  void iSearchLine(const std::string& str, std::vector<int>& res);
54 };
55 
56 } // end namespace teditor
teditor::ISearch::reset
void reset()
Definition: isearch.cpp:48
teditor::CmdMsgBar::getOptLoc
int getOptLoc() const
Definition: cmd_msg_bar.h:72
teditor::ISearch::matchesAt
const std::vector< int > & matchesAt(int i) const
Definition: isearch.cpp:34
logger.h
teditor::strFind
bool strFind(const std::string &line, const std::string &str)
Definition: utils.cpp:237
teditor::CmdMsgBar::setOptLoc
void setOptLoc(int loc)
Definition: cmd_msg_bar.h:73
teditor::CmdMsgBar::setStartLine
void setStartLine(int line)
Definition: cmd_msg_bar.h:76
teditor::Buffer::length
int length() const
Definition: buffer.h:92
teditor::ISearch::updateChoices
bool updateChoices(const std::string &str)
Definition: isearch.cpp:40
teditor::CmdMsgBar
Definition: cmd_msg_bar.h:50
teditor::Buffer::getPoint
const Point & getPoint() const
Definition: buffer.h:165
teditor::Pos2d::y
T y
Definition: pos2d.h:16
teditor::Line::get
const std::string & get() const
Definition: line.h:51
teditor::Choices
Definition: cmd_msg_bar.h:15
teditor::Buffer::at
Line & at(int idx)
Definition: buffer.h:98
teditor::ISearch::size
int size() const
Definition: isearch.h:24
isearch.h
teditor::iStrFindEmpty
bool iStrFindEmpty(const std::string &line, const std::string &str)
Definition: isearch.cpp:15
teditor::Window
Definition: window.h:15
cmd_msg_bar.h
ASSERT
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
teditor::ISearch::emptyAt
bool emptyAt(int i) const
Definition: isearch.h:34
buffer.h
teditor::ISearch::getFinalStr
std::string getFinalStr(int idx, const std::string &str) const
Definition: isearch.cpp:26
teditor::ISearch::ISearch
ISearch(Window &w, bool _noCase)
Definition: isearch.cpp:21
teditor::ISearch::updateMainBuffer
void updateMainBuffer(CmdMsgBar &cmBar)
Definition: isearch.cpp:68
teditor::ISearch::resetLocations
void resetLocations(CmdMsgBar &cmBar)
Definition: isearch.cpp:63
window.h
teditor::iStrFind
bool iStrFind(const std::string &line, const std::string &str)
Definition: utils.cpp:241
teditor::Buffer::gotoLine
void gotoLine(int lineNum, const Point &dim)
Definition: buffer.cpp:797
teditor::ISearch
Incremental search support used by Ctrl-F command.
Definition: isearch.h:19
teditor::ISearch::at
const std::string & at(int idx) const
Definition: isearch.cpp:30
teditor::strFindEmpty
bool strFindEmpty(const std::string &line, const std::string &str)
Definition: isearch.cpp:10
teditor::Window::dim
const Pos2di & dim() const
Definition: window.h:59
teditor::Buffer
Definition: buffer.h:25
teditor
Definition: any.hpp:10