~ubuntu-branches/debian/wheezy/mudlet/wheezy

« back to all changes in this revision

Viewing changes to src/hunspell/csutil.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Craig Small
  • Date: 2011-05-14 20:12:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110514201249-184gqx5jjqam02lg
Tags: 2.0-rc5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef __CSUTILHXX__
2
 
#define __CSUTILHXX__
3
 
 
4
 
#include "hunvisapi.h"
5
 
 
6
 
// First some base level utility routines
7
 
 
8
 
#include <string.h>
9
 
#include "w_char.hxx"
10
 
#include "htypes.hxx"
11
 
 
12
 
#ifdef MOZILLA_CLIENT
13
 
#include "nscore.h" // for mozalloc headers
14
 
#endif
15
 
 
16
 
// casing
17
 
#define NOCAP   0
18
 
#define INITCAP 1
19
 
#define ALLCAP  2
20
 
#define HUHCAP  3
21
 
#define HUHINITCAP  4
22
 
 
23
 
// default encoding and keystring
24
 
#define SPELL_ENCODING  "ISO8859-1"
25
 
#define SPELL_KEYSTRING "qwertyuiop|asdfghjkl|zxcvbnm" 
26
 
 
27
 
// default morphological fields
28
 
#define MORPH_STEM        "st:"
29
 
#define MORPH_ALLOMORPH   "al:"
30
 
#define MORPH_POS         "po:"
31
 
#define MORPH_DERI_PFX    "dp:"
32
 
#define MORPH_INFL_PFX    "ip:"
33
 
#define MORPH_TERM_PFX    "tp:"
34
 
#define MORPH_DERI_SFX    "ds:"
35
 
#define MORPH_INFL_SFX    "is:"
36
 
#define MORPH_TERM_SFX    "ts:"
37
 
#define MORPH_SURF_PFX    "sp:"
38
 
#define MORPH_FREQ        "fr:"
39
 
#define MORPH_PHON        "ph:"
40
 
#define MORPH_HYPH        "hy:"
41
 
#define MORPH_PART        "pa:"
42
 
#define MORPH_FLAG        "fl:"
43
 
#define MORPH_HENTRY      "_H:"
44
 
#define MORPH_TAG_LEN     strlen(MORPH_STEM)
45
 
 
46
 
#define MSEP_FLD ' '
47
 
#define MSEP_REC '\n'
48
 
#define MSEP_ALT '\v'
49
 
 
50
 
// default flags
51
 
#define DEFAULTFLAGS   65510
52
 
#define FORBIDDENWORD  65510
53
 
#define ONLYUPCASEFLAG 65511
54
 
 
55
 
// convert UTF-16 characters to UTF-8
56
 
LIBHUNSPELL_DLL_EXPORTED char * u16_u8(char * dest, int size, const w_char * src, int srclen);
57
 
 
58
 
// convert UTF-8 characters to UTF-16
59
 
LIBHUNSPELL_DLL_EXPORTED int u8_u16(w_char * dest, int size, const char * src);
60
 
 
61
 
// sort 2-byte vector
62
 
LIBHUNSPELL_DLL_EXPORTED void flag_qsort(unsigned short flags[], int begin, int end);
63
 
 
64
 
// binary search in 2-byte vector
65
 
LIBHUNSPELL_DLL_EXPORTED int flag_bsearch(unsigned short flags[], unsigned short flag, int right);
66
 
 
67
 
// remove end of line char(s)
68
 
LIBHUNSPELL_DLL_EXPORTED void mychomp(char * s);
69
 
 
70
 
// duplicate string
71
 
LIBHUNSPELL_DLL_EXPORTED char * mystrdup(const char * s);
72
 
 
73
 
// strcat for limited length destination string
74
 
LIBHUNSPELL_DLL_EXPORTED char * mystrcat(char * dest, const char * st, int max);
75
 
 
76
 
// duplicate reverse of string
77
 
LIBHUNSPELL_DLL_EXPORTED char * myrevstrdup(const char * s);
78
 
 
79
 
// parse into tokens with char delimiter
80
 
LIBHUNSPELL_DLL_EXPORTED char * mystrsep(char ** sptr, const char delim);
81
 
// parse into tokens with char delimiter
82
 
LIBHUNSPELL_DLL_EXPORTED char * mystrsep2(char ** sptr, const char delim);
83
 
 
84
 
// parse into tokens with char delimiter
85
 
LIBHUNSPELL_DLL_EXPORTED char * mystrrep(char *, const char *, const char *);
86
 
 
87
 
// append s to ends of every lines in text
88
 
LIBHUNSPELL_DLL_EXPORTED void strlinecat(char * lines, const char * s);
89
 
 
90
 
// tokenize into lines with new line
91
 
LIBHUNSPELL_DLL_EXPORTED int line_tok(const char * text, char *** lines, char breakchar);
92
 
 
93
 
// tokenize into lines with new line and uniq in place
94
 
LIBHUNSPELL_DLL_EXPORTED char * line_uniq(char * text, char breakchar);
95
 
LIBHUNSPELL_DLL_EXPORTED char * line_uniq_app(char ** text, char breakchar);
96
 
 
97
 
// change oldchar to newchar in place
98
 
LIBHUNSPELL_DLL_EXPORTED char * tr(char * text, char oldc, char newc);
99
 
 
100
 
// reverse word
101
 
LIBHUNSPELL_DLL_EXPORTED int reverseword(char *);
102
 
 
103
 
// reverse word
104
 
LIBHUNSPELL_DLL_EXPORTED int reverseword_utf(char *);
105
 
 
106
 
// remove duplicates
107
 
LIBHUNSPELL_DLL_EXPORTED int uniqlist(char ** list, int n);
108
 
 
109
 
// free character array list
110
 
LIBHUNSPELL_DLL_EXPORTED void freelist(char *** list, int n);
111
 
 
112
 
// character encoding information
113
 
struct cs_info {
114
 
  unsigned char ccase;
115
 
  unsigned char clower;
116
 
  unsigned char cupper;
117
 
};
118
 
 
119
 
// Unicode character encoding information
120
 
struct unicode_info {
121
 
  unsigned short c;
122
 
  unsigned short cupper;
123
 
  unsigned short clower;
124
 
};
125
 
 
126
 
struct unicode_info2 {
127
 
  char cletter;
128
 
  unsigned short cupper;
129
 
  unsigned short clower;
130
 
};
131
 
 
132
 
LIBHUNSPELL_DLL_EXPORTED int initialize_utf_tbl();
133
 
LIBHUNSPELL_DLL_EXPORTED void free_utf_tbl();
134
 
LIBHUNSPELL_DLL_EXPORTED unsigned short unicodetoupper(unsigned short c, int langnum);
135
 
LIBHUNSPELL_DLL_EXPORTED unsigned short unicodetolower(unsigned short c, int langnum);
136
 
LIBHUNSPELL_DLL_EXPORTED int unicodeisalpha(unsigned short c);
137
 
 
138
 
struct enc_entry {
139
 
  const char * enc_name;
140
 
  struct cs_info * cs_table;
141
 
};
142
 
 
143
 
// language to encoding default map
144
 
 
145
 
struct lang_map {
146
 
  const char * lang;
147
 
  const char * def_enc;
148
 
  int num;
149
 
};
150
 
 
151
 
LIBHUNSPELL_DLL_EXPORTED struct cs_info * get_current_cs(const char * es);
152
 
 
153
 
LIBHUNSPELL_DLL_EXPORTED const char * get_default_enc(const char * lang);
154
 
 
155
 
// get language identifiers of language codes
156
 
LIBHUNSPELL_DLL_EXPORTED int get_lang_num(const char * lang);
157
 
 
158
 
// get characters of the given 8bit encoding with lower- and uppercase forms
159
 
LIBHUNSPELL_DLL_EXPORTED char * get_casechars(const char * enc);
160
 
 
161
 
// convert null terminated string to all caps using encoding
162
 
LIBHUNSPELL_DLL_EXPORTED void enmkallcap(char * d, const char * p, const char * encoding);
163
 
 
164
 
// convert null terminated string to all little using encoding
165
 
LIBHUNSPELL_DLL_EXPORTED void enmkallsmall(char * d, const char * p, const char * encoding);
166
 
 
167
 
// convert null terminated string to have initial capital using encoding
168
 
LIBHUNSPELL_DLL_EXPORTED void enmkinitcap(char * d, const char * p, const char * encoding);
169
 
 
170
 
// convert null terminated string to all caps
171
 
LIBHUNSPELL_DLL_EXPORTED void mkallcap(char * p, const struct cs_info * csconv);
172
 
 
173
 
// convert null terminated string to all little
174
 
LIBHUNSPELL_DLL_EXPORTED void mkallsmall(char * p, const struct cs_info * csconv);
175
 
 
176
 
// convert null terminated string to have initial capital
177
 
LIBHUNSPELL_DLL_EXPORTED void mkinitcap(char * p, const struct cs_info * csconv);
178
 
 
179
 
// convert first nc characters of UTF-8 string to little
180
 
LIBHUNSPELL_DLL_EXPORTED void mkallsmall_utf(w_char * u, int nc, int langnum);
181
 
 
182
 
// convert first nc characters of UTF-8 string to capital
183
 
LIBHUNSPELL_DLL_EXPORTED void mkallcap_utf(w_char * u, int nc, int langnum);
184
 
 
185
 
// get type of capitalization
186
 
LIBHUNSPELL_DLL_EXPORTED int get_captype(char * q, int nl, cs_info *);
187
 
 
188
 
// get type of capitalization (UTF-8)
189
 
LIBHUNSPELL_DLL_EXPORTED int get_captype_utf8(w_char * q, int nl, int langnum);
190
 
 
191
 
// strip all ignored characters in the string
192
 
LIBHUNSPELL_DLL_EXPORTED void remove_ignored_chars_utf(char * word, unsigned short ignored_chars[], int ignored_len);
193
 
 
194
 
// strip all ignored characters in the string
195
 
LIBHUNSPELL_DLL_EXPORTED void remove_ignored_chars(char * word, char * ignored_chars);
196
 
 
197
 
LIBHUNSPELL_DLL_EXPORTED int parse_string(char * line, char ** out, int ln);
198
 
 
199
 
LIBHUNSPELL_DLL_EXPORTED int parse_array(char * line, char ** out, unsigned short ** out_utf16,
200
 
    int * out_utf16_len, int utf8, int ln);
201
 
 
202
 
LIBHUNSPELL_DLL_EXPORTED int fieldlen(const char * r);
203
 
LIBHUNSPELL_DLL_EXPORTED char * copy_field(char * dest, const char * morph, const char * var);
204
 
 
205
 
LIBHUNSPELL_DLL_EXPORTED int morphcmp(const char * s, const char * t);
206
 
 
207
 
LIBHUNSPELL_DLL_EXPORTED int get_sfxcount(const char * morph);
208
 
 
209
 
// conversion function for protected memory
210
 
LIBHUNSPELL_DLL_EXPORTED void store_pointer(char * dest, char * source);
211
 
 
212
 
// conversion function for protected memory
213
 
LIBHUNSPELL_DLL_EXPORTED char * get_stored_pointer(const char * s);
214
 
 
215
 
// hash entry macros
216
 
LIBHUNSPELL_DLL_EXPORTED inline char* HENTRY_DATA(struct hentry *h)
217
 
{
218
 
    char *ret;
219
 
    if (!h->var)
220
 
        ret = NULL;
221
 
    else if (h->var & H_OPT_ALIASM)
222
 
        ret = get_stored_pointer(&(h->word[0]) + h->blen + 1);
223
 
    else 
224
 
        ret = &(h->word[0]) + h->blen + 1;
225
 
    return ret;
226
 
}
227
 
 
228
 
// NULL-free version for warning-free OOo build
229
 
LIBHUNSPELL_DLL_EXPORTED inline const char* HENTRY_DATA2(const struct hentry *h)
230
 
{
231
 
    const char *ret;
232
 
    if (!h->var)
233
 
        ret = "";
234
 
    else if (h->var & H_OPT_ALIASM)
235
 
        ret = get_stored_pointer(&(h->word[0]) + h->blen + 1);
236
 
    else
237
 
        ret = &(h->word[0]) + h->blen + 1;
238
 
    return ret;
239
 
}
240
 
 
241
 
LIBHUNSPELL_DLL_EXPORTED inline char* HENTRY_FIND(struct hentry *h, const char *p)
242
 
{
243
 
    return (HENTRY_DATA(h) ? strstr(HENTRY_DATA(h), p) : NULL);
244
 
}
245
 
 
246
 
#define w_char_eq(a,b) (((a).l == (b).l) && ((a).h == (b).h))
247
 
 
248
 
#endif