File: speller-c.cpp

package info (click to toggle)
aspell 0.60.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 10,000 kB
  • ctags: 4,862
  • sloc: sh: 48,145; cpp: 22,153; perl: 1,546; ansic: 1,535; makefile: 684; sed: 16
file content (173 lines) | stat: -rw-r--r-- 5,132 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Automatically generated file.  Do not edit directly. */

/* This file is part of The New Aspell
 * Copyright (C) 2001-2002 by Kevin Atkinson under the GNU LGPL
 * license version 2.0 or 2.1.  You should have received a copy of the
 * LGPL license along with this library if you did not you can find it
 * at http://www.gnu.org/.                                              */

#include "convert.hpp"
#include "error.hpp"
#include "mutable_string.hpp"
#include "posib_err.hpp"
#include "speller.hpp"
#include "word_list.hpp"

namespace acommon {

class CanHaveError;
class Config;
struct Error;
class Speller;
class WordList;

extern "C" CanHaveError * new_aspell_speller(Config * config)
{
  PosibErr<Speller *> ret = new_speller(config);
  if (ret.has_err()) {
    return new CanHaveError(ret.release_err());
  } else {
    return ret;
  }
}

extern "C" Speller * to_aspell_speller(CanHaveError * obj)
{
  return static_cast<Speller *>(obj);
}

extern "C" void delete_aspell_speller(Speller * ths)
{
  delete ths;
}

extern "C" unsigned int aspell_speller_error_number(const Speller * ths)
{
  return ths->err_ == 0 ? 0 : 1;
}

extern "C" const char * aspell_speller_error_message(const Speller * ths)
{
  return ths->err_ ? ths->err_->mesg : "";
}

extern "C" const Error * aspell_speller_error(const Speller * ths)
{
  return ths->err_;
}

extern "C" Config * aspell_speller_config(Speller * ths)
{
  return ths->config();
}

extern "C" int aspell_speller_check(Speller * ths, const char * word, int word_size)
{
  ths->temp_str_0.clear();
  ths->to_internal_->convert(word, word_size, ths->temp_str_0);
  unsigned int s0 = ths->temp_str_0.size();
  PosibErr<bool> ret = ths->check(MutableString(ths->temp_str_0.mstr(), s0));
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return -1;
  return ret.data;
}

extern "C" int aspell_speller_add_to_personal(Speller * ths, const char * word, int word_size)
{
  ths->temp_str_0.clear();
  ths->to_internal_->convert(word, word_size, ths->temp_str_0);
  unsigned int s0 = ths->temp_str_0.size();
  PosibErr<void> ret = ths->add_to_personal(MutableString(ths->temp_str_0.mstr(), s0));
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return 0;
  return 1;
}

extern "C" int aspell_speller_add_to_session(Speller * ths, const char * word, int word_size)
{
  ths->temp_str_0.clear();
  ths->to_internal_->convert(word, word_size, ths->temp_str_0);
  unsigned int s0 = ths->temp_str_0.size();
  PosibErr<void> ret = ths->add_to_session(MutableString(ths->temp_str_0.mstr(), s0));
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return 0;
  return 1;
}

extern "C" const WordList * aspell_speller_personal_word_list(Speller * ths)
{
  PosibErr<const WordList *> ret = ths->personal_word_list();
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return 0;
  if (ret.data)
    const_cast<WordList *>(ret.data)->from_internal_ = ths->from_internal_;
  return ret.data;
}

extern "C" const WordList * aspell_speller_session_word_list(Speller * ths)
{
  PosibErr<const WordList *> ret = ths->session_word_list();
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return 0;
  if (ret.data)
    const_cast<WordList *>(ret.data)->from_internal_ = ths->from_internal_;
  return ret.data;
}

extern "C" const WordList * aspell_speller_main_word_list(Speller * ths)
{
  PosibErr<const WordList *> ret = ths->main_word_list();
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return 0;
  if (ret.data)
    const_cast<WordList *>(ret.data)->from_internal_ = ths->from_internal_;
  return ret.data;
}

extern "C" int aspell_speller_save_all_word_lists(Speller * ths)
{
  PosibErr<void> ret = ths->save_all_word_lists();
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return 0;
  return 1;
}

extern "C" int aspell_speller_clear_session(Speller * ths)
{
  PosibErr<void> ret = ths->clear_session();
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return 0;
  return 1;
}

extern "C" const WordList * aspell_speller_suggest(Speller * ths, const char * word, int word_size)
{
  ths->temp_str_0.clear();
  ths->to_internal_->convert(word, word_size, ths->temp_str_0);
  unsigned int s0 = ths->temp_str_0.size();
  PosibErr<const WordList *> ret = ths->suggest(MutableString(ths->temp_str_0.mstr(), s0));
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return 0;
  if (ret.data)
    const_cast<WordList *>(ret.data)->from_internal_ = ths->from_internal_;
  return ret.data;
}

extern "C" int aspell_speller_store_replacement(Speller * ths, const char * mis, int mis_size, const char * cor, int cor_size)
{
  ths->temp_str_0.clear();
  ths->to_internal_->convert(mis, mis_size, ths->temp_str_0);
  unsigned int s0 = ths->temp_str_0.size();
  ths->temp_str_1.clear();
  ths->to_internal_->convert(cor, cor_size, ths->temp_str_1);
  unsigned int s1 = ths->temp_str_1.size();
  PosibErr<bool> ret = ths->store_replacement(MutableString(ths->temp_str_0.mstr(), s0), MutableString(ths->temp_str_1.mstr(), s1));
  ths->err_.reset(ret.release_err());
  if (ths->err_ != 0) return -1;
  return ret.data;
}



}