|
From: Martin K. <Mar...@St...> - 2005-03-26 19:54:31
|
Hi there, Since I critised the Spring code base within a forum post made in the architectural section (topic: Spring Code Remarks), I felt like refactoring the prime evil class HtmlUtils. Please don't take the prime evil thing as an offence. But the HtmlUtil implementation features some of the biggest abuses in terms of if statements and code duplication, I have ever seen. So this implementation is surely blessed by the dark side! ;-) I have spend around three hours to rework the current implementation. I could eleminate 200 SLOC lines of code and refactored the character entity references setup to be more readable (boy that was a hot editing session). Also the unescape and escape methods got some attantion. (found a way to improve the performance as well). The current trouble maker is the isSpecialCharacter method. I would like to scrap this method and let the CharacterEntityReference class take care of it. You know this class has the appropriate knowledge and it can be easily computed at startup using an int-array. There are two opptions: First use 3000 bits(! not bytes!) and go for a mapping of the chars 0....1000 and 8000...10000. This would provide O(1) complexity. Another way would be the use of a sorted char array with O(log n) but around 1000 bytes. I would like to implement the first one. It is nearly a no brainer but it might be a bit difficult for the reader. But I would like to get away from 104 McCabe decision points, anyway. Another point is the unescape method. I am not sure if EMPTY_REFERENCE and MALFORMED_REFERENCE are really needed. Is there anything in the spec about '&;' being allowed? I would like to drop that too. Another thing is that I think I found a semantical bug in the orginal implementation. Check out this test-case: & In the current implementation the first & and the ';' is threatened as a reference. Since this reference can not be resolved, it will be droped. I would think it should be evaluated to & ' '. I couldn't test the refactoring (it is still incomplete anyways) since I did it within a test runtime environment. I use the Spring codebase of 1.4 as the default use-case scenario for my final exams work (which is about to be completed in two weeks I hope). Cheers, Martin (Kersten) |