Debian Codegraph @

src/af/xap/xp/xap_Dictionary.h

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998,1999 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20
21 #ifndef XAP_DICTIONARY_H
22 #define XAP_DICTIONARY_H
23
24 #include <stdio.h>
25
26 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
27 * so even if it's commented out in-file that's still a lot of work for
28 * the preprocessor to do...
29 */
30 #ifndef UT_TYPES_H
31 #include "ut_types.h"
32 #endif
33 #include "ut_hash.h"
34
35 /*
36 A simple custom dictionary class, which allows the user to add words
37 which aren't in the standard dictionary. The contents are stored as
38 UTF-8 plaintext, with one word per line.
39 */
40 class ABI_EXPORT XAP_Dictionary
41 {
42 public:
43 XAP_Dictionary(const char * szFilename);
44 ~XAP_Dictionary();
45
46 const char * getShortName(void) const;
47
48 bool load(void);
49 bool save(void);
50 UT_uint32 countCommonChars(UT_UCSChar * pszNeedle, UT_UCSChar *pszHaystack);
51 void suggestWord(UT_GenericVector<UT_UCSChar *> * pVecSuggestions, const UT_UCSChar * pWord, UT_uint32 len);
52 bool addWord(const char * pWord);
53 bool addWord(const UT_UCSChar * pWord, UT_uint32 len);
54 bool isWord(const UT_UCSChar * pWord, UT_uint32 len) const;
55
56 protected:
57 bool _openFile(const char * mode);
58 UT_uint32 _writeBytes(const UT_Byte * pBytes, UT_uint32 length);
59 bool _writeBytes(const UT_Byte * sz);
60 bool _closeFile(void);
61 void _abortFile(void);
62
63 bool _parseUTF8(void);
64 void _outputUTF8(const UT_UCSChar * data, UT_uint32 length);
65
66 const char * m_szFilename;
67
68 bool m_bDirty;
69 UT_GenericStringMap<UT_UCSChar *> m_hashWords;
70
71 private:
72 FILE * m_fp;
73 };
74
75
76 #endif /* XAP_DICTIONARY_H */