1 module henhouse.translator.html; 2 3 import file = std.file; 4 import uni = std.uni; 5 6 import hhc = henhouse.converter; 7 import hht_t = henhouse.translator.text; 8 9 10 /** 11 * HTML Translator 12 */ 13 class Translator : hht_t.Translator 14 { 15 override string translateText(string original) 16 { 17 char current; 18 string chicken; 19 string buffer; 20 21 for (int i = 0; i < original.length; i++) { 22 current = original[i]; 23 24 if ('<' == current) { 25 if (0 < buffer.length) { 26 chicken ~= hhc.wordToChicken(buffer); 27 buffer = ""; 28 } 29 30 do { 31 chicken ~= original[i]; 32 i++; 33 } 34 while ('>' != original[i]); 35 36 chicken ~= '>'; 37 continue; 38 } 39 40 if (uni.isAlpha(current)) { 41 buffer ~= current; 42 continue; 43 } 44 45 if (0 < buffer.length) { 46 chicken ~= hhc.wordToChicken(buffer); 47 buffer = ""; 48 } 49 50 chicken ~= current; 51 } 52 53 return chicken; 54 } 55 56 unittest 57 { 58 Translator trans = new Translator(); 59 string original = "<html><body><h1>HTML</h1><p>Converted text!</p></body></html>"; 60 string chicken = "<html><body><h1>CHICKEN</h1><p>Chicken chicken!</p></body></html>"; 61 62 assert(chicken == trans.translateText(original)); 63 } 64 }