1 module henhouse.translator.text;
2 
3 import file = std.file;
4 import uni  = std.uni;
5 
6 import hhc   = henhouse.converter;
7 import hht_i = henhouse.translator.itranslator;
8 
9 
10 /**
11  * Plaintext Translator.
12  */
13 class Translator : hht_i.ITranslator
14 {
15     string translateFile(string filename)
16     {
17         string original = cast(string) file.readText(filename);
18 
19         return translateText(original);
20     }
21 
22     string translateText(string original)
23     {
24         char   current;
25         string chicken;
26         string buffer;
27 
28         for (int i = 0; i < original.length; i++) {
29             current = original[i];
30 
31             if (uni.isAlpha(current)) {
32                 buffer ~= current;
33                 continue;
34             }
35 
36             if (0 < buffer.length) {
37                 chicken ~= hhc.wordToChicken(buffer);
38                 buffer   = "";
39             }
40 
41             chicken ~= current;
42         }
43 
44         return chicken;
45     }
46 
47     unittest
48     {
49         Translator trans = new Translator();
50         string original  = "Much chicken! So convert!";
51         string chicken   = "Chicken chicken! Chicken chicken!";
52 
53         assert(chicken == trans.translateText(original));
54     }
55 }