1 // -*- coding: viscii tab-width: 2 mode: c++ -*-
6 static char *keys
= "`~1!2@3#4$5%6^7&8*9(0)-_=+\\|" "qwertyuiop[{]}" "asdfghjkl;:'\"" "zxcvbnm,<.>/?";
7 static char *keymap
[] = {
83 void KeyRecover::init(const char *input_
,int N
)
85 uint n
= strlen(input_
);
91 for (i
= 0;i
< n
;i
++) {
92 char c
= tolower(input
[i
]);
93 char *s
= strchr(keys
,c
);
95 vmap
[i
] = keymap
[s
-keys
];
96 vvv
[i
] = strlen(vmap
[i
]);
108 bool KeyRecover::inner_step(string
&output
)
112 while (cgen
.step(vv
)) {
114 for (uint i
= 0;i
< len
;i
++) {
115 output
[v
[i
]] = vmap
[v
[i
]][vv
[i
]];
124 bool KeyRecover::step(string
&output
)
127 if (inner_step(output
))
129 // inner_step returns false, it means that we can continue the main loop
132 while (posgen
.step(v
,len
)) {
135 for (uint i
= 0;i
< len
;i
++)
139 if (inner_step(output
))
145 void KeyRecover::done()
150 void keyboard_recover(const char *input
,set
<string
> &output
)
155 while (keyr
.step(s
)) {
161 uint n = strlen(input);
165 vector<const char*> vmap;
168 for (i = 0;i < n;i ++) {
169 char c = tolower(input[i]);
170 char *s = strchr(keys,c);
172 vmap[i] = keymap[s-keys];
173 vvv[i] = strlen(vmap[i]);
185 while (posgen.step(v,len)) {
189 for (i = 0;i < len;i ++)
192 while (cgen.step(vv)) {
194 for (i = 0;i < len;i ++) {
195 s[v[i]] = vmap[v[i]][vv[i]];
205 string
vni_recover(const char *input
)
208 uint p
,i
,n
= strlen(input
);
209 char diacritic
= '0';
212 s
= "0"; // diacritic placeholder
214 for (i
= 0;i
< n
;i
++) {
216 case '1': diacritic
= '1'; break;
217 case '2': diacritic
= '2'; break;
218 case '3': diacritic
= '3'; break;
219 case '4': diacritic
= '4'; break;
220 case '5': diacritic
= '5'; break;
226 if (p
!= string::npos
) {
231 if (p
!= string::npos
) {
238 if (p
!= string::npos
) {
243 if (p
!= string::npos
) {
250 if (p
!= string::npos
) {
255 if (p
!= string::npos
) {
269 if (p
!= string::npos
) {
274 if (p
!= string::npos
) {
281 if (p
!= string::npos
) {
286 if (p
!= string::npos
) {
298 if (p
!= string::npos
)
302 if (p
!= string::npos
)
311 if (p
!= string::npos
)
315 if (p
!= string::npos
)
329 if (syll
.parse(s
.c_str()))
330 return syll
.to_str();
335 string
telex_recover(const char *input
)
338 uint p
,i
,n
= strlen(input
);
339 char diacritic
= '0';
342 s
= "0"; // diacritic placeholder
344 for (i
= 0;i
< n
;i
++) {
345 switch (tolower(input
[i
])) {
346 case 's': diacritic
= '1'; break;
347 case 'f': diacritic
= '2'; break;
348 case 'r': diacritic
= '3'; break;
349 case 'x': diacritic
= '4'; break;
350 case 'j': diacritic
= '5'; break;
356 if (p
!= string::npos
) {
361 if (p
!= string::npos
) {
368 if (p
!= string::npos
) {
373 if (p
!= string::npos
) {
380 if (p
!= string::npos
) {
385 if (p
!= string::npos
) {
395 case '[': s
+= '½'; break;
396 case ']': s
+= 'ß'; break;
399 if (!s
.empty() && tolower(s
[s
.size()-1]) == 'a')
400 s
[s
.size()-1] = s
[s
.size()-1] == 'a' ? 'â' : 'Â';
406 if (!s
.empty() && tolower(s
[s
.size()-1]) == 'e')
407 s
[s
.size()-1] = s
[s
.size()-1] == 'e' ? 'ê' : 'Ê';
413 if (!s
.empty() && tolower(s
[s
.size()-1]) == 'o')
414 s
[s
.size()-1] = s
[s
.size()-1] == 'o' ? 'ô' : 'Ô';
420 if (!s
.empty() && tolower(s
[s
.size()-1]) == 'd')
421 s
[s
.size()-1] = s
[s
.size()-1] == 'd' ? 'ð' : 'Ð';
434 if (syll
.parse(s
.c_str()))
435 return syll
.to_str();
440 void im_recover(const char *input
,set
<string
> &output
)
443 s
= vni_recover(input
);
446 s
= telex_recover(input
);