Nuspell
spellchecker
finder.hxx
Go to the documentation of this file.
1 /* Copyright 2016-2020 Dimitrij Mijoski
2  *
3  * This file is part of Nuspell.
4  *
5  * Nuspell is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Nuspell is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Nuspell. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
24 #ifndef NUSPELL_FINDER_HXX
25 #define NUSPELL_FINDER_HXX
26 
27 #include "nuspell_export.h"
28 
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 #ifdef _MSC_VER
34 #define NUSPELL_MSVC_PRAGMA_WARNING(x) __pragma(warning(x))
35 #else
36 #define NUSPELL_MSVC_PRAGMA_WARNING(x)
37 #endif
38 NUSPELL_MSVC_PRAGMA_WARNING(push)
39 NUSPELL_MSVC_PRAGMA_WARNING(disable : 4251)
40 
41 namespace nuspell {
42 inline namespace v4 {
43 
44 NUSPELL_EXPORT auto append_default_dir_paths(std::vector<std::string>& paths)
45  -> void;
46 
47 NUSPELL_EXPORT auto
48 append_libreoffice_dir_paths(std::vector<std::string>& paths) -> void;
49 
50 NUSPELL_EXPORT auto search_dir_for_dicts(
51  const std::string& dir_path,
52  std::vector<std::pair<std::string, std::string>>& dict_list) -> void;
53 
54 NUSPELL_EXPORT auto search_dirs_for_dicts(
55  const std::vector<std::string>& dir_paths,
56  std::vector<std::pair<std::string, std::string>>& dict_list) -> void;
57 
58 NUSPELL_EXPORT auto search_default_dirs_for_dicts(
59  std::vector<std::pair<std::string, std::string>>& dict_list) -> void;
60 
61 NUSPELL_EXPORT auto find_dictionary(
62  const std::vector<std::pair<std::string, std::string>>& dict_list,
63  const std::string& dict_name)
64  -> std::vector<std::pair<std::string, std::string>>::const_iterator;
65 
71 class NUSPELL_EXPORT Dict_Finder_For_CLI_Tool {
72  std::vector<std::string> dir_paths;
73  std::vector<std::pair<std::string, std::string>> dict_multimap;
74 
75  public:
77  auto& get_dir_paths() const { return dir_paths; }
78  auto& get_dictionaries() const { return dict_multimap; }
79  auto get_dictionary_path(const std::string& dict) const -> std::string;
80 };
81 
82 class NUSPELL_DEPRECATED_EXPORT Finder {
83  using Dict_List = std::vector<std::pair<std::string, std::string>>;
84 
85  std::vector<std::string> paths;
86  Dict_List dictionaries;
87 
88  public:
89  using const_iterator = Dict_List::const_iterator;
90 
91  auto add_default_dir_paths() -> void;
92  auto add_libreoffice_dir_paths() -> void;
93  auto search_for_dictionaries() -> void;
94 
95  auto static search_all_dirs_for_dicts() -> Finder;
96 
97  auto& get_dir_paths() const { return paths; }
98  auto& get_dictionaries() const { return dictionaries; }
99  auto begin() const { return dictionaries.begin(); }
100  auto end() const { return dictionaries.end(); }
101  auto find(const std::string& dict) const -> const_iterator;
102  auto equal_range(const std::string& dict) const
103  -> std::pair<const_iterator, const_iterator>;
104  auto get_dictionary_path(const std::string& dict) const -> std::string;
105 };
106 } // namespace v4
107 } // namespace nuspell
108 NUSPELL_MSVC_PRAGMA_WARNING(pop)
109 #endif // NUSPELL_FINDER_HXX
nuspell::v4::append_default_dir_paths
auto append_default_dir_paths(std::vector< string > &paths) -> void
Append the paths of the default directories to be searched for dictionaries.
Definition: finder.cxx:71
nuspell
Library main namespace.
Definition: aff_data.cxx:31
nuspell::v4::search_dirs_for_dicts
auto search_dirs_for_dicts(const std::vector< string > &dir_paths, std::vector< std::pair< string, string >> &dict_list) -> void
Search the directories for dictionaries.
Definition: finder.cxx:487
nuspell::v4::append_libreoffice_dir_paths
auto append_libreoffice_dir_paths(std::vector< std::string > &paths) -> void
Append the paths of the LibreOffice's directories to be searched for dictionaries.
Definition: finder.cxx:300
nuspell::v4::Dict_Finder_For_CLI_Tool
Don't use this except from Nuspell CLI tool.
Definition: finder.hxx:71
nuspell::v4::Finder
Definition: finder.hxx:82
nuspell::v4::search_dir_for_dicts
auto search_dir_for_dicts(const string &dir_path, vector< pair< string, string >> &dict_list) -> void
Search a directory for dictionaries.
Definition: finder.cxx:444
nuspell::v4::search_default_dirs_for_dicts
auto search_default_dirs_for_dicts(std::vector< std::pair< std::string, std::string >> &dict_list) -> void
Search the default directories for dictionaries.
Definition: finder.cxx:503
nuspell::v4::find_dictionary
auto find_dictionary(const std::vector< std::pair< std::string, std::string >> &dict_list, const std::string &dict_name) -> std::vector< std::pair< std::string, std::string >>::const_iterator
Find dictionary path given the name.
Definition: finder.cxx:521