Following the last post on Image Map and HTML5, there has been some interesting development. Namely, the algorithm for dealing with a list of numbers isn’t as simple as it seems.
HTML5 actually has specification around how non-numeric characters should be dealt with in a list of numbers. For example, “a=23 b=56” is valid, as per the spec. To explore what strings can be accepted and what cannot be, I have implemented the spec in Java quickly. Please download it from here.
The comments are extracted directly from the specification. As you can see, it is difficult to read the algorithm, that is written in English. According to Bob Martin (if I remember correctly that this is from him), programming language is the best language to describe a program’s behaviour, and so WHATWG may want to consider adopting a simple programming language to describe the spec.
Anyway, this Java implementation should make the spec clearer. Please note that, in order to make it as accurate as possible, the Java code is not refactored to look prettier. Once unit tests are written against the spec, the algorithm can be refactored into shorter, fancier and faster code.
Update: I put up a Github project with this implementation and unit tests. Check it out if you are interested: https://github.com/vvasabi/html5-number-list.