1 #include "license.hunspell"
2 #include "license.myspell"
11 RepList::RepList(int n
) {
12 dat
= (replentry
**) malloc(sizeof(replentry
*) * n
);
13 if (dat
== 0) size
= 0; else size
= n
;
19 for (int i
= 0; i
< pos
; i
++) {
20 free(dat
[i
]->pattern
);
21 free(dat
[i
]->pattern2
);
27 int RepList::get_pos() {
31 replentry
* RepList::item(int n
) {
35 int RepList::near(const char * word
) {
38 while ((p2
- p1
) > 1) {
39 int m
= (p1
+ p2
) / 2;
40 int c
= strcmp(word
, dat
[m
]->pattern
);
42 if (c
< 0) p2
= m
; else p1
= p2
= m
;
48 int RepList::match(const char * word
, int n
) {
49 if (strncmp(word
, dat
[n
]->pattern
, strlen(dat
[n
]->pattern
)) == 0) return strlen(dat
[n
]->pattern
);
53 int RepList::add(char * pat1
, char * pat2
) {
54 if (pos
>= size
|| pat1
== NULL
|| pat2
== NULL
) return 1;
55 replentry
* r
= (replentry
*) malloc(sizeof(replentry
));
56 if (r
== NULL
) return 1;
57 r
->pattern
= mystrrep(pat1
, "_", " ");
58 r
->pattern2
= mystrrep(pat2
, "_", " ");
62 for (int i
= pos
- 1; i
> 0; i
--) {
64 if (strcmp(r
->pattern
, dat
[i
- 1]->pattern
) < 0) {
72 int RepList::conv(const char * word
, char * dest
) {
75 for (size_t i
= 0; i
< strlen(word
); i
++) {
76 int n
= near(word
+ i
);
77 int l
= match(word
+ i
, n
);
79 strcpy(dest
+ stl
, dat
[n
]->pattern2
);
80 stl
+= strlen(dat
[n
]->pattern2
);
83 } else dest
[stl
++] = word
[i
];