1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include "readline.hpp"
7 #include "stardict_lib.hpp"
8 
9 //this structure is wrapper and it need for unification
10 //results of search whith return Dicts class
11 struct TSearchResult {
12     std::string bookname;
13     std::string def;
14     std::string exp;
15 
TSearchResultTSearchResult16     TSearchResult(const std::string &bookname_, const std::string &def_, const std::string &exp_)
17         : bookname(bookname_)
18         , def(def_)
19         , exp(exp_)
20     {
21     }
22 };
23 
24 typedef std::vector<TSearchResult> TSearchResultList;
25 
26 //this class is wrapper around Dicts class for easy use
27 //of it
28 class Library : public Libs
29 {
30 public:
Library(bool uinput,bool uoutput,bool colorize_output,bool use_json,bool no_fuzzy)31     Library(bool uinput, bool uoutput, bool colorize_output, bool use_json, bool no_fuzzy)
32         : utf8_input_(uinput)
33         , utf8_output_(uoutput)
34         , colorize_output_(colorize_output)
35         , json_(use_json)
36     {
37         setVerbose(!use_json);
38         setFuzzy(!no_fuzzy);
39     }
40 
41     bool process_phrase(const char *loc_str, IReadLine &io, bool force = false);
42 
43 private:
44     bool utf8_input_;
45     bool utf8_output_;
46     bool colorize_output_;
47     bool json_;
48 
49     void SimpleLookup(const std::string &str, TSearchResultList &res_list);
50     void LookupWithFuzzy(const std::string &str, TSearchResultList &res_list);
51     void LookupWithRule(const std::string &str, TSearchResultList &res_lsit);
52     void LookupData(const std::string &str, TSearchResultList &res_list);
53     void print_search_result(FILE *out, const TSearchResult &res, bool &first_result);
54 };
55