OpenTTD Source: src/autocompletion.h Source File

OpenTTD Source 15.3

autocompletion.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef AUTOCOMPLETION_H
11#define AUTOCOMPLETION_H
12
13#include "textbuf_type.h"
14
15 class AutoCompletion {
16protected:
17 Textbuf *textbuf;
18
19private:
20 std::string initial_buf;
21
22 std::string_view prefix;
23 std::string_view query;
24
25 std::vector<std::string> suggestions;
26 size_t current_suggestion_index;
27
28public:
29 AutoCompletion(Textbuf *textbuf) : textbuf(textbuf)
30 {
31 this->Reset();
32 }
33 virtual ~AutoCompletion() = default;
34
35 bool AutoComplete();
36 void Reset();
37
38private:
39 void InitSuggestions(std::string_view text);
40
41 virtual std::vector<std::string> GetSuggestions(std::string_view prefix, std::string_view query) = 0;
42 virtual void ApplySuggestion(std::string_view prefix, std::string_view suggestion) = 0;
43};
44
45#endif /* AUTOCOMPLETION_H */
AutoCompletion
Definition autocompletion.h:15
AutoCompletion::AutoComplete
bool AutoComplete()
Definition autocompletion.cpp:23
AutoCompletion::query
std::string_view query
Last token of the text. This is used to based the suggestions on.
Definition autocompletion.h:23
AutoCompletion::prefix
std::string_view prefix
Prefix of the text before the last space.
Definition autocompletion.h:22
AutoCompletion::initial_buf
std::string initial_buf
Value of text buffer when we started current suggestion session.
Definition autocompletion.h:20
Textbuf
Helper/buffer for input fields.
Definition textbuf_type.h:30
textbuf_type.h
Stuff related to text buffers.