[Next]
[Up]
[Previous]
[Contents]
Next: 5. International Support
Up: Aspell .26.2 alpha A
Previous: 3. The Aspell utility
  Contents
Subsections
Note: The information on the C++ library interface is
currently outdated. This section will be updated once the interface stabilizes
which should be within a release or two.
The C++ library is very easy to use however it is not 100% stable yet. Fell
free to use it but be aware that you may need to make minor changes in your
code. To use the library include link it with libaspell.
Declared in file <aspell.hh>
- typedef Suggestions - A Random Access container of strings
- typedef WordList - A Random Access container of string like classes
- typedef SWordList - A Forward container
- aspell(const string &master, const string &personal)
- const Error& error() const
const Error& problem() const
- const char * lang_name() const
- const Suggestions suggest(const string &word) const
- bool check(const string &word) const
- bool check_raw(const string &word) const - checks word
with out changing its case or trying to trim it in any way
- void add_personal(const string &word) - add a word to the personal
word list
- void add_session(const string &word) - add a word to the session
word list
- void save_personal_dict()
- void clear_session()
- void change_personal_dict(const string &base)
- void get_personal(WordList &data) - puts the personal word
list in data
- void get_session(WordList &data) - puts the session word list
in data
- double score(const char *w1, const char *w2) - score the
two words based roughly on how aspell would.
- const string to_soundslike(const string &word) const
- const string to_phoneme(const string &word) const
- const SWordList soundslike(const string &word) const - returns
a list of words in the current wordlist that soundslike word
- bool ignore_replacements()
- bool ignore_replacements(bool) - set whether to store replacements
or not. Returns the previous value.
- void store_replacement(const string& mis, const string &cor)
- enum Problem {none, nonexistent, bad_format, cant_write, duplicates,
unknown _lang, mismatched_lang}
- Problem problem
- string file - the name of the offending file if any
- string add_info
- string message() const - a human readable error message combining
the three variables
- operator bool() const - true if
there is an error, false otherwise
Declared in <as_check.hh>.
- template <class ForwardIterator>
struct CheckResults {
ForwardIterator begin;
ForwardIterator end
operator bool()
};
template <class ForwardIterator [, class StatusFunc]>
CheckResults<ForwardIterator> check (const aspell &sc
, ForwardIterator begin, ForwardIterator end
[, const StatusFunc &print_status])
Checks the data between between begin and end. When it encounters
an unknown word it will return CheckResults. CheckResults::begin
will contain an iterator pointing to the begging of the word and CheckResults::end
will contain an iterator pointing to the end of the word and CheckResults
will evaluate to true. If check reached the end then CheckResults
will evaluate to false.
print_status is an optional generator (a function object this is called with
no augments) that check will call after it successfully checked a word.
I hope to provide some soon but for right now please see the file aspell.cc.
I am also providing a C interface so that C programmers can use my library without
a lot of hassle. Unfortunately because my actually library is C++ code there
are several cravats to linking C to C++ code according to the C++FAQ Lite:
- Your must use your C++ compiler when compiling main() (e.g., for static initialization)
- Your C++ compiler should direct the linking process (e.g., so it can get its
special libraries)
- Your C and C++ compilers probably need to come from same vendor and have compatible
versions (e.g., so they have the same calling conventions)
However depending on the compiler and/or linker you are using you may be able
to get away with not doing one or more of these things. Your mileage may vary.
The C interface library is still not 100 percent finished yet so for now here
is the header file aspell-c.h which should give you a rough idea of
how to use it. Link your code with libaspell to use.
- #include <stdlib.h>
typedef struct aspell aspell;
typedef struct SC_Error aspellError;
typedef enum aspellProblem {
as_none, as_nonexistent, as_bad_format,
as_cant_write, as_duplicates,
as_unknown_lang, as_mismatched_lang
} aspellProblem;
typedef const char * aspellString;
typedef struct aspellSuggestions {
size_t size;
aspellString * data; /* an array of size elements */
void *internal_obj;
} aspellSuggestions;
typedef struct aspellWordList {
size_t size;
aspellString * data;
void *internal_obj;
} aspellWordList;
#ifdef __cplusplus
extern "C" {
#endif
aspell * aspell_new(const char *master, const char *personal);
void aspell_free(aspell *sc);
const aspellError * aspell_error(aspell *sc);
const char * aspell_lang_name(aspell *sc);
aspellSuggestions * aspell_suggest(aspell *sc, const char *word);
int aspell_check(aspell *sc, const char *word);
int aspell_check_raw(aspell *sc, const char *word);
void aspell_add_personal(aspell *sc, const char *word);
void aspell_add_session(aspell *sc, const char *word);
void aspell_save_personal(aspell *sc);
void aspell_clear_session(aspell *sc);
void aspell_change_personal(aspell *sc, const char *base);
aspellWordList * get_personal(aspell *sc); /* not implemented yet */
aspellWordList * get_session(aspell *sc); /* not implemented yet */
void aspell_free_suggestions(aspellSuggestions *wl);
void aspell_free_word_list(aspellWordList *wl);
const char * aspell_error_file(const aspellError *error);
const char * aspell_error_addinfo(const aspellError *error);
aspellProblem aspell_error_problem(const aspellError *error);
const char * aspell_error_message(const aspellError *error);
#ifdef __cplusplus
};
#endif
Read only Aspell methods and functions are thread safe as long as new, delete,
delete[], and STL allocators are thread safe. To the best of my knowledge
gcc and egcs meet these requirements. It is up to the programmer to make sure
multiple threads do not do thing such as change the dictionaries and add or
delete items from the personal or session dictionaries.
[Next]
[Up]
[Previous]
[Contents]
Next: 5. International Support
Up: Aspell .26.2 alpha A
Previous: 3. The Aspell utility
  Contents
1999-01-04