equal
deleted
inserted
replaced
|
1 #include <stdio.h> |
|
2 #include "dictre.h" |
|
3 |
|
4 static int closed_accent(const unsigned char *tmp) |
|
5 { |
|
6 if (tmp[0] == 0xcc && tmp[1] == 0x81) |
|
7 return 1; |
|
8 return 0; |
|
9 } |
|
10 |
|
11 static int open_accent(const unsigned char *tmp) |
|
12 { |
|
13 if (tmp[0] == 0x60) |
|
14 return 1; |
|
15 return 0; |
|
16 } |
|
17 |
|
18 /* Must free what is needed */ |
|
19 char * mix_accents(char *a, const char *b) |
|
20 { |
|
21 int ia,ib,o; |
|
22 char *out; |
|
23 char tmp[MAXWORD]; |
|
24 |
|
25 ia = 0; |
|
26 ib = 0; |
|
27 o = 0; |
|
28 while(a[ia] != 0 || b[ib] != 0) |
|
29 { |
|
30 if (closed_accent(&a[ia])) |
|
31 { |
|
32 tmp[o] = a[ia]; |
|
33 tmp[o+1] = a[ia+1]; |
|
34 o+=2; |
|
35 ia+=2; |
|
36 if(closed_accent(&b[ib])) |
|
37 ib+=2; |
|
38 continue; |
|
39 } else if (closed_accent(&b[ib])) |
|
40 { |
|
41 tmp[o] = b[ib]; |
|
42 tmp[o+1] = b[ib+1]; |
|
43 o+=2; |
|
44 ib+=2; |
|
45 continue; |
|
46 } else if (open_accent(&a[ia])) |
|
47 { |
|
48 tmp[o] = b[ia]; |
|
49 o+=1; |
|
50 ia+=1; |
|
51 if (open_accent(&b[ib])) |
|
52 ib+=1; |
|
53 continue; |
|
54 } else if (open_accent(&b[ib])) |
|
55 { |
|
56 tmp[o] = b[ib]; |
|
57 o+=1; |
|
58 ib+=1; |
|
59 continue; |
|
60 } |
|
61 else |
|
62 { |
|
63 /* Letter */ |
|
64 tmp[o] = a[ia]; |
|
65 if (a[ia] != 0) |
|
66 ++ia; |
|
67 if (b[ib] != 0) |
|
68 ++ib; |
|
69 ++o; |
|
70 } |
|
71 } |
|
72 tmp[o] = 0; |
|
73 out = strdup(tmp); |
|
74 free(a); |
|
75 return out; |
|
76 } |
|
77 |
|
78 void remove_accent(unsigned char *dest, const unsigned char *from) |
|
79 { |
|
80 int i,o; |
|
81 |
|
82 i = 0; |
|
83 o = 0; |
|
84 while (from[i] != 0) |
|
85 { |
|
86 if (from[i] == 0xcc && from[i+1] == 0x81) |
|
87 i+=2; |
|
88 else if (from[i] == 0x60) |
|
89 ++i; |
|
90 else |
|
91 { |
|
92 dest[o] = from[i]; |
|
93 ++o; |
|
94 ++i; |
|
95 } |
|
96 } |
|
97 dest[o] = 0; |
|
98 } |