|
From: Martin K. <Mar...@St...> - 2005-03-27 22:10:21
|
> 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 have implemented the O(1) solution. Looks quite simple. I also try to run the test suite but the unit test of the HtmlUtils method consists only of two small test cases which does not look very potent in my opinion. Is this class intended to be tested indirectly? Another point: The setup of the HTML character entity references is currently done using add and addSequence calls. I would like to take a step back and use the real source instead. (http://www.w3.org/TR/REC-html40/sgml/entities.html#h-24.2.1) I think of a solution using a resource (file) instead of lots of add/addSequence calls. Also the testing would be improved and the read in is a no-brainer for me. Also the initialization can be done lazily and since it is a HtmlUtils is a global static service singelton behaviour (only one initialization needed) is an option. Also the readability of the class would improve greatly and we would be able to unit test this class easily entirely. Currently I was able to cut down the size of the old implementation by 2/3. The current refactored version is about 8KB in size compared to the original 24KB source code. But using a resource file I may be able to cut it down to 2 KB (around 40 SLOCs). Does anything speak against the resource (file) based setup aproach? Cheers, Martin (Kersten) |