/src/aspell/modules/speller/default/multi_ws.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | #include "config.hpp" |
3 | | #include "data.hpp" |
4 | | #include "file_util.hpp" |
5 | | #include "fstream.hpp" |
6 | | #include "getdata.hpp" |
7 | | #include "string.hpp" |
8 | | #include "parm_string.hpp" |
9 | | #include "errors.hpp" |
10 | | #include "vector.hpp" |
11 | | |
12 | | #include "gettext.h" |
13 | | |
14 | | namespace { |
15 | | |
16 | | using namespace acommon; |
17 | | using namespace aspeller; |
18 | | |
19 | | typedef Vector<Dict *> Wss; |
20 | | |
21 | | class MultiDictImpl : public Dictionary |
22 | | { |
23 | | public: |
24 | 2.02k | MultiDictImpl() : Dictionary(multi_dict, "MultiDictImpl") {} |
25 | | PosibErr<void> load(ParmString, Config &, DictList *, SpellerImpl *); |
26 | | DictsEnumeration * dictionaries() const; |
27 | | private: |
28 | | Wss wss; |
29 | | }; |
30 | | |
31 | | PosibErr<void> MultiDictImpl::load(ParmString fn, |
32 | | Config & config, |
33 | | DictList * new_dicts, |
34 | | SpellerImpl * speller) |
35 | 2.02k | { |
36 | 2.02k | String dir = figure_out_dir("",fn); |
37 | 2.02k | FStream in; |
38 | 2.02k | RET_ON_ERR(in.open(fn, "r")); |
39 | 2.02k | set_file_name(fn); |
40 | 2.02k | String buf; DataPair d; |
41 | 5.05k | while(getdata_pair(in, d, buf)) |
42 | 3.02k | { |
43 | 3.02k | if (d.key == "add") { |
44 | | |
45 | 3.02k | RET_ON_ERR_SET(add_data_set(d.value, config, new_dicts, speller, dir), Dict *, res); |
46 | 3.02k | RET_ON_ERR(set_check_lang(res->lang()->name(), config)); |
47 | 3.02k | wss.push_back(res); |
48 | | |
49 | 3.02k | } else { |
50 | | |
51 | 0 | return make_err(unknown_key, d.key).with_file(fn, d.line_num); |
52 | |
|
53 | 0 | } |
54 | 3.02k | } |
55 | | |
56 | 2.02k | if (wss.empty()) { |
57 | 0 | return make_err(bad_file_format, fn, |
58 | 0 | _("There must be at least one \"add\" line.")); |
59 | 0 | } |
60 | | |
61 | 2.02k | return no_err; |
62 | 2.02k | } |
63 | | |
64 | | struct Parms |
65 | | { |
66 | | typedef Dict * Value; |
67 | | typedef Wss::const_iterator Iterator; |
68 | | Iterator end; |
69 | 0 | Parms(Iterator e) : end(e) {} |
70 | 0 | bool endf(Iterator i) const {return i == end;} |
71 | 0 | Value end_state() const {return 0;} |
72 | 0 | Value deref(Iterator i) const {return *i;} |
73 | | }; |
74 | | |
75 | | DictsEnumeration * MultiDictImpl::dictionaries() const |
76 | 0 | { |
77 | 0 | return new MakeEnumeration<Parms>(wss.begin(), wss.end()); |
78 | 0 | } |
79 | | } |
80 | | |
81 | | namespace aspeller { |
82 | | |
83 | | MultiDict * new_default_multi_dict() |
84 | 2.02k | { |
85 | 2.02k | return new MultiDictImpl(); |
86 | 2.02k | } |
87 | | |
88 | | } |